The -indvars pass is not computing the exit value of j in either of these cases: int ltst(int x) { int i, j; j=0; for(i=0; i<x; i++)j++; return(j); } int ltst(int x) { int i = 0, j = 0 do { j++, i++; } while (i < x); return(j); }
Another obvious case: int main() { int i = 0; for (int x = 0; x < 200000; ++x) i += 3; return i; }
*** Bug 1232 has been marked as a duplicate of this bug. ***
This regression is largely due to LCSSA landing. For example, the input to indvars on the code in comment #1 is: define i32 @foo() { entry: br label %bb5 bb5: ; preds = %bb5, %entry %x.03.0 = phi i32 [ 0, %entry ], [ %indvar.next, %bb5 ] ; <i32> [#uses=2] %i.01.0 = mul i32 %x.03.0, 3 ; <i32> [#uses=1] %tmp2 = add i32 %i.01.0, 3 ; <i32> [#uses=1] %indvar.next = add i32 %x.03.0, 1 ; <i32> [#uses=2] icmp ne i32 %indvar.next, 200000 ; <i1>:0 [#uses=1] br i1 %0, label %bb5, label %bb7 bb7: ; preds = %bb5 %tmp2.lcssa = phi i32 [ %tmp2, %bb5 ] ; <i32> [#uses=1] ret i32 %tmp2.lcssa } the LCSSA phi node prevents exit value substitution due to IndVarSimplify.cpp:347 -Chris
Implemented. Patch here: http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070226/045475.html Testcases here: test/Transforms/IndVarsSimplify/loop_evaluate_[234].ll -Chris