Loop-Unroll optimization

Hi,

The loop that I am trying it on is:
for(i=0; i< 1000; i++)
{
c[i] = a[i] + b[i];
}

I can't find any benefit unrolling this loop.

I just want to try loop-unroll and see corresponding changes in the bitcode file. For that any loop will do. Have you been able to test llvm loop-unroll successfully?

Hi, you need to run some optimization passes first. (like -O2)

2011/5/3 Manish Gupta <mgupta.iitr@gmail.com>

You mean like

llvm-gcc-4.2 -O2 -emit-llvm Hello.c -c -o Hello.bc

But still i am not able to observe any effect on bit code by running

opt-2.8 -loop-unroll Hello.bc -o Hello_unroll.bc

Hi,

You might want to try running -loops -loop-simplify before loop unroll.

From loop simplify.cpp


This pass performs several transformations to transform natural loops into a
00011 // simpler form, which makes subsequent analyses and transformations simpler and
00012 // more effective.

Arushi

We are looking for some LLVM compiler engineers for our GPU compiler team. Those positions involve both compiler feature development and optimizations on LLVM. Please contact me at czhang@qualcomm.com<mailto:czhang@qualcomm.com> if you are interested. Here is a link with more details of the job description: https://jobs.qualcomm.com/public/jobDetails.xhtml?requisitionId=1878327&page=jobSearch.

Chihong Zhang

Even after all the sequence of commands below bit-code is not showing any effect of loop-unrolling

manish@manish:~/Test2$ llvm-gcc-4.2 -O2 -emit-llvm Hello.c -c -o Hello.bc

manish@manish:~/Test2$ opt-2.8 -loops Hello.bc -o Hello1.bc
manish@manish:~/Test2$ opt-2.8 -loopsimplify Hello1.bc -o Hello2.bc
manish@manish:~/Test2$ opt-2.8 -indvars Hello2.bc -o Hello3.bc
manish@manish:~/Test2$ opt-2.8 -loop-unroll Hello3.bc -o Hello4.bc
manish@manish:~/Test2$ llvm-dis-2.8 Hello4.bc

My Hello.c looks like:

for(i=0; i< 1000; i++)
{
c[i] = a[i] + b[i];
}

printf(“%d\n”, c[999]);

  1. You should run the passes in the same opt command, for passes like loops which is an analysis pass provides results to the following passes.

  2. You can pass a -debug flag to opt to see the some debugging info.

  3. I tried this
    opt -mem2reg -loops -loopsimplify -loop-unroll -unroll-count=3 -debug loop.o -o tt.bc

and got this message.

Loop Size = 14
Can’t unroll; loop not terminated by a conditional branch.

  1. Looking at LoopUnroll.cpp showed a comment that said -loop-rotate helps, so I used the following

opt -mem2reg -loops -loopsimplify -loop-rotate -lcssa -loop-unroll -unroll-count=3 -debug loop.o -o tt.bc

Getting an unrolled version of the loop.

Arushi

1 Like

Awesome! I am getting the unroll version of the loop.

But I have no -debug option with my opt command (I have a Debug build)?