This is an archive of the discontinued LLVM Phabricator instance.

[LoopRotate] Fix incorrect SCEV invalidation in loop rotation
ClosedPublic

Authored by mkazantsev on Apr 23 2018, 4:45 AM.

Details

Summary

LoopRotate only invalidates innermost loops while the changes that it makes may
also affert any of this parents. With patch rL329047, SCEV becomes much smarter
about calculation of exit counts for outer loops, so we cannot assume that they are
not affected.

Diff Detail

Repository
rL LLVM

Event Timeline

mkazantsev created this revision.Apr 23 2018, 4:45 AM
mkazantsev edited the summary of this revision. (Show Details)Apr 23 2018, 4:58 AM
mkazantsev accepted this revision.Apr 23 2018, 5:26 AM

We've fixed a bunch of bugs of this sort, so I think it's fine to go with.

This revision is now accepted and ready to land.Apr 23 2018, 5:26 AM
This revision was automatically updated to reflect the committed changes.

We've fixed a bunch of bugs of this sort, so I think it's fine to go with.

So generally, as a matter of politeness, good to avoid the review if you're gonna go with post-submit.

However I also have a question here -- are we going to have any SCEV left?

We don't re-run SCEV mid-way through the loop pass manager. If we invalidate all outer scevs when we loop rotate, won't that completely defeat SCEVs analysis on outer loops? Or will we lazily rebuild it?

Or will we lazily rebuild it?

We will lazily rebuild SCEV expressions as needed. Not great for compile time, but we should be functionally correct.

@mkazantsev: IMO this illustrates an architectural problem with SCEV's cache -- ideally the cache would parallel the hierarchy of the loop tree itself so that changing an inner loop does not require us to throw away all of the information computed on the outer loop. Do you have some ideas on how we can fix this architectural issue?

llvm/trunk/lib/Transforms/Utils/LoopRotationUtils.cpp
262

Can you please add a comment on *how* we can affect parent loops? Rotating an inner loop should not change the trip count of outer loops so right now the statement sounds a bit confusing. Perhaps: "Loop rotation can change the dominance relationships between blocks in the inner loop and blocks in the outer loop. It may also delete blocks from the inner loop. Both of these may end up violating invariants in backedge taken infos cached by SCEV about outer loops."

mkazantsev marked an inline comment as done.Apr 23 2018, 7:13 PM
mkazantsev added inline comments.
llvm/trunk/lib/Transforms/Utils/LoopRotationUtils.cpp
262