[LLVMdev] Unnatural loops with O0

Adrian Prantl adrian at complang.tuwien.ac.at
Thu May 8 09:33:48 PDT 2008


Hello everybody,

we noticed that llvmgcc4.2-2.2 sometimes generates non-natural loops
when compiling to bytecode without any optimizations. Apparently what
happens is that the loop header is duplicated, which results in two
entry points for the loop. Since this could obstruct subsequent loop
optimizations, it might be interesting to further investigate this behavior.

To show the problem, I have included an example from libmad:

llvm-gcc -fdump-tree-all -O0 -I. -D_GNU_SOURCE -D__STDC_LIMIT_MACROS
-O0 -m32 -I/usr/include -c bit.c -o Output/bit.bc -emit-llvm

opt -print-cfg Output/bit.bc -o test.bc -f
dot -o test.ps -Tps cfg.mad_bit_crc.dot

In the CFG of mad_bit_crc(), the second while loop is entered from two
other basic blocks.

  From what I have seen, this does not happen in the front end. GCC does
transform the loop to a do-while, but does not duplicate the condition.

One work-around that I have found is to insert a label right before the
loop, s.t. LLVM is not allowed to duplicate the entry. However, it would
be great if there was some easier way to achieve this.

regards,
Adrian

-------------- next part --------------
A non-text attachment was scrubbed...
Name: bit-preprocessed.c.gz
Type: application/x-gzip
Size: 6003 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080508/80af7cd5/attachment.bin>


More information about the llvm-dev mailing list