[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 17:13:24 PDT 2026
https://github.com/justinfargnoli updated https://github.com/llvm/llvm-project/pull/192155
>From fb78adcde96166af530331504191770aff96a3bd Mon Sep 17 00:00:00 2001
From: Justin Fargnoli <jfargnoli at nvidia.com>
Date: Wed, 15 Apr 2026 00:13:15 +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 | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index f017419791a85..f486c56a92b1e 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -538,7 +538,8 @@ PassBuilder::buildO1FunctionSimplificationPipeline(OptimizationLevel Level,
PGOOpt->Action != PGOOptions::SampleUse)
LPM2.addPass(LoopFullUnrollPass(Level.getSpeedupLevel(),
/* OnlyWhenForced= */ !PTO.LoopUnrolling,
- PTO.ForgetAllSCEVInLoopUnroll));
+ PTO.ForgetAllSCEVInLoopUnroll,
+ /* PrepareForLTO= */ isLTOPreLink(Phase)));
invokeLoopOptimizerEndEPCallbacks(LPM2, Level);
@@ -722,7 +723,8 @@ PassBuilder::buildFunctionSimplificationPipeline(OptimizationLevel Level,
PGOOpt->Action != PGOOptions::SampleUse)
LPM2.addPass(LoopFullUnrollPass(Level.getSpeedupLevel(),
/* OnlyWhenForced= */ !PTO.LoopUnrolling,
- PTO.ForgetAllSCEVInLoopUnroll));
+ PTO.ForgetAllSCEVInLoopUnroll,
+ /* PrepareForLTO= */ isLTOPreLink(Phase)));
invokeLoopOptimizerEndEPCallbacks(LPM2, Level);
More information about the llvm-commits
mailing list