diff --git a/llvm/include/llvm/Passes/PassBuilder.h b/llvm/include/llvm/Passes/PassBuilder.h --- a/llvm/include/llvm/Passes/PassBuilder.h +++ b/llvm/include/llvm/Passes/PassBuilder.h @@ -392,6 +392,9 @@ bool DebugLogging, ModuleSummaryIndex *ExportSummary); + void addLateLTOOptimizationPasses(ModulePassManager &MPM, + ModuleSummaryIndex *ExportSummary); + /// Build the default `AAManager` with the default alias analysis pipeline /// registered. AAManager buildDefaultAAPipeline(); diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -1151,9 +1151,7 @@ // Stop here at -O1. if (Level == 1) { - // The LowerTypeTestsPass needs to run to lower type metadata and the - // type.test intrinsics. The pass does nothing if CFI is disabled. - MPM.addPass(LowerTypeTestsPass(ExportSummary, nullptr)); + addLateLTOOptimizationPasses(MPM, ExportSummary); return MPM; } @@ -1277,6 +1275,13 @@ // targets in the current module. MPM.addPass(CrossDSOCFIPass()); + addLateLTOOptimizationPasses(MPM, ExportSummary); + + return MPM; +} + +void PassBuilder::addLateLTOOptimizationPasses( + ModulePassManager &MPM, ModuleSummaryIndex *ExportSummary) { // Lower type metadata and the type.test intrinsic. This pass supports // clang's control flow integrity mechanisms (-fsanitize=cfi*) and needs // to be run at link time if CFI is enabled. This pass does nothing if @@ -1299,7 +1304,6 @@ MPM.addPass(GlobalDCEPass()); // FIXME: Enable MergeFuncs, conditionally, after ported, maybe. - return MPM; } AAManager PassBuilder::buildDefaultAAPipeline() { diff --git a/llvm/test/Other/new-pm-lto-defaults.ll b/llvm/test/Other/new-pm-lto-defaults.ll --- a/llvm/test/Other/new-pm-lto-defaults.ll +++ b/llvm/test/Other/new-pm-lto-defaults.ll @@ -60,7 +60,6 @@ ; CHECK-O-NEXT: Running analysis: CallGraphAnalysis ; CHECK-O-NEXT: Running pass: GlobalSplitPass ; CHECK-O-NEXT: Running pass: WholeProgramDevirtPass -; CHECK-O1-NEXT: Running pass: LowerTypeTestsPass ; CHECK-O2-NEXT: Running pass: GlobalOptPass ; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}PromotePass> ; CHECK-O2-NEXT: Running pass: ConstantMergePass @@ -90,10 +89,12 @@ ; CHECK-O2-NEXT: Running analysis: PhiValuesAnalysis ; CHECK-O2-NEXT: Running analysis: DemandedBitsAnalysis ; CHECK-O2-NEXT: Running pass: CrossDSOCFIPass -; CHECK-O2-NEXT: Running pass: LowerTypeTestsPass -; CHECK-O2-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}SimplifyCFGPass> -; CHECK-O2-NEXT: Running pass: EliminateAvailableExternallyPass -; CHECK-O2-NEXT: Running pass: GlobalDCEPass +; CHECK-O-NEXT: Running pass: LowerTypeTestsPass +; CHECK-O-NEXT: Running pass: ModuleToFunctionPassAdaptor<{{.*}}SimplifyCFGPass> +; CHECK-O1-NEXT: Running analysis: TargetIRAnalysis on foo +; CHECK-O1-NEXT: Running analysis: AssumptionAnalysis on foo +; CHECK-O-NEXT: Running pass: EliminateAvailableExternallyPass +; CHECK-O-NEXT: Running pass: GlobalDCEPass ; CHECK-O-NEXT: Finished llvm::Module pass manager run. ; CHECK-O-NEXT: Running pass: PrintModulePass diff --git a/llvm/test/tools/gold/X86/opt-level.ll b/llvm/test/tools/gold/X86/opt-level.ll --- a/llvm/test/tools/gold/X86/opt-level.ll +++ b/llvm/test/tools/gold/X86/opt-level.ll @@ -6,7 +6,7 @@ ; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext -plugin-opt=save-temps \ ; RUN: -m elf_x86_64 \ ; RUN: -plugin-opt=O1 -r -o %t.o %t.bc -; RUN: llvm-dis < %t.o.0.4.opt.bc -o - | FileCheck --check-prefix=CHECK-O1 --check-prefix=CHECK-O1-OLDPM %s +; RUN: llvm-dis < %t.o.0.4.opt.bc -o - | FileCheck --check-prefix=CHECK-O1 %s ; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext -plugin-opt=save-temps \ ; RUN: -m elf_x86_64 \ ; RUN: -plugin-opt=O2 -r -o %t.o %t.bc @@ -19,7 +19,7 @@ ; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext -plugin-opt=save-temps \ ; RUN: -m elf_x86_64 --plugin-opt=new-pass-manager \ ; RUN: -plugin-opt=O1 -r -o %t.o %t.bc -; RUN: llvm-dis < %t.o.0.4.opt.bc -o - | FileCheck --check-prefix=CHECK-O1 --check-prefix=CHECK-O1-NEWPM %s +; RUN: llvm-dis < %t.o.0.4.opt.bc -o - | FileCheck --check-prefix=CHECK-O1 %s ; RUN: %gold -plugin %llvmshlibdir/LLVMgold%shlibext -plugin-opt=save-temps \ ; RUN: -m elf_x86_64 --plugin-opt=new-pass-manager \ ; RUN: -plugin-opt=O2 -r -o %t.o %t.bc @@ -49,9 +49,7 @@ end: ; CHECK-O0: phi - ; CHECK-O1-OLDPM: select - ; The new PM does not do as many optimizations at O1 - ; CHECK-O1-NEWPM: phi + ; CHECK-O1: select %r = phi i32 [ 1, %t ], [ 2, %f ] ret i32 %r }