[llvm] r314997 - [PassManager] Run global optimizations after the inliner.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 11:06:37 PDT 2017


Author: davide
Date: Thu Oct  5 11:06:37 2017
New Revision: 314997

URL: http://llvm.org/viewvc/llvm-project?rev=314997&view=rev
Log:
[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

Modified:
    llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
    llvm/trunk/test/CodeGen/AMDGPU/early-inline.ll
    llvm/trunk/test/Other/pass-pipelines.ll

Modified: llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp?rev=314997&r1=314996&r2=314997&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/PassManagerBuilder.cpp Thu Oct  5 11:06:37 2017
@@ -489,9 +489,11 @@ void PassManagerBuilder::populateModuleP
   // 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::populateModuleP
   // 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());
 

Modified: llvm/trunk/test/CodeGen/AMDGPU/early-inline.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/AMDGPU/early-inline.ll?rev=314997&r1=314996&r2=314997&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/AMDGPU/early-inline.ll (original)
+++ llvm/trunk/test/CodeGen/AMDGPU/early-inline.ll Thu Oct  5 11:06:37 2017
@@ -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)

Modified: llvm/trunk/test/Other/pass-pipelines.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Other/pass-pipelines.ll?rev=314997&r1=314996&r2=314997&view=diff
==============================================================================
--- llvm/trunk/test/Other/pass-pipelines.ll (original)
+++ llvm/trunk/test/Other/pass-pipelines.ll Thu Oct  5 11:06:37 2017
@@ -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.




More information about the llvm-commits mailing list