[LLVMdev] Unnatural loops with O0

Chris Lattner clattner at apple.com
Thu Feb 12 09:51:39 PST 2009


On Feb 12, 2009, at 7:55 AM, Duncan Sands wrote:

> Hi Marc,
>
>> Is there a compelling reason why llvm-gcc does not always produce  
>> natural
>> loops.  Is it a code size issue, or are there performance  
>> implications as
>> well?  I am seeing a simple 'while' loop compiled to an unnatural  
>> loop,
>> without any gotos, breaks, or continues.  What is the reason for  
>> this?
>
> is it already an unnatural loop when it comes out of the gcc parts of
> llvm-gcc (you can check this by compiling with: -O0 -emit-llvm)?  Or
> is it llvm itself that creates the unnatural loops?

Right.  There is little we can do about the -O0 -emit-llvm code: this  
is a literal translation of what the GCC front-end gives us.  If some  
*optimizer* is turning reducible loops into non-reducible control  
flow, then that is a completely different matter and I would consider  
that to be a serious bug.

If the gcc front-end is doing this to you, you can try out clang,  
which should not.

-Chris



More information about the llvm-dev mailing list