This is an archive of the discontinued LLVM Phabricator instance.

Update MemorySSA in LoopRotate.
ClosedPublic

Authored by asbirlea on Sep 5 2018, 11:31 PM.

Details

Summary

Teach LoopRotate to preserve MemorySSA.
Enable tests for correctness, dependency disabled by default.

Diff Detail

Event Timeline

asbirlea created this revision.Sep 5 2018, 11:31 PM
asbirlea updated this revision to Diff 164261.Sep 6 2018, 11:55 AM

Enable tests. Add new tests to check analysis is preserved.

asbirlea edited the summary of this revision. (Show Details)Sep 6 2018, 11:58 AM
asbirlea added reviewers: greened, chandlerc, bogner.
asbirlea updated this revision to Diff 164288.Sep 6 2018, 2:19 PM

Update test and format.

asbirlea updated this revision to Diff 164939.Sep 11 2018, 11:48 AM

Moving the MSSA after cloning earlier to avoid the ValueMap invalidation.
Adding another test.
And ping.

greened added inline comments.Sep 20 2018, 11:07 AM
lib/Transforms/Scalar/LoopRotation.cpp
49

Why not just pass the Optional?

106

Again, maybe just pass the Optional.

lib/Transforms/Utils/LoopRotationUtils.cpp
59

Use an Optional here?

276

These tests should remain the same with an Optional.

asbirlea added inline comments.Sep 20 2018, 1:26 PM
lib/Transforms/Scalar/LoopRotation.cpp
49

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.

asbirlea updated this revision to Diff 166362.Sep 20 2018, 2:22 PM

Update pr35210.ll after recent upstream changes.

greened added inline comments.Sep 20 2018, 6:20 PM
lib/Transforms/Scalar/LoopRotation.cpp
49

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.

asbirlea added inline comments.Sep 24 2018, 2:36 PM
lib/Transforms/Scalar/LoopRotation.cpp
49

It can be expensive if not used but it should be cheaper than MemoryDependenceAnalysis the AliasSetTracker.
End goal is to use it in LICM instead of AST, and in BBUtils instead of MemoryDependenceAnalysis. There are probably others, but these are on my list for now.

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.
I think such a refactoring should be separate from this patch.
What do you think?

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

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!

chandlerc accepted this revision.Oct 22 2018, 1:15 PM

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?

This revision is now accepted and ready to land.Oct 22 2018, 1:15 PM
asbirlea updated this revision to Diff 170530.Oct 22 2018, 5:12 PM

Test updated. Thank you for the review!

asbirlea marked 9 inline comments as done.Oct 22 2018, 5:13 PM
This revision was automatically updated to reflect the committed changes.
lebedev.ri added inline comments.
llvm/trunk/lib/Transforms/Utils/LoopRotationUtils.cpp
682–687 ↗(On Diff #171013)

@asbirlea @fhahn

Is this actually correct?
Don't you want to run verification after actually doing the changes?
I.e. shouldn't this be

{
  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;
}
Herald added a project: Restricted Project. · View Herald TranscriptJul 14 2020, 6:50 AM
fhahn added inline comments.Jul 14 2020, 7:01 AM
llvm/trunk/lib/Transforms/Utils/LoopRotationUtils.cpp
682–687 ↗(On Diff #171013)

Yeah the code in the patch doesn't look right, given that the actual modifications happen in processLoop.

asbirlea marked an inline comment as done.Jul 14 2020, 10:00 AM
asbirlea added inline comments.
llvm/trunk/lib/Transforms/Utils/LoopRotationUtils.cpp
682–687 ↗(On Diff #171013)

It's correct, but unnecessary. Thank you for noticing!
That verification can be removed, since there are additional verificatons inside LoopRotate::rotateLoop that should cover the need to verify after the LR.processLoop(L); call.

fhahn added inline comments.Jul 15 2020, 4:01 AM
llvm/trunk/lib/Transforms/Utils/LoopRotationUtils.cpp
682–687 ↗(On Diff #171013)

I dropped the verify calls there in 9ea0d8c38fc5