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 @@ -516,6 +516,17 @@ MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM))); } +// Helper to check the current compilation phase +static bool isLTOPreLink(ThinOrFullLTOPhase Phase) { + switch (Phase) { + case ThinOrFullLTOPhase::ThinLTOPreLink: + case ThinOrFullLTOPhase::FullLTOPreLink: + return true; + default: + return false; + } +} + // TODO: Investigate the cost/benefit of tail call elimination on debugging. FunctionPassManager PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level, @@ -562,7 +573,8 @@ LPM1.addPass(LoopInstSimplifyPass()); LPM1.addPass(LoopSimplifyCFGPass()); - LPM1.addPass(LoopRotatePass(/* Disable header duplication */ true)); + LPM1.addPass(LoopRotatePass(/* Disable header duplication */ true, + isLTOPreLink(Phase))); // TODO: Investigate promotion cap for O1. LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap)); LPM1.addPass(SimpleLoopUnswitchPass()); @@ -726,7 +738,8 @@ LPM1.addPass(LoopSimplifyCFGPass()); // Disable header duplication in loop rotation at -Oz. - LPM1.addPass(LoopRotatePass(Level != OptimizationLevel::Oz)); + LPM1.addPass( + LoopRotatePass(Level != OptimizationLevel::Oz, isLTOPreLink(Phase))); // TODO: Investigate promotion cap for O1. LPM1.addPass(LICMPass(PTO.LicmMssaOptCap, PTO.LicmMssaNoAccForPromotionCap)); LPM1.addPass(