Loop unrolling is a loop optimization strategy.
Questions tagged [loop-unrolling]
164 questions
1
vote
1 answer
Why does clang is unable to unroll a loop (that gcc unrolls)?
I am writing in C and compiling using clang. I am trying to unroll a loop. The loop is not unrolled and there is a warning.
loop not unrolled: the optimizer was unable to perform the requested transformation; the transformation might be disabled or…

ilyamt
- 49
- 1
- 7
1
vote
2 answers
Why does gcc's code-gen for my unrolled loop epilogue look over-complicated?
Thanks for all the comments so far. I am sorry that I have used a bad example in my original question, that almost everyone would say: "Oh, you should use memcopy!" But that is not what my question is about.
My question is more generic about how…

Zheyuan Li
- 71,365
- 17
- 180
- 248
1
vote
1 answer
How to unroll a list comprehension
I have the following code I am trying to understand as I am new to Python. I understand that the code computes the powerset but the line subsetlist = [ subset + [item] for subset in result] is a little hard to understand. How can I break this…

Jeff Benister
- 468
- 3
- 12
1
vote
1 answer
What do we know about the "strength" of nvcc's #pragma unroll?
What do we know about the unrolling capabilities of nvcc when encountering #pragma unroll directive? How sophisticated is it? Has anyone experimented with more and more complex loop structures to see what it gives up on?
For example,
#pragma…

einpoklum
- 118,144
- 57
- 340
- 684
1
vote
0 answers
LLVM: how to check that there are no loops in bytecode after loop-unrolling
I have a number of C source code files, on which I would like to perform some type of static analysis. First, I need to get rid of any loop in the control flow graph, for which I use the following one-liners:
~$ clang -emit-llvm -c file.c -o…

Patrick Trentin
- 7,126
- 3
- 23
- 40
1
vote
3 answers
Nested Loop Unrolling in C
I want to optimize my code by using unrolling loop. I tried to apply unrolling but I think I cannot do it and I cannot see my problem. I want to apply unrolling loop to outer loop.
This loops do transpose of matrix.
This is my loop to apply…

bekirsevki
- 302
- 7
- 20
1
vote
2 answers
Are either Clang or GCC able to autovectorize manually unrolled loops?
I have an idea for a code style for writing specific kinds of numerical algorithms where you write your algorithm purely in data-layout agnostic fashion.
i.e. All of your functions take (one or more) scalar arguments, and return (through a pointer)…

Andrew Wagner
- 22,677
- 21
- 86
- 100
1
vote
2 answers
gcc loop unrolling oddity
In the course of writing a "not-equal scan" for Boolean arrays,
I ended up writing this loop:
// Heckman recursive doubling
#ifdef STRENGTHREDUCTION // Haswell/gcc does not like the multiply
for( s=1; s

Robert Bernecky
- 139
- 1
- 2
1
vote
1 answer
Unrolling y86 loop
I am trying to unroll a loop in y86 code but I been getting 2 different values when I try to run a test program. The reg. code is:
xorq %rax,%rax # count = 0;
andq %rdx,%rdx # len <= 0?
jle Done # if so, goto…

Nukodi
- 335
- 1
- 9
- 24
1
vote
1 answer
C compiler loop unrolling clarification
I am having trouble understanding how MSVC compiler is unrolling the following loop (sorry for my poor understanding of the assembly language):
#define NUM_ITERATIONS (1000 * 1000 * 1000)
double dummySum = 0;
for (int x = 0; x < NUM_ITERATIONS;…

Lou
- 4,244
- 3
- 33
- 72
1
vote
1 answer
The most efficient way of counting positive, negative and zero number using loop unrolling
Say I have the following instruction, simply checks if a number is positive or not (negative or zero) and if it was positive add 1 to our counter (and we don't care if the numbers is negative or zero). I can do this with a simple loop…

Yar
- 7,020
- 11
- 49
- 69
1
vote
1 answer
How to implement base 2 loop unrolling at run-time for optimization purposes
Consider some code that needs to executed repeatedly anywhere between 1-1,000,000 times, and that the number of repeats is not known at compile time. It is my understanding that loop unrolling would be a negligible optimization given the large…

silvergasp
- 1,517
- 12
- 23
1
vote
1 answer
Effect of Unroll and Jam on a large loop
When I compiled my application, the performance was worse than I expected and I figured out the compiler was reporting a warning like the below.
remark #25461: Imperfect Loop Unroll-Jammed by 2 (pre-vector)
And this is my short code.
for(i=0; i

Sunwoo Lee
- 29
- 3
1
vote
4 answers
C++: Loop Optimization and Loop Unwinding (To loop or not to loop)
Update:
This discussion went further than I expected so i'm updating this with the code that I was actually working on when this question popped up into my head. It was a decision between 8 and 16 lines of code to determine who the winner of a…

gNerb
- 867
- 2
- 12
- 28
1
vote
2 answers
How to tell the compiler to unroll this loop
I have the following loop that I am running on an ARM processor.
// pin here is pointer to some part of an array
for (i = 0; i < v->numelements; i++)
{
pe = pptr[i];
peParent = pe->parent;
SPHERE *ps = (SPHERE *)(pe->data);
…

MetallicPriest
- 29,191
- 52
- 200
- 356