This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Preserve LCSSA on inner loops
AbandonedPublic

Authored by sanjoy on Nov 22 2015, 11:39 AM.

Details

Summary

Currently IndVarSimplify breaks LCSSA on inner loops even though it says
it preserves LCSSA. Fix this by running formLCSSARecursively
explictly on the inner loops.

Fixes PR25578 and PR24804.

There are couple of ways we can make this logic more frugal if needed:

  • Inspect only newly inserted / moved instructions for possible LCSSA breakage
  • Teach SCEVExpander to not break LCSSA for any loop in the loop nest

Test cases courtesy of David Majnemer and Michael Zolotukhin!

Diff Detail

Event Timeline

sanjoy updated this revision to Diff 40883.Nov 22 2015, 11:39 AM
sanjoy retitled this revision from to [IndVars] Preserve LCSSA on inner loops.
sanjoy updated this object.
sanjoy added a subscriber: llvm-commits.
hfinkel accepted this revision.Nov 26 2015, 11:32 AM
hfinkel added a reviewer: hfinkel.
hfinkel added a subscriber: hfinkel.

LGTM.

lib/Transforms/Scalar/IndVarSimplify.cpp
2185

This does not seem to be documented explicitly anywhere, could you also add some comments in SCEVExpander's header file to this effect as well.

This revision is now accepted and ready to land.Nov 26 2015, 11:32 AM
sanjoy abandoned this revision.Nov 29 2015, 2:38 PM

Hi Hal,

Thank you for the review.

After taking a closer look I think I've found the two specific things that need to be fixed to have -indvars preserve LCSSA for the entire loop nest. Given that the two fixes are not very invasive, I think brute-forcing LCSSA after -indvars (i.e. this patch) is not the right fix. I have the two new fixes up for review at D15058 and D15059.

The comment I made about SCEVExpander was also misleading -- at least in the breaking test cases, SCEVExpander does not break LCSSA for the inner loops, but it is -indvars that is the problem.

I'm abandoning this revision for now in favor of D15058 and D15059.