diff --git a/clang/test/CodeGen/pgo-sample.c b/clang/test/CodeGen/pgo-sample.c --- a/clang/test/CodeGen/pgo-sample.c +++ b/clang/test/CodeGen/pgo-sample.c @@ -1,6 +1,16 @@ // Test if PGO sample use passes are invoked. // // Ensure Pass PGOInstrumentationGenPass is invoked. -// RUN: %clang_cc1 -O2 -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -// CHECK: Remove unused exception handling info -// CHECK: Sample profile pass +// RUN: %clang_cc1 -O2 -fno-experimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=LEGACY +// RUN: %clang_cc1 -O2 -fexperimental-new-pass-manager -fprofile-sample-use=%S/Inputs/pgo-sample.prof %s -fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s --check-prefix=NEWPM + +// LEGACY: Remove unused exception handling info +// LEGACY: Sample profile pass + +// The new pass manager analog to PruneEH is a combination of 'function-attrs' +// and 'function(simplify-cgf)'. +// NEWPM-DAG: PostOrderFunctionAttrsPass +// NEWPM-DAG: SimplifyCFGPass +// NEWPM: SampleProfileLoaderPass + +int func(int a) { return a; } 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 @@ -659,8 +659,15 @@ // More details about SamplePGO design can be found in: // https://research.google.com/pubs/pub45290.html // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured. - if (LoadSampleProfile) + if (LoadSampleProfile) { EarlyFPM.addPass(InstCombinePass()); + + // We must also remove exception handling before attaching sample profile + // data. + MPM.addPass( + createModuleToPostOrderCGSCCPassAdaptor(PostOrderFunctionAttrsPass())); + EarlyFPM.addPass(SimplifyCFGPass()); + } MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM))); if (LoadSampleProfile) { diff --git a/llvm/test/Other/new-pm-pgo.ll b/llvm/test/Other/new-pm-pgo.ll --- a/llvm/test/Other/new-pm-pgo.ll +++ b/llvm/test/Other/new-pm-pgo.ll @@ -16,11 +16,13 @@ ; USE: Running pass: PGOMemOPSizeOpt ; SAMPLE_USE_O: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}> ; SAMPLE_USE_PRE_LINK: Running pass: ModuleToFunctionPassAdaptor<{{.*}}AddDiscriminatorsPass{{.*}}> +; SAMPLE_USE_POST_LINK: Running pass: ModuleToPostOrderCGSCCPassAdaptor ; SAMPLE_USE: Running pass: SimplifyCFGPass ; SAMPLE_USE: Running pass: SROA ; SAMPLE_USE: Running pass: EarlyCSEPass ; SAMPLE_USE: Running pass: LowerExpectIntrinsicPass ; SAMPLE_USE_POST_LINK: Running pass: InstCombinePass +; SAMPLE_USE_POST_LINK: Running pass: SimplifyCFGPass ; SAMPLE_USE: Running pass: SampleProfileLoaderPass ; SAMPLE_USE_O: Running pass: PGOIndirectCallPromotion ; SAMPLE_USE_POST_LINK-NOT: Running pass: GlobalOptPass