This is an archive of the discontinued LLVM Phabricator instance.

[PGOMemOPSize] Preserve the DominatorTree
ClosedPublic

Authored by NutshellySima on Jul 3 2018, 11:42 PM.

Details

Summary

PGOMemOPSize only modifies CFG in a couple of places; thus we can preserve the DominatorTree with little effort.
When optimizing SQLite with -O3, this patch can decrease 3.8% of the numbers of nodes traversed by DFS and 5.7% of the times DominatorTreeBase::recalculation is called.

Diff Detail

Repository
rL LLVM

Event Timeline

NutshellySima created this revision.Jul 3 2018, 11:42 PM
dmgreen added inline comments.Jul 4 2018, 12:17 AM
lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
346 ↗(On Diff #154053)

Why not use DTU for the whole thing ;)

432 ↗(On Diff #154053)

We can use getAnalysisIfAvailable to only get the DT if it's already been created by some other pass in the pipeline. That way we can preserve it if it already exists, but don't have to recalculate it if not.

443 ↗(On Diff #154053)

I think the new pass manager equivalent to getAnalysisIfAvailable is getCachedResult<..>(F).

Address comments.

NutshellySima marked 2 inline comments as done.Jul 5 2018, 12:06 AM
NutshellySima added inline comments.
lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
346 ↗(On Diff #154053)

SplitBlock currently only accepts DT. I'll take care of making these APIs consistent later.

The updates looks correct to me. Can you add a test for pgo-memop-opt that preserves the DT and verifies it's correct.

lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
346 ↗(On Diff #154053)

That sounds sensible. To do this bit at a time.

If/when you do try to convert SplitBlock to take a DTU, I think it may be best to just convert it to use the incremental updater, not using what DominatorTreeBase::splitBlock does right now. See D14723 if you want to make PDT's work with splitBlock, but I suspect the incremental updater will easier and not much slower (especially if the updates can be done lazily).

435 ↗(On Diff #154174)

This is often done with "DominatorTree *DT = DTWP ? &DTWP->getDomTree() : nullptr;" to put it all on a single line.

NutshellySima added inline comments.Jul 6 2018, 5:52 AM
lib/Transforms/Instrumentation/PGOMemOPSizeOpt.cpp
346 ↗(On Diff #154053)

For converting splitBlock to use the incremental updater, because DTU can return the current UpdateStratrgy, I think we can implement the code to use the incremental way when the strategy is lazy and use the current approach + PDT support when the strategy is eager.

I used this approach in D48967 (llvm::MergeBasicBlockIntoOnlyPred and llvm::MergeBlockIntoPredecessor).

If some timing/benchmarking shows that the performance won't be affected too much, we can then make splitBlock to use the incremental updater under both updateStrategies.

  1. Use opt -verify-dom-info to verify DomTree.
  2. Address comments.
NutshellySima set the repository for this revision to rL LLVM.Jul 6 2018, 7:03 AM
NutshellySima marked an inline comment as done.
NutshellySima marked 4 inline comments as done.Jul 7 2018, 4:43 AM
dmgreen accepted this revision.Jul 8 2018, 1:42 AM

LGTM

test/Transforms/PGOProfile/memop_clone.ll
1 ↗(On Diff #154401)

pgo-memop-opt requires LoopInfo, which requires DomTree, right? So this will test preserving the DT. SGTM.

This revision is now accepted and ready to land.Jul 8 2018, 1:42 AM
NutshellySima added inline comments.Jul 8 2018, 4:47 AM
test/Transforms/PGOProfile/memop_clone.ll
1 ↗(On Diff #154401)

Yes. I also tried with an invalid DomTree, it indeed asserts as expected.

This revision was automatically updated to reflect the committed changes.