This is an archive of the discontinued LLVM Phabricator instance.

[LPM/BPI] Preserve BPI through trivial loop pass pipeline
ClosedPublic

Authored by reames on Apr 16 2019, 12:26 PM.

Details

Summary

Currently, we do not expose BPI to loop passes at all. In the old pass manager, we somehow ended up with valid BPI (at least in some circumstances); in the new one, it's invalidated before running any loop pass if either LCSSA or LoopSimplify actually make changes. If they don't make changes, then BPI is valid and available.

I'm not sure that we're going to be able to push through BPI through all loop passes, and the behaviour of an non-preserved by a loop pass function analysis worries me quite a bit. However, I think it's worth supporting at least simple cases, which is what these changes do.

Here's the reasoning by which preservation is correct for each:

  • LCSSA does not modify the CFG. BPI only maps terminator instructions to data, so not modifying the CFG ensures data validity.
  • LoopSimplify can insert blocks, but it does so only by splitting existing blocks and edges. This results in the interesting property that all new terminators are unconditional branches. BPI does not contain entries for such terminators. All deletions are handled via ValueHandle callbacks w/in BPI.

This avoids an invalidation between the two requires in the following trivial pass pipeline:
opt -passes="requires<branch-prob>,loop(no-op-loop),requires<branch-prob>"

Diff Detail

Repository
rL LLVM

Event Timeline

reames created this revision.Apr 16 2019, 12:26 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 16 2019, 12:26 PM

Can you please take the rationale, especially for LoopSimplify, and add it as a comment in the source code? At some point someone might break this invariant, and without the comment, they'll be no easy way to know that.

reames updated this revision to Diff 195753.Apr 18 2019, 8:39 AM

Address review comment

hfinkel accepted this revision.Apr 19 2019, 12:05 PM

Hal, ping?

LGTM

This revision is now accepted and ready to land.Apr 19 2019, 12:05 PM
This revision was automatically updated to reflect the committed changes.