[LLVMdev] Strange loop unrolling problem

Pertti Kellomäki pertti.kellomaki at tut.fi
Wed Apr 22 02:48:44 PDT 2009


I am having a strange problem with loop unrolling. Attached is
a small example that demonstrates what happens.

There is a for-loop with a known trip count, and some control
flow inside the loop. If the condition of the control flow only
depends on the loop index and loop invariant variables, the loop
is not unrolled. However, if the condition involves potentially
loop variant variables, the loop does get unrolled.

The volatile variable assignments are there just to keep loop
body from disappearing completely. In the real case this
is derived from, the loop body contains some inline assembly.

The code within #ifdef MODIFY_V2 in the attached C code is in
fact dead code, as the condition of the if statement is never
true. However, including this dead code in the compilation
causes unrolling to take place.

Am I missing something or should I file a bug? I tried looking
around at LoopUnroll.cpp and UnrollLoop.cpp, but did not find
an immediate cause for this. From the debug output it looks like
instcombine is doing different things in the two cases.
-- 
Pertti
-------------- next part --------------
A non-text attachment was scrubbed...
Name: unroll.c
Type: text/x-csrc
Size: 380 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090422/70b9e70d/attachment.c>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Makefile
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090422/70b9e70d/attachment.ksh>


More information about the llvm-dev mailing list