[llvm] [lto pipeline] Add flag to skip module optimization passes in the prelink lto pipeline (PR #90364)

Nathan Lanza via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 27 16:25:57 PDT 2024


https://github.com/lanza created https://github.com/llvm/llvm-project/pull/90364

As Nikita Popov calls out in
https://www.npopov.com/2023/04/07/LLVM-middle-end-pipeline.html#the-lto-pipelines,
the FullLTO prelink pipeline is pretty suboptimal. The fact that the
pipeline runs optimization passes before the pre-LTO pipeline means that
it degrades simplification passes during LTO.

Add an option to remove that here. In reality, we could probably just
enable this always, but there's often push back to churn to potentially
invasive changes. So just add a flag for now.


>From 874904094f3c098f77dcdae73cedeb00d20489b6 Mon Sep 17 00:00:00 2001
From: Nathan Lanza <nathanlanza at gmail.com>
Date: Sat, 27 Apr 2024 23:25:47 +0000
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?=
 =?UTF-8?q?l=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.5
---
 llvm/lib/Passes/PassBuilderPipelines.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Passes/PassBuilderPipelines.cpp b/llvm/lib/Passes/PassBuilderPipelines.cpp
index 90ba3b541553e2..683aecf49cc2ad 100644
--- a/llvm/lib/Passes/PassBuilderPipelines.cpp
+++ b/llvm/lib/Passes/PassBuilderPipelines.cpp
@@ -298,6 +298,11 @@ static cl::opt<bool> UseLoopVersioningLICM(
     "enable-loop-versioning-licm", cl::init(false), cl::Hidden,
     cl::desc("Enable the experimental Loop Versioning LICM pass"));
 
+static cl::opt<bool> DisableFullLTOPrelinkOptimization(
+    "disable-full-lto-prelink-optimization", cl::init(false), cl::Hidden,
+    cl::desc("Disable the module optimization pipeline for the FullLTO prelink "
+             "pipeline"));
+
 namespace llvm {
 extern cl::opt<bool> EnableMemProfContextDisambiguation;
 
@@ -1553,7 +1558,9 @@ PassBuilder::buildPerModuleDefaultPipeline(OptimizationLevel Level,
   MPM.addPass(buildModuleSimplificationPipeline(Level, LTOPhase));
 
   // Now add the optimization pipeline.
-  MPM.addPass(buildModuleOptimizationPipeline(Level, LTOPhase));
+  if (LTOPhase != ThinOrFullLTOPhase::FullLTOPreLink ||
+      !DisableFullLTOPrelinkOptimization)
+    MPM.addPass(buildModuleOptimizationPipeline(Level, LTOPhase));
 
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
       PGOOpt->Action == PGOOptions::SampleUse)



More information about the llvm-commits mailing list