[LLVMdev] llvm-gcc loop unrolling

Chris Lattner sabre at nondot.org
Wed Apr 20 06:54:52 PDT 2005


On Wed, 20 Apr 2005, Evan Jones wrote:
> What component is responsible for loop unrolling, llvm-gcc, or some LLVM pass 
> after GCC? When compiling this function:

the llvm-gcc front-end does no non-trivial optimization.  This is 
performed by the llvm -loop-unroll pass.

> void printArray( int array[16] ) {
> 	for( int i = 0; i < 16; ++ i ) {
> 		printf( "%d\n", array[i] );
> 	}
> }
>
> llvm-gcc chooses to unroll this loop, and I don't think it should. It doesn't 
> unroll the loop if there are 17 iterations, only 16. It also produces this 
> output even when compiling with -Os, which is supposed to turn off 
> optimizations like this.

Currently, -Os is ignored.

> Wouldn't it be better to leave the loop unrolling to some later optimization 
> pass? This way, future passes can easily recognize that this is in fact a 
> loop.

I'm not sure what you mean here.  Before the loop-unroll pass runs, the 
loop is not unrolled.  If you don't want this behavior, you can hack 
tools/gccas/gccas.cpp to not run the loop unroll pass.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.cs.uiuc.edu/




More information about the llvm-dev mailing list