Skip to content

Commit 6617529

Browse files
committed
[CodeGen][DwarfEHPrepare] Preserve Dominator Tree
Now that D94827 has flipped the switch, and SimplifyCFG is officially marked as production-ready regarding Dominator Tree preservation, 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 Differential Revision: https://reviews.llvm.org/D95548
1 parent 8cfa963 commit 6617529

File tree

3 files changed

+8
-18
lines changed

3 files changed

+8
-18
lines changed

llvm/lib/CodeGen/DwarfEHPrepare.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ size_t DwarfEHPrepare::pruneUnreachableResumes(
153153
BasicBlock *BB = RI->getParent();
154154
new UnreachableInst(Ctx, RI);
155155
RI->eraseFromParent();
156-
simplifyCFG(BB, *TTI, RequireAndPreserveDomTree ? DTU : nullptr);
156+
simplifyCFG(BB, *TTI, DTU);
157157
}
158158
}
159159
Resumes.resize(ResumesLeft);
@@ -242,33 +242,23 @@ bool DwarfEHPrepare::InsertUnwindResumeCalls() {
242242
CI->setDoesNotReturn();
243243
new UnreachableInst(Ctx, UnwindBB);
244244

245-
if (DTU && RequireAndPreserveDomTree)
245+
if (DTU)
246246
DTU->applyUpdates(Updates);
247247

248248
return true;
249249
}
250250

251251
bool DwarfEHPrepare::run() {
252-
assert(((OptLevel == CodeGenOpt::None || !RequireAndPreserveDomTree) ||
253-
(DTU &&
254-
DTU->getDomTree().verify(DominatorTree::VerificationLevel::Full))) &&
255-
"Original domtree is invalid?");
256-
257252
bool Changed = InsertUnwindResumeCalls();
258253

259-
assert(((OptLevel == CodeGenOpt::None || !RequireAndPreserveDomTree) ||
260-
(DTU &&
261-
DTU->getDomTree().verify(DominatorTree::VerificationLevel::Full))) &&
262-
"Original domtree is invalid?");
263-
264254
return Changed;
265255
}
266256

267257
static bool prepareDwarfEH(CodeGenOpt::Level OptLevel,
268258
FunctionCallee &RewindFunction, Function &F,
269259
const TargetLowering &TLI, DominatorTree *DT,
270260
const TargetTransformInfo *TTI) {
271-
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Eager);
261+
DomTreeUpdater DTU(DT, DomTreeUpdater::UpdateStrategy::Lazy);
272262

273263
return DwarfEHPrepare(OptLevel, RewindFunction, F, TLI, DT ? &DTU : nullptr,
274264
TTI)
@@ -295,8 +285,11 @@ class DwarfEHPrepareLegacyPass : public FunctionPass {
295285
const TargetLowering &TLI = *TM.getSubtargetImpl(F)->getTargetLowering();
296286
DominatorTree *DT = nullptr;
297287
const TargetTransformInfo *TTI = nullptr;
288+
if (auto *DTWP = getAnalysisIfAvailable<DominatorTreeWrapperPass>())
289+
DT = &DTWP->getDomTree();
298290
if (OptLevel != CodeGenOpt::None) {
299-
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
291+
if (!DT)
292+
DT = &getAnalysis<DominatorTreeWrapperPass>().getDomTree();
300293
TTI = &getAnalysis<TargetTransformInfoWrapperPass>().getTTI(F);
301294
}
302295
return prepareDwarfEH(OptLevel, RewindFunction, F, TLI, DT, TTI);
@@ -308,9 +301,8 @@ class DwarfEHPrepareLegacyPass : public FunctionPass {
308301
if (OptLevel != CodeGenOpt::None) {
309302
AU.addRequired<DominatorTreeWrapperPass>();
310303
AU.addRequired<TargetTransformInfoWrapperPass>();
311-
if (RequireAndPreserveDomTree)
312-
AU.addPreserved<DominatorTreeWrapperPass>();
313304
}
305+
AU.addPreserved<DominatorTreeWrapperPass>();
314306
}
315307

316308
StringRef getPassName() const override {

llvm/test/CodeGen/ARM/O3-pipeline.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
; CHECK-NEXT: Dominator Tree Construction
5656
; CHECK-NEXT: Exception handling preparation
5757
; CHECK-NEXT: Merge internal globals
58-
; CHECK-NEXT: Dominator Tree Construction
5958
; CHECK-NEXT: Natural Loop Information
6059
; CHECK-NEXT: Scalar Evolution Analysis
6160
; CHECK-NEXT: Lazy Branch Probability Analysis

llvm/test/CodeGen/X86/opt-pipeline.ll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
; CHECK-NEXT: Safe Stack instrumentation pass
7070
; CHECK-NEXT: Insert stack protectors
7171
; CHECK-NEXT: Module Verifier
72-
; CHECK-NEXT: Dominator Tree Construction
7372
; CHECK-NEXT: Basic Alias Analysis (stateless AA impl)
7473
; CHECK-NEXT: Function Alias Analysis Results
7574
; CHECK-NEXT: Natural Loop Information

0 commit comments

Comments
 (0)