From: Davide Italiano Date: Thu, 5 Oct 2017 18:06:37 +0000 (+0000) Subject: [PassManager] Run global optimizations after the inliner. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=300b37a6ada03c0eae8f1a9ce95cd916ae8b0429;p=llvm [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 --- diff --git a/lib/Transforms/IPO/PassManagerBuilder.cpp b/lib/Transforms/IPO/PassManagerBuilder.cpp index d23892292c3..1a17508d2b2 100644 --- a/lib/Transforms/IPO/PassManagerBuilder.cpp +++ b/lib/Transforms/IPO/PassManagerBuilder.cpp @@ -489,9 +489,11 @@ void PassManagerBuilder::populateModulePassManager( // Start of CallGraph SCC passes. if (!DisableUnitAtATime) MPM.add(createPruneEHPass()); // Remove dead EH info + bool RunInliner = false; if (Inliner) { MPM.add(Inliner); Inliner = nullptr; + RunInliner = true; } if (!DisableUnitAtATime) MPM.add(createPostOrderFunctionAttrsLegacyPass()); @@ -505,6 +507,18 @@ void PassManagerBuilder::populateModulePassManager( // pass manager that we are specifically trying to avoid. To prevent this // we must insert a no-op module pass to reset the pass manager. MPM.add(createBarrierNoopPass()); + + // 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. + if (RunInliner) { + MPM.add(createGlobalOptimizerPass()); + MPM.add(createGlobalDCEPass()); + } + if (RunPartialInlining) MPM.add(createPartialInliningPass()); diff --git a/test/CodeGen/AMDGPU/early-inline.ll b/test/CodeGen/AMDGPU/early-inline.ll index c871d54bec7..a4f970ee238 100644 --- a/test/CodeGen/AMDGPU/early-inline.ll +++ b/test/CodeGen/AMDGPU/early-inline.ll @@ -1,6 +1,5 @@ ; RUN: opt -mtriple=amdgcn-- -O1 -S -inline-threshold=1 -amdgpu-early-inline-all %s | FileCheck %s -; CHECK: @c_alias @c_alias = alias i32 (i32), i32 (i32)* @callee define i32 @callee(i32 %x) { @@ -17,6 +16,7 @@ entry: ; CHECK: mul i32 ; CHECK-NOT: call i32 +; CHECK: define i32 @c_alias define amdgpu_kernel void @caller(i32 %x) { entry: %res = call i32 @callee(i32 %x) diff --git a/test/Other/pass-pipelines.ll b/test/Other/pass-pipelines.ll index d47c02ee7a4..9ecfc4f6201 100644 --- a/test/Other/pass-pipelines.ll +++ b/test/Other/pass-pipelines.ll @@ -56,6 +56,8 @@ ; a barrier pass. ; CHECK-O2: A No-Op Barrier Pass ; Reduce the size of the IR ASAP after the inliner. +; CHECK-O2-NEXT: Global Variable Optimizer +; CHECK-O2: Dead Global Elimination ; CHECK-O2-NEXT: Eliminate Available Externally ; Inferring function attribute should be right after the CGSCC pipeline, before ; any other optimizations/analyses.