Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit 1aecec4

Browse files
dccialexcrichton
authored andcommitted
[PassManager] Run global optimizations after the inliner.
The inliner performs some kind of dead code elimination as it goes, but there are cases that are not really caught by it. We might at some point consider teaching the inliner about them, but it is OK for now to run GlobalOpt + GlobalDCE in tandem as their benefits generally outweight the cost, making the whole pipeline faster. This fixes PR34652. Differential Revision: https://reviews.llvm.org/D38154 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@314997 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent d9e7d26 commit 1aecec4

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

lib/Transforms/IPO/PassManagerBuilder.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -475,9 +475,11 @@ void PassManagerBuilder::populateModulePassManager(
475475
// Start of CallGraph SCC passes.
476476
if (!DisableUnitAtATime)
477477
MPM.add(createPruneEHPass()); // Remove dead EH info
478+
bool RunInliner = false;
478479
if (Inliner) {
479480
MPM.add(Inliner);
480481
Inliner = nullptr;
482+
RunInliner = true;
481483
}
482484
if (!DisableUnitAtATime)
483485
MPM.add(createPostOrderFunctionAttrsLegacyPass());
@@ -492,6 +494,17 @@ void PassManagerBuilder::populateModulePassManager(
492494
// we must insert a no-op module pass to reset the pass manager.
493495
MPM.add(createBarrierNoopPass());
494496

497+
// The inliner performs some kind of dead code elimination as it goes,
498+
// but there are cases that are not really caught by it. We might
499+
// at some point consider teaching the inliner about them, but it
500+
// is OK for now to run GlobalOpt + GlobalDCE in tandem as their
501+
// benefits generally outweight the cost, making the whole pipeline
502+
// faster.
503+
if (RunInliner) {
504+
MPM.add(createGlobalOptimizerPass());
505+
MPM.add(createGlobalDCEPass());
506+
}
507+
495508
if (!DisableUnitAtATime && OptLevel > 1 && !PrepareForLTO &&
496509
!PrepareForThinLTO)
497510
// Remove avail extern fns and globals definitions if we aren't

test/Other/pass-pipelines.ll

+2
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
; a barrier pass.
5757
; CHECK-O2: A No-Op Barrier Pass
5858
; Reduce the size of the IR ASAP after the inliner.
59+
; CHECK-O2-NEXT: Global Variable Optimizer
60+
; CHECK-O2: Dead Global Elimination
5961
; CHECK-O2-NEXT: Eliminate Available Externally
6062
; Inferring function attribute should be right after the CGSCC pipeline, before
6163
; any other optimizations/analyses.

0 commit comments

Comments
 (0)