LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1179 - -indvars pass fails to replace exit value of loop when profitable
Summary: -indvars pass fails to replace exit value of loop when profitable
Status: RESOLVED FIXED
Alias: None
Product: libraries
Classification: Unclassified
Component: Loop Optimizer (show other bugs)
Version: 1.8
Hardware: All All
: P enhancement
Assignee: Chris Lattner
URL:
Keywords: code-quality, regression
: 1232 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-02-05 11:41 PST by Chris Lattner
Modified: 2019-05-05 06:32 PDT (History)
5 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Lattner 2007-02-05 11:41:21 PST
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);
}
Comment 1 Chris Lattner 2007-02-15 12:21:14 PST
Another obvious case:

int main() {
int i = 0;
for (int x = 0; x < 200000; ++x)
i += 3;
return i;
}
Comment 2 Chris Lattner 2007-02-28 19:48:25 PST
*** Bug 1232 has been marked as a duplicate of this bug. ***
Comment 3 Chris Lattner 2007-03-03 01:50:19 PST
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
Comment 4 Chris Lattner 2007-03-03 19:02:33 PST
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