This is from ‘early JIT tests’ thread on comp.lang.misc.
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 ; [#uses=1]
%tmp13 = setgt int %x, 0 ; [#uses=1]
br bool %tmp13, label %bb, label %bb7
bb: ; preds = %bb, %entry
%indvar = phi uint [ 0, %entry ], [ %indvar.next, %bb ] ; [#uses=2]
%i.0.0 = cast uint %indvar to int ; [#uses=1]
%tmp1 = add int %i.0.0, 1 ; [#uses=1]
%indvar.next = add uint %indvar, 1 ; [#uses=2]
%exitcond = seteq uint %indvar.next, %x ; [#uses=1]
br bool %exitcond, label %bb7, label %bb
bb7: ; preds = %bb, %entry
%j.0.1 = phi int [ 0, %entry ], [ %tmp1, %bb ] ; [#uses=1]
ret int %j.0.1
}
Aaron
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
-indvars pass fails to replace exit value of loop when profitable · Issue #1551 · llvm/llvm-project · GitHub 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