This is an archive of the discontinued LLVM Phabricator instance.

[IRCE] Canonicalize pre/post loops after the blocks are added into parent loop
ClosedPublic

Authored by anna on Jun 2 2017, 11:59 AM.

Details

Summary

We were canonizalizing the pre loop (into loop-simplify form) before
the post loop blocks were added into parent loop. This is incorrect when IRCE is
done on a subloop. The post-loop blocks are created, but not yet added to the
parent loop. So, loop-simplification on the pre-loop incorrectly updates
LoopInfo.

This patch corrects the ordering so that pre and post loop blocks are added to
parent loop (if any), and then the loops are canonicalized to LCSSA and
LoopSimplifyForm.

Diff Detail

Repository
rL LLVM

Event Timeline

anna created this revision.Jun 2 2017, 11:59 AM
anna added inline comments.Jun 2 2017, 1:20 PM
lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
1380 ↗(On Diff #101256)

As a later follow up change, I plan to:

  1. rename PreLoop/ PostLoop and function createClonedLoopStructure.
  2. move DT.recalculate just before calling canonicalizeLoop, so that all data structure updates are at one place.
reames accepted this revision.Jun 2 2017, 3:46 PM

LGTM w/comments addressed before submission.

lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
1391 ↗(On Diff #101256)

minor: I'd hoist the null check to the caller so it's more explicit.

test/Transforms/IRCE/correct-loop-info.ll
12 ↗(On Diff #101256)

Add checks just so we see what the output should look like. Consider using the update script.

This revision is now accepted and ready to land.Jun 2 2017, 3:46 PM
This revision was automatically updated to reflect the committed changes.
anna marked 2 inline comments as done.Jun 6 2017, 7:54 AM
anna added inline comments.
test/Transforms/IRCE/correct-loop-info.ll
12 ↗(On Diff #101256)

Thanks, the update script is pretty useful for cases like these!