[PATCH] D95548: [DwarfEHPrepare] Preserve Dominator Tree

Roman Lebedev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 27 10:58:28 PST 2021


lebedev.ri created this revision.
lebedev.ri added reviewers: fhahn, jdoerfert, arsenm, mkazantsev, kuhar, brzycki, nikic.
lebedev.ri added a project: LLVM.
Herald added subscribers: pengfei, hiraditya.
lebedev.ri requested review of this revision.
Herald added a subscriber: wdng.

Now that D94827 <https://reviews.llvm.org/D94827> has flipped the switch, and SimplifyCFG is officially marked
as production-ready to preserve Dominator Tree,
we can update this user pass to also preserve Dominator Tree.

This is a geomean compile-time win of `-0.05%`..`-0.08%`.
https://llvm-compile-time-tracker.com/compare.php?from=51a25846c198cff00abad0936f975167357afa6f&to=082499aac236a5c141e50a9e77870d5be2de5f0b&stat=instructions


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95548

Files:
  llvm/lib/CodeGen/DwarfEHPrepare.cpp
  llvm/test/CodeGen/ARM/O3-pipeline.ll
  llvm/test/CodeGen/X86/opt-pipeline.ll


Index: llvm/test/CodeGen/X86/opt-pipeline.ll
===================================================================
--- llvm/test/CodeGen/X86/opt-pipeline.ll
+++ llvm/test/CodeGen/X86/opt-pipeline.ll
@@ -70,7 +70,6 @@
 ; CHECK-NEXT:       Safe Stack instrumentation pass
 ; CHECK-NEXT:       Insert stack protectors
 ; CHECK-NEXT:       Module Verifier
-; CHECK-NEXT:       Dominator Tree Construction
 ; CHECK-NEXT:       Basic Alias Analysis (stateless AA impl)
 ; CHECK-NEXT:       Function Alias Analysis Results
 ; CHECK-NEXT:       Natural Loop Information
Index: llvm/test/CodeGen/ARM/O3-pipeline.ll
===================================================================
--- llvm/test/CodeGen/ARM/O3-pipeline.ll
+++ llvm/test/CodeGen/ARM/O3-pipeline.ll
@@ -55,7 +55,6 @@
 ; CHECK-NEXT:      Dominator Tree Construction
 ; CHECK-NEXT:      Exception handling preparation
 ; CHECK-NEXT:      Merge internal globals
-; CHECK-NEXT:      Dominator Tree Construction
 ; CHECK-NEXT:      Natural Loop Information
 ; CHECK-NEXT:      Scalar Evolution Analysis
 ; CHECK-NEXT:      Lazy Branch Probability Analysis
Index: llvm/lib/CodeGen/DwarfEHPrepare.cpp
===================================================================
--- llvm/lib/CodeGen/DwarfEHPrepare.cpp
+++ llvm/lib/CodeGen/DwarfEHPrepare.cpp
@@ -153,7 +153,7 @@
       BasicBlock *BB = RI->getParent();
       new UnreachableInst(Ctx, RI);
       RI->eraseFromParent();
-      simplifyCFG(BB, *TTI, RequireAndPreserveDomTree ? DTU : nullptr);
+      simplifyCFG(BB, *TTI, DTU);
     }
   }
   Resumes.resize(ResumesLeft);
@@ -242,25 +242,15 @@
   CI->setDoesNotReturn();
   new UnreachableInst(Ctx, UnwindBB);
 
-  if (DTU && RequireAndPreserveDomTree)
+  if (DTU)
     DTU->applyUpdates(Updates);
 
   return true;
 }
 
 bool DwarfEHPrepare::run() {
-  assert(((OptLevel == CodeGenOpt::None || !RequireAndPreserveDomTree) ||
-          (DTU &&
-           DTU->getDomTree().verify(DominatorTree::VerificationLevel::Full))) &&
-         "Original domtree is invalid?");
-
   bool Changed = InsertUnwindResumeCalls();
 
-  assert(((OptLevel == CodeGenOpt::None || !RequireAndPreserveDomTree) ||
-          (DTU &&
-           DTU->getDomTree().verify(DominatorTree::VerificationLevel::Full))) &&
-         "Original domtree is invalid?");
-
   return Changed;
 }
 
@@ -268,7 +258,7 @@
                            FunctionCallee &RewindFunction, Function &F,
                            const TargetLowering &TLI, DominatorTree *DT,
                            const TargetTransformInfo *TTI) {
-  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
+  DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
 
   return DwarfEHPrepare(OptLevel, RewindFunction, F, TLI, DT ? &DTU : nullptr,
                         TTI)
@@ -295,8 +285,11 @@
     const TargetLowering &TLI = *TM.getSubtargetImpl(F)->getTargetLowering();
     DominatorTree *DT = nullptr;
     const TargetTransformInfo *TTI = nullptr;
+    if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
+      DT = &DTWP->getDomTree();
     if (OptLevel != CodeGenOpt::None) {
-      DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
+      if (!DT)
+        DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
       TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
     }
     return prepareDwarfEH(OptLevel, RewindFunction, F, TLI, DT, TTI);
@@ -308,9 +301,8 @@
     if (OptLevel != CodeGenOpt::None) {
       AU.addRequired<DominatorTreeWrapperPass>();
       AU.addRequired<TargetTransformInfoWrapperPass>();
-      if (RequireAndPreserveDomTree)
-        AU.addPreserved<DominatorTreeWrapperPass>();
     }
+    AU.addPreserved<DominatorTreeWrapperPass>();
   }
 
   StringRef getPassName() const override {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95548.319625.patch
Type: text/x-patch
Size: 3790 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210127/b2970421/attachment-0001.bin>


More information about the llvm-commits mailing list