This is an archive of the discontinued LLVM Phabricator instance.

[RDA] Avoid full reprocessing of blocks in loops (NFCI)
ClosedPublic

Authored by nikic on Apr 5 2020, 1:08 PM.

Details

Summary

RDA sometimes needs to visit blocks twice, to take into account reaching defs coming in along loop back edges. Currently it handles repeated visitation the same way as usual, which means that it will scan through all instructions and their reg unit defs again. Not only is this very inefficient, it also means that all reaching defs in loops are going to be inserted twice.

We can do much better than this. The only thing we need to handle is a new reaching def from a predecessor, which either needs to be prepended to the reaching definitions (if there was no reaching def from a predecessor), or needs to replace an existing predecessor reaching def, if it is more recent. Since D77508 we only store the most recent predecessor reaching def, so that's the only one that may need updating.

This also has the nice side-effect that reaching definitions are now automatically sorted and unique, so drop the llvm::sort() call in favor of an assertion.

Diff Detail

Event Timeline

nikic created this revision.Apr 5 2020, 1:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 5 2020, 1:08 PM
samparker added inline comments.Apr 6 2020, 7:49 AM
lib/CodeGen/ReachingDefAnalysis.cpp
157 ↗(On Diff #255189)

It would be nice to reduce the indentation and just continue on the inverse. And maybe also continue when MBBReachingDefs[MBBNumber][Unit] is empty instead of comparing iterators below?

nikic updated this revision to Diff 255386.Apr 6 2020, 9:50 AM

Reduce indentation with early continue. Make NumInsts the number of non-debug instructions (as processDef is skipped for debug instructions).

nikic marked an inline comment as done.Apr 6 2020, 9:53 AM
nikic added inline comments.
lib/CodeGen/ReachingDefAnalysis.cpp
157 ↗(On Diff #255189)

I've added the early continue for the ReachingDefDefaultVal check. I don't think the same can be done if MBBReachingDefs[MBBNumber][Unit] is empty, because we do need to insert a reaching def (and possibly update the end of block reaching def) in that case.

samparker accepted this revision.Apr 6 2020, 11:01 PM

Okay, thanks for doing this. LGTM.

This revision is now accepted and ready to land.Apr 6 2020, 11:01 PM
This revision was automatically updated to reflect the committed changes.