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 @@ -1072,6 +1072,14 @@ MPM.addPass(CoroCleanupPass()); + // Optimize globals now that functions are fully simplified. + MPM.addPass(GlobalOptPass()); + + // Remove dead code, except in the ThinLTO pre-link pipeline where we may want + // to keep available_externally functions. + if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink) + MPM.addPass(GlobalDCEPass()); + if (EnableMemProfiler && Phase != ThinOrFullLTOPhase::ThinLTOPreLink) { MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass())); MPM.addPass(ModuleMemProfilerPass()); @@ -1227,10 +1235,6 @@ LTOPhase == ThinOrFullLTOPhase::FullLTOPreLink); ModulePassManager MPM; - // Optimize globals now that the module is fully simplified. - MPM.addPass(GlobalOptPass()); - MPM.addPass(GlobalDCEPass()); - // Run partial inlining pass to partially inline functions that have // large bodies. if (RunPartialInlining) @@ -1475,9 +1479,6 @@ if (RunPartialInlining) MPM.addPass(PartialInlinerPass()); - // Reduce the size of the IR as much as possible. - MPM.addPass(GlobalOptPass()); - if (PGOOpt && PGOOpt->PseudoProbeForProfiling && PGOOpt->Action == PGOOptions::SampleUse) MPM.addPass(PseudoProbeUpdatePass());