This is an archive of the discontinued LLVM Phabricator instance.

[LSR] Prevent formula with SCEVAddRecExpr type of Reg from Sibling loops
ClosedPublic

Authored by wmi on Feb 15 2017, 6:44 PM.

Details

Summary

In rL294814, we allow formula with SCEVAddRecExpr type of Reg from loops other than current loop. This is good for the case when induction variable of outerloop being used in expr in innerloop. But it is very bad to allow such Reg from sibling loop because we may need to add lsr.iv in other sibling loops when scev expanding those SCEVAddRecExpr type exprs. For the testcase below, one loop can be inserted with a bunch of lsr.iv because of LSR for other loops.

// The induction variable j from a loop in the middle will have initial value generated
// from previous sibling loop and exit value used by its next sibling loop.
void goo(long i, long j);
long cond;

void foo(long N) {
long i = 0;
long j = 0;
i = 0; do { goo(i, j); i++; j++; } while (cond);
i = 0; do { goo(i, j); i++; j++; } while (cond);
i = 0; do { goo(i, j); i++; j++; } while (cond);
i = 0; do { goo(i, j); i++; j++; } while (cond);
i = 0; do { goo(i, j); i++; j++; } while (cond);
i = 0; do { goo(i, j); i++; j++; } while (cond);
}

The fix is to only allow formula with SCEVAddRecExpr type of Reg from current loop or its parents.

Diff Detail

Repository
rL LLVM

Event Timeline

wmi created this revision.Feb 15 2017, 6:44 PM
chandlerc accepted this revision.Feb 15 2017, 9:34 PM
chandlerc added a subscriber: chandlerc.

LGTM, this seems to be an obvious fix to the bug, and exactly matches the intent from the original patch.

This revision is now accepted and ready to land.Feb 15 2017, 9:34 PM
This revision was automatically updated to reflect the committed changes.