[LLVMdev] Misc optimization issue

Chris Lattner sabre at nondot.org
Mon Feb 5 10:06:05 PST 2007


On Mon, 5 Feb 2007, Aaron Gray wrote:
> This is from 'early JIT tests' thread on comp.lang.misc.

Interesting, that's a great catch.  Because of the particular 
configuration of phi nodes in this case, we don't catch it.  I filed
http://llvm.org/PR1179 to track this.  Note that this is due to the LLVM 
loop optimizer, it has nothing to do with the JIT. :)

Thanks,

-Chris

> Given :-
>
> int ltst(int x)
> {
> int i, j;
>
> j=0;
> for(i=0; i<x; i++)j++;
>
> return(j);
> }
>
> This is from the online LLVM compiler. AND It does not seem to optimize it down !
>
> ; ModuleID = '/tmp/webcompile/_24843_0.bc'
> target datalayout = "e-p:32:32"
> target endian = little
> target pointersize = 32
> target triple = "i686-pc-linux-gnu"
>
> implementation   ; Functions:
>
> int %ltst(int %x) {
> entry:
> %x = cast int %x to uint ; <uint> [#uses=1]
> %tmp13 = setgt int %x, 0 ; <bool> [#uses=1]
> br bool %tmp13, label %bb, label %bb7
>
> bb:                                                 ; preds = %bb, %entry
> %indvar = phi uint [ 0, %entry ], [ %indvar.next, %bb ] ; <uint> [#uses=2]
> %i.0.0 = cast uint %indvar to int                 ; <int> [#uses=1]
> %tmp1 = add int %i.0.0, 1                 ; <int> [#uses=1]
> %indvar.next = add uint %indvar, 1            ; <uint> [#uses=2]
> %exitcond = seteq uint %indvar.next, %x ; <bool> [#uses=1]
> br bool %exitcond, label %bb7, label %bb
>
> bb7:                                                 ; preds = %bb, %entry
> %j.0.1 = phi int [ 0, %entry ], [ %tmp1, %bb ] ; <int> [#uses=1]
> ret int %j.0.1
> }
>
> Aaron
>

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list