I am getting an error Can't unroll; loop not terminated by a conditional branch
for the following code:
for(i=0 ; j<10 && i<5 ; i++)
j= j+2;
I am using the following command for unrolling loops in a file a.bc
:
opt -loops -loop-rotate -loop-simplify -loop-unroll -unroll-count=3 -unroll-allow-partial -debug a.bc -o a.loop.bc
Is there a way to unroll loops avoiding this error?
Asked
Active
Viewed 1,386 times
1

piXel_pRo
- 159
- 2
- 14
1 Answers
2
use this command and it should work (I have tested it on LLVM 3.6 and 3.7)
opt -mem2reg -simplifycfg -loops -lcssa -loop-simplify -loop-rotate
-loop-unroll -unroll-count=3 -unroll-allow-partial -debug a.bc -o a.loop.bc
you need first of all mem2reg to have your bitcode converted to SSA from (if it is not already), in the other hand the loop has two conditional exiting branches and one unconditional backedge, so simplifycfg seems helpful to transform it to one-conditional backedge form which can be handled by unroll pass

hadi sadeghi
- 517
- 4
- 7
-
we might also want to use `-unroll-threshold` to unroll bigger loops – piXel_pRo Jan 01 '16 at 14:26