]> granicus.if.org Git - llvm/commitdiff
Resubmit r356511 "[TailCallElim] Add tailcall elimination pass to LTO pipelines"
authorRobert Lougher <rob.lougher@gmail.com>
Wed, 20 Mar 2019 19:08:18 +0000 (19:08 +0000)
committerRobert Lougher <rob.lougher@gmail.com>
Wed, 20 Mar 2019 19:08:18 +0000 (19:08 +0000)
Failing LLD tests have been fixed in r356593.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@356594 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Passes/PassBuilder.cpp
lib/Transforms/IPO/PassManagerBuilder.cpp
test/LTO/X86/tailcallelim.ll [new file with mode: 0644]
test/Other/new-pm-lto-defaults.ll

index 2baff8990105d7b485cf9fd3868771a453a0235d..ba0d6c2bd684a439007003c62b894dfa9598d5c0 100644 (file)
@@ -1185,6 +1185,10 @@ PassBuilder::buildLTODefaultPipeline(OptimizationLevel Level, bool DebugLogging,
   // Break up allocas
   FPM.addPass(SROA());
 
+  // LTO provides additional opportunities for tailcall elimination due to
+  // link-time inlining, and visibility of nocapture attribute.
+  FPM.addPass(TailCallElimPass());
+
   // Run a few AA driver optimizations here and now to cleanup the code.
   MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
 
index 0505135673b1b432961001331ededa36c938613c..9e241aa335aee24598c92bbea6fe59a5145d4004 100644 (file)
@@ -896,6 +896,10 @@ void PassManagerBuilder::addLTOOptimizationPasses(legacy::PassManagerBase &PM) {
   // Break up allocas
   PM.add(createSROAPass());
 
+  // LTO provides additional opportunities for tailcall elimination due to
+  // link-time inlining, and visibility of nocapture attribute.
+  PM.add(createTailCallEliminationPass());
+
   // Run a few AA driven optimizations here and now, to cleanup the code.
   PM.add(createPostOrderFunctionAttrsLegacyPass()); // Add nocapture.
   PM.add(createGlobalsAAWrapperPass()); // IP alias analysis.
diff --git a/test/LTO/X86/tailcallelim.ll b/test/LTO/X86/tailcallelim.ll
new file mode 100644 (file)
index 0000000..2c3a9b5
--- /dev/null
@@ -0,0 +1,22 @@
+; Check that the LTO pipelines add the Tail Call Elimination pass.
+
+; RUN: llvm-as < %s > %t1
+; RUN: llvm-lto -o %t2 %t1 --exported-symbol=foo -save-merged-module
+; RUN: llvm-dis < %t2.merged.bc | FileCheck %s
+
+; RUN: llvm-lto2 run -r %t1,foo,plx -r %t1,bar,plx -o %t3 %t1 -save-temps
+; RUN: llvm-dis < %t3.0.4.opt.bc | FileCheck %s
+
+; RUN: llvm-lto2 run -r %t1,foo,plx -r %t1,bar,plx -o %t4 %t1 -save-temps -use-new-pm
+; RUN: llvm-dis < %t4.0.4.opt.bc | FileCheck %s
+
+target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @foo() {
+; CHECK: tail call void @bar()
+  call void @bar()
+  ret void
+}
+
+declare void @bar()
index ee2f0414e6285d9965e588a0ca13ad847d6f43ca..a3eaa1e856aa70585daac94f729ce0ce0e502f4c 100644 (file)
@@ -81,6 +81,7 @@
 ; CHECK-O2-NEXT: Running pass: JumpThreadingPass
 ; CHECK-O2-NEXT: Running analysis: LazyValueAnalysis
 ; CHECK-O2-NEXT: Running pass: SROA on foo
+; CHECK-O2-NEXT: Running pass: TailCallElimPass on foo
 ; CHECK-O2-NEXT: Finished llvm::Function pass manager run.
 ; CHECK-O2-NEXT: Running pass: ModuleToPostOrderCGSCCPassAdaptor<{{.*}}PostOrderFunctionAttrsPass>
 ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PassManager{{.*}}>