Teach LoopRotate to preserve MemorySSA.
Enable tests for correctness, dependency disabled by default.
Details
Diff Detail
- Repository
- rL LLVM
Event Timeline
Moving the MSSA after cloning earlier to avoid the ValueMap invalidation.
Adding another test.
And ping.
lib/Transforms/Scalar/LoopRotation.cpp | ||
---|---|---|
49 ↗ | (On Diff #164939) | Why not just pass the Optional? |
106 ↗ | (On Diff #164939) | Again, maybe just pass the Optional. |
lib/Transforms/Utils/LoopRotationUtils.cpp | ||
59 ↗ | (On Diff #164939) | Use an Optional here? |
276 ↗ | (On Diff #164939) | These tests should remain the same with an Optional. |
lib/Transforms/Scalar/LoopRotation.cpp | ||
---|---|---|
49 ↗ | (On Diff #164939) | I'm inclined to prefer using the pointer just due to consistency with the other passes + the hope that this won't be Optional forever :). If you or other reviewers strongly prefer passing the Optional, please let me know and I'll update here and in all other passes. |
lib/Transforms/Scalar/LoopRotation.cpp | ||
---|---|---|
49 ↗ | (On Diff #164939) | I don't have a strong position on this, just throwing it out as an idea. Using an optional does eliminate the ternary operations and would make the code a bit cleaner. How expensive is MemorySSA? I'm not sure we can guarantee it will be available so it might always have to be optional. |
lib/Transforms/Scalar/LoopRotation.cpp | ||
---|---|---|
49 ↗ | (On Diff #164939) | It can be expensive if not used but it should be cheaper than MemoryDependenceAnalysis the AliasSetTracker. I tried to go ahead and make the change to Optional, but I end up moving the ternary somewhere else: either in the constructor for LoopRotate, or in each call to a BasicBlockUtil (e.g. MergeBlockIntoPredecessor or CriticalEdgeSplittingOptions). In utils, it seems the norm is to use pointers and check for null. Not saying using an Optional wouldn't be better, but it will require having all passes changed to pass Optional as well in the same patch. |
LGTM, but I don't know if I should be the one to sign off on this since I've never touched LoopRotate.
lib/Transforms/Scalar/LoopRotation.cpp | ||
---|---|---|
49 ↗ | (On Diff #164939) | Yeah, that sounds fine to me. I'm fine with the way this is. Was just wondering if Optional might make it cleaner, but it sounds like that would overly complicate this patch and is better left for a later change. Thanks! |
Minor comments on test case, otherwise this LGTM. Feel free to submit with a minimized test case.
test/Transforms/LoopRotate/preserve-mssa.ll | ||
---|---|---|
130–136 ↗ | (On Diff #166362) | Can this test case be minimized some to remove all these atributes and other unnecessary IR boilerplate? |
llvm/trunk/lib/Transforms/Utils/LoopRotationUtils.cpp | ||
---|---|---|
682–687 | Is this actually correct? { if (MSSAU && VerifyMemorySSA) MSSAU->getMemorySSA()->verifyMemorySSA(); LoopRotate LR(Threshold, LI, TTI, AC, DT, SE, MSSAU, SQ, RotationOnly, IsUtilMode); bool Changed = LR.processLoop(L); if (MSSAU && VerifyMemorySSA) MSSAU->getMemorySSA()->verifyMemorySSA(); return Changed; } |
llvm/trunk/lib/Transforms/Utils/LoopRotationUtils.cpp | ||
---|---|---|
682–687 | Yeah the code in the patch doesn't look right, given that the actual modifications happen in processLoop. |
llvm/trunk/lib/Transforms/Utils/LoopRotationUtils.cpp | ||
---|---|---|
682–687 | It's correct, but unnecessary. Thank you for noticing! |
llvm/trunk/lib/Transforms/Utils/LoopRotationUtils.cpp | ||
---|---|---|
682–687 | I dropped the verify calls there in 9ea0d8c38fc5 |
@asbirlea @fhahn
Is this actually correct?
Don't you want to run verification after actually doing the changes?
I.e. shouldn't this be