[llvm] [LTO] Enable PrepareForLTO for loop unrolling in pre-link pipelines (PR #192155)
Justin Fargnoli via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 14 15:54:06 PDT 2026
https://github.com/justinfargnoli created https://github.com/llvm/llvm-project/pull/192155
## Summary
- Set `PrepareForLTO=true` on the `LoopFullUnrollPass` in the O1 and O2 function simplification pipelines when running in a ThinLTO or FullLTO pre-link phase
- This defers unrolling of loops with calls that may be inlined during the LTO link phase, allowing the post-link unroller to make better decisions
- Depends on https://github.com/llvm/llvm-project/pull/192153
## Test plan
- Tests will be added after the base PR (#192153) lands
>From e16111226c85233026cfd6aeb5714c52278737a1 Mon Sep 17 00:00:00 2001
From: Justin Fargnoli <jfargnoli at nvidia.com>
Date: Tue, 14 Apr 2026 22:52:46 +0000
Subject: [PATCH] [LTO] Enable PrepareForLTO for loop unrolling in pre-link
pipelines
Set PrepareForLTO=true on the LoopFullUnrollPass in the O1 and O2
function simplification pipelines when running in a ThinLTO or
FullLTO pre-link phase. This defers unrolling of loops with calls
that may be inlined during the LTO link phase, allowing the post-link
unroller to make better decisions with fully resolved call targets.
---
llvm/lib/Passes/PassBuilderPipelines.cpp | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index f017419791a85..94c8fbe447c94 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -536,9 +536,12 @@ PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
// attention to it.
if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink || !PGOOpt ||
PGOOpt->Action != PGOOptions::SampleUse)
- LPM2.addPass(LoopFullUnrollPass(Level.getSpeedupLevel(),
- /* OnlyWhenForced= */ !PTO.LoopUnrolling,
- PTO.ForgetAllSCEVInLoopUnroll));
+ LPM2.addPass(LoopFullUnrollPass(
+ Level.getSpeedupLevel(),
+ /* OnlyWhenForced= */ !PTO.LoopUnrolling,
+ PTO.ForgetAllSCEVInLoopUnroll,
+ /* PrepareForLTO= */ Phase == ThinOrFullLTOPhase::ThinLTOPreLink ||
+ Phase == ThinOrFullLTOPhase::FullLTOPreLink));
invokeLoopOptimizerEndEPCallbacks(LPM2, Level);
@@ -720,9 +723,12 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
// attention to it.
if (Phase != ThinOrFullLTOPhase::ThinLTOPreLink || !PGOOpt ||
PGOOpt->Action != PGOOptions::SampleUse)
- LPM2.addPass(LoopFullUnrollPass(Level.getSpeedupLevel(),
- /* OnlyWhenForced= */ !PTO.LoopUnrolling,
- PTO.ForgetAllSCEVInLoopUnroll));
+ LPM2.addPass(LoopFullUnrollPass(
+ Level.getSpeedupLevel(),
+ /* OnlyWhenForced= */ !PTO.LoopUnrolling,
+ PTO.ForgetAllSCEVInLoopUnroll,
+ /* PrepareForLTO= */ Phase == ThinOrFullLTOPhase::ThinLTOPreLink ||
+ Phase == ThinOrFullLTOPhase::FullLTOPreLink));
invokeLoopOptimizerEndEPCallbacks(LPM2, Level);
More information about the llvm-commits
mailing list