diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp --- a/llvm/lib/Passes/PassBuilderPipelines.cpp +++ b/llvm/lib/Passes/PassBuilderPipelines.cpp @@ -951,22 +951,26 @@ if (Phase == ThinOrFullLTOPhase::ThinLTOPostLink && !LoadSampleProfile) MPM.addPass(PGOIndirectCallPromotion(true /* InLTO */, HasSampleProfile)); - // Do basic inference of function attributes from known properties of system - // libraries and other oracles. - MPM.addPass(InferFunctionAttrsPass()); - MPM.addPass(CoroEarlyPass()); - // Create an early function pass manager to cleanup the output of the - // frontend. + // frontend. Not necessary with LTO post link pipelines since the pre link + // pipeline already cleaned up the frontend output. FunctionPassManager EarlyFPM; - // Lower llvm.expect to metadata before attempting transforms. - // Compare/branch metadata may alter the behavior of passes like SimplifyCFG. - EarlyFPM.addPass(LowerExpectIntrinsicPass()); - EarlyFPM.addPass(SimplifyCFGPass()); - EarlyFPM.addPass(SROAPass(SROAOptions::ModifyCFG)); - EarlyFPM.addPass(EarlyCSEPass()); - if (Level == OptimizationLevel::O3) - EarlyFPM.addPass(CallSiteSplittingPass()); + if (Phase != ThinOrFullLTOPhase::ThinLTOPostLink) { + // Do basic inference of function attributes from known properties of system + // libraries and other oracles. + MPM.addPass(InferFunctionAttrsPass()); + MPM.addPass(CoroEarlyPass()); + + // Lower llvm.expect to metadata before attempting transforms. + // Compare/branch metadata may alter the behavior of passes like + // SimplifyCFG. + EarlyFPM.addPass(LowerExpectIntrinsicPass()); + EarlyFPM.addPass(SimplifyCFGPass()); + EarlyFPM.addPass(SROAPass(SROAOptions::ModifyCFG)); + EarlyFPM.addPass(EarlyCSEPass()); + if (Level == OptimizationLevel::O3) + EarlyFPM.addPass(CallSiteSplittingPass()); + } // In SamplePGO ThinLTO backend, we need instcombine before profile annotation // to convert bitcast to direct calls so that they can be inlined during the @@ -976,8 +980,10 @@ // FIXME: revisit how SampleProfileLoad/Inliner/ICP is structured. if (LoadSampleProfile) EarlyFPM.addPass(InstCombinePass()); - MPM.addPass(createModuleToFunctionPassAdaptor(std::move(EarlyFPM), - PTO.EagerlyInvalidateAnalyses)); + + if (!EarlyFPM.isEmpty()) + MPM.addPass(createModuleToFunctionPassAdaptor( + std::move(EarlyFPM), PTO.EagerlyInvalidateAnalyses)); if (LoadSampleProfile) { // Annotate sample profile right after early FPM to ensure freshness of