[llvm-branch-commits] [NewPM] Match LegacyPM behavior for opt-bisect in passes (PR #225439)

via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Sep 22 08:54:32 PDT 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-backend-aarch64

Author: Aiden Grossman (boomanaiden154)

<details>
<summary>Changes</summary>

This patch updates passes that change their behavior around opt-bisect
(e.g., performing less optimizations) so that this behavior is
replicated in the NewPM.

Assisted by LLM.


---
Full diff: https://github.com/llvm/llvm-project/pull/225439.diff


14 Files Affected:

- (modified) llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp (+2-1) 
- (modified) llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp (+6-5) 
- (modified) llvm/lib/CodeGen/StackColoring.cpp (+3-1) 
- (modified) llvm/lib/CodeGen/TwoAddressInstructionPass.cpp (+2-1) 
- (modified) llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp (+2-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp (+2-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUPreLegalizerCombiner.cpp (+2-1) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPURegBankCombiner.cpp (+2-2) 
- (modified) llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp (+3-1) 
- (modified) llvm/lib/Target/WebAssembly/GISel/WebAssemblyPostLegalizerCombiner.cpp (+5-1) 
- (modified) llvm/lib/Target/WebAssembly/GISel/WebAssemblyPreLegalizerCombiner.cpp (+4-1) 
- (modified) llvm/lib/Target/X86/GISel/X86PreLegalizerCombiner.cpp (+2-1) 
- (modified) llvm/test/CodeGen/X86/replace_unsupported_masked_mem_intrin.ll (+1) 
- (modified) llvm/test/Other/X86/opt-bisect-isel.ll (+1) 


``````````diff
diff --git a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
index d9e88f22ac2ca3..dcf3e5beb8b9c7 100644
--- a/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
+++ b/llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp
@@ -5300,7 +5300,8 @@ PreservedAnalyses IRTranslatorPass::run(MachineFunction &MF,
   const TargetSubtargetInfo &Subtarget = MF.getSubtarget();
   Function &F = MF.getFunction();
 
-  bool ShouldSkipOpts = MF.getFunction().hasOptNone();
+  bool ShouldSkipOpts = MF.getFunction().hasOptNone() ||
+                        shouldSkipOptimizationForOptBisect(MF.getFunction());
   auto &FAM = MFAM.getResult<FunctionAnalysisManagerMachineFunctionProxy>(MF)
                   .getManager();
   auto &MAMProxy =
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
index 59a1f885d4eea5..97061800ddba39 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
@@ -451,13 +451,14 @@ SelectionDAGISelPass::run(MachineFunction &MF,
   // we change the optimisation level.
   MF.setUseDebugInstrRef(MF.shouldUseDebugInstrRef());
 
-  // Reset OptLevel to None for optnone functions.
+  // Reset OptLevel to None for optnone functions or when opt-bisect skips.
   // TODO: Add a function analysis to handle this.
   Selector->MF = &MF;
-  // Reset OptLevel to None for optnone functions.
-  CodeGenOptLevel NewOptLevel = MF.getFunction().hasOptNone()
-                                    ? CodeGenOptLevel::None
-                                    : Selector->OptLevel;
+  CodeGenOptLevel NewOptLevel =
+      (MF.getFunction().hasOptNone() ||
+       shouldSkipOptimizationForOptBisect(MF.getFunction()))
+          ? CodeGenOptLevel::None
+          : Selector->OptLevel;
 
   OptLevelChanger OLC(*Selector, NewOptLevel);
   Selector->initializeAnalysisResults(MFAM);
diff --git a/llvm/lib/CodeGen/StackColoring.cpp b/llvm/lib/CodeGen/StackColoring.cpp
index 81e4e1bfdefbfc..f6fdfcaec742d9 100644
--- a/llvm/lib/CodeGen/StackColoring.cpp
+++ b/llvm/lib/CodeGen/StackColoring.cpp
@@ -1195,7 +1195,9 @@ bool StackColoringLegacy::runOnMachineFunction(MachineFunction &MF) {
 PreservedAnalyses StackColoringPass::run(MachineFunction &MF,
                                          MachineFunctionAnalysisManager &MFAM) {
   StackColoring SC(&MFAM.getResult<SlotIndexesAnalysis>(MF));
-  if (SC.run(MF)) {
+  bool OnlyRemoveMarkers = MF.getFunction().hasOptNone() ||
+                           shouldSkipOptimizationForOptBisect(MF.getFunction());
+  if (SC.run(MF, OnlyRemoveMarkers)) {
     auto PA = getMachineFunctionPassPreservedAnalyses();
     PA.preserve<MachineRegisterClassAnalysis>();
     return PA;
diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
index ed24e4aba91197..fd18e7d6259af0 100644
--- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
+++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
@@ -236,7 +236,8 @@ TwoAddressInstructionPass::run(MachineFunction &MF,
   LiveIntervals *LIS = MFAM.getCachedResult<LiveIntervalsAnalysis>(MF);
 
   TwoAddressInstructionImpl Impl(MF, MFAM, LIS);
-  if (MF.getFunction().hasOptNone())
+  if (MF.getFunction().hasOptNone() ||
+      shouldSkipOptimizationForOptBisect(MF.getFunction()))
     Impl.setOptLevel(CodeGenOptLevel::None);
 
   MFPropsModifier _(*this, MF);
diff --git a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
index 6ba25ac4ffa0a7..3f450693b00af5 100644
--- a/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AArch64/GISel/AArch64PostLegalizerCombiner.cpp
@@ -986,7 +986,8 @@ AArch64PostLegalizerCombinerPass::run(MachineFunction &MF,
     return PreservedAnalyses::all();
 
   const bool IsOptNone = TM->isGlobalISelOptNone();
-  bool EnableOpt = !IsOptNone;
+  bool EnableOpt =
+      !IsOptNone && !shouldSkipOptimizationForOptBisect(MF.getFunction());
 
   GISelValueTracking *VT = &MFAM.getResult<GISelValueTrackingAnalysis>(MF);
   MachineDominatorTree *MDT =
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
index 4373cfee6587ff..558258868642bf 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPostLegalizerCombiner.cpp
@@ -504,7 +504,8 @@ AMDGPUPostLegalizerCombinerPass::run(MachineFunction &MF,
   if (!RuleConfig.parseCommandLineOption())
     report_fatal_error("Invalid rule identifier");
 
-  bool IsOptNone = MF.getTarget().getOptLevel() == CodeGenOptLevel::None;
+  bool IsOptNone = MF.getTarget().getOptLevel() == CodeGenOptLevel::None ||
+                   shouldSkipOptimizationForOptBisect(MF.getFunction());
 
   GISelValueTracking &VT = MFAM.getResult<GISelValueTrackingAnalysis>(MF);
   GISelCSEInfo *CSEInfo = MFAM.getResult<GISelCSEAnalysis>(MF).get();
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPreLegalizerCombiner.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPreLegalizerCombiner.cpp
index e5ff2397141418..575c083ba51b67 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPreLegalizerCombiner.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPreLegalizerCombiner.cpp
@@ -312,7 +312,8 @@ llvm::createAMDGPUPreLegalizeCombinerLegacyPass(bool IsOptLevelNone) {
 PreservedAnalyses
 AMDGPUPreLegalizerCombinerPass::run(MachineFunction &MF,
                                     MachineFunctionAnalysisManager &MFAM) {
-  bool IsOptLevelNone = MF.getTarget().getOptLevel() == CodeGenOptLevel::None;
+  bool IsOptLevelNone = MF.getTarget().getOptLevel() == CodeGenOptLevel::None ||
+                        shouldSkipOptimizationForOptBisect(MF.getFunction());
 
   if (!runCombiner(
           MF, [&]() { return MFAM.getResult<GISelCSEAnalysis>(MF).get(); },
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURegBankCombiner.cpp b/llvm/lib/Target/AMDGPU/AMDGPURegBankCombiner.cpp
index 790c8879502458..ed1531fccb5ed4 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURegBankCombiner.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURegBankCombiner.cpp
@@ -729,8 +729,8 @@ PreservedAnalyses
 AMDGPURegBankCombinerPass::run(MachineFunction &MF,
                                MachineFunctionAnalysisManager &MFAM) {
   const Function &F = MF.getFunction();
-  bool EnableOpt =
-      MF.getTarget().getOptLevel() != CodeGenOptLevel::None && !F.hasOptNone();
+  bool EnableOpt = MF.getTarget().getOptLevel() != CodeGenOptLevel::None &&
+                   !F.hasOptNone() && !shouldSkipOptimizationForOptBisect(F);
 
   if (!runCombiner(
           MF, [&]() { return &MFAM.getResult<GISelValueTrackingAnalysis>(MF); },
diff --git a/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp b/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp
index 1e1fbe75f53c2a..b47962ba8c1e72 100644
--- a/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVPreLegalizerCombiner.cpp
@@ -186,7 +186,9 @@ PreservedAnalyses
 SPIRVPreLegalizerCombinerPass::run(MachineFunction &MF,
                                    MachineFunctionAnalysisManager &MFAM) {
   bool Changed = runPreLegalizerCombiner(
-      MF, MF.getFunction().hasOptNone(),
+      MF,
+      MF.getFunction().hasOptNone() ||
+          shouldSkipOptimizationForOptBisect(MF.getFunction()),
       [&]() { return &MFAM.getResult<GISelValueTrackingAnalysis>(MF); },
       [&]() { return &MFAM.getResult<MachineDominatorTreeAnalysis>(MF); });
   if (!Changed)
diff --git a/llvm/lib/Target/WebAssembly/GISel/WebAssemblyPostLegalizerCombiner.cpp b/llvm/lib/Target/WebAssembly/GISel/WebAssemblyPostLegalizerCombiner.cpp
index 6c04533d5abca9..2504d3f56490fd 100644
--- a/llvm/lib/Target/WebAssembly/GISel/WebAssemblyPostLegalizerCombiner.cpp
+++ b/llvm/lib/Target/WebAssembly/GISel/WebAssemblyPostLegalizerCombiner.cpp
@@ -191,7 +191,11 @@ bool WebAssemblyPostLegalizerCombinerLegacy::runOnMachineFunction(
 PreservedAnalyses WebAssemblyPostLegalizerCombinerPass::run(
     MachineFunction &MF, MachineFunctionAnalysisManager &MFAM) {
   bool Changed = runCombinerOnMachineFunction(
-      MF, [&]() { return MF.getFunction().hasOptNone(); },
+      MF,
+      [&]() {
+        return MF.getFunction().hasOptNone() ||
+               shouldSkipOptimizationForOptBisect(MF.getFunction());
+      },
       [&]() { return &MFAM.getResult<GISelValueTrackingAnalysis>(MF); },
       [&]() { return &MFAM.getResult<MachineDominatorTreeAnalysis>(MF); },
       [&]() { return MFAM.getResult<GISelCSEAnalysis>(MF).get(); });
diff --git a/llvm/lib/Target/WebAssembly/GISel/WebAssemblyPreLegalizerCombiner.cpp b/llvm/lib/Target/WebAssembly/GISel/WebAssemblyPreLegalizerCombiner.cpp
index c1261263c92c78..0221575e571e21 100644
--- a/llvm/lib/Target/WebAssembly/GISel/WebAssemblyPreLegalizerCombiner.cpp
+++ b/llvm/lib/Target/WebAssembly/GISel/WebAssemblyPreLegalizerCombiner.cpp
@@ -196,7 +196,10 @@ WebAssemblyPreLegalizerCombinerPass::run(MachineFunction &MF,
                                          MachineFunctionAnalysisManager &MFAM) {
   bool Changed = runCombinerOnMachineFunction(
       MF, [&]() { return MFAM.getResult<GISelCSEAnalysis>(MF).get(); },
-      [&]() { return MF.getFunction().hasOptNone(); },
+      [&]() {
+        return MF.getFunction().hasOptNone() ||
+               shouldSkipOptimizationForOptBisect(MF.getFunction());
+      },
       [&]() { return &MFAM.getResult<GISelValueTrackingAnalysis>(MF); },
       [&]() { return &MFAM.getResult<MachineDominatorTreeAnalysis>(MF); });
   return Changed ? getMachineFunctionPassPreservedAnalyses()
diff --git a/llvm/lib/Target/X86/GISel/X86PreLegalizerCombiner.cpp b/llvm/lib/Target/X86/GISel/X86PreLegalizerCombiner.cpp
index abd8707bc77339..e828afb96bfe37 100644
--- a/llvm/lib/Target/X86/GISel/X86PreLegalizerCombiner.cpp
+++ b/llvm/lib/Target/X86/GISel/X86PreLegalizerCombiner.cpp
@@ -184,7 +184,8 @@ X86PreLegalizerCombinerPass::run(MachineFunction &MF,
 
   auto &CSEInfo = MFAM.getResult<GISelCSEAnalysis>(MF);
   const Function &F = MF.getFunction();
-  bool EnableOpt = MF.getTarget().getOptLevel() != CodeGenOptLevel::None;
+  bool EnableOpt = MF.getTarget().getOptLevel() != CodeGenOptLevel::None &&
+                   !shouldSkipOptimizationForOptBisect(F);
   GISelValueTracking &VT = MFAM.getResult<GISelValueTrackingAnalysis>(MF);
   MachineDominatorTree &MDT = MFAM.getResult<MachineDominatorTreeAnalysis>(MF);
   CombinerInfo CInfo = createCombinerInfo(EnableOpt, F);
diff --git a/llvm/test/CodeGen/X86/replace_unsupported_masked_mem_intrin.ll b/llvm/test/CodeGen/X86/replace_unsupported_masked_mem_intrin.ll
index 2299a931c80fb9..fe57508a091f9b 100644
--- a/llvm/test/CodeGen/X86/replace_unsupported_masked_mem_intrin.ll
+++ b/llvm/test/CodeGen/X86/replace_unsupported_masked_mem_intrin.ll
@@ -2,6 +2,7 @@
 ; pr33001 - Check that llc doesn't crash when running with O0 option.
 
 ; RUN: llc -O2 -opt-bisect-limit=0 -mtriple=x86_64-unknown-linux-gnu -mattr=+sse,+sse2 < %s -o /dev/null
+; RUN: llc -O2 -opt-bisect-limit=0 -enable-new-pm -mtriple=x86_64-unknown-linux-gnu -mattr=+sse,+sse2 < %s -o /dev/null
 ; Check that llc doesn't crash due to ScalarizeMaskedMemIntring not being run
 ; because of opt-bisect-limit that in turn causes crash in instruction selection
 ; for unsupported gather/scatter.
diff --git a/llvm/test/Other/X86/opt-bisect-isel.ll b/llvm/test/Other/X86/opt-bisect-isel.ll
index 78a5f202646cb7..2e4a54c75cb36d 100644
--- a/llvm/test/Other/X86/opt-bisect-isel.ll
+++ b/llvm/test/Other/X86/opt-bisect-isel.ll
@@ -4,6 +4,7 @@
 ; if it is not run in -O0 mode.
 
 ; RUN: llc -O3 -opt-bisect-limit=0 -o - %s | FileCheck %s
+; RUN: llc -O3 -opt-bisect-limit=0 -enable-new-pm -o - %s | FileCheck %s
 
 target triple = "x86_64-unknown-linux-gnu"
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/225439


More information about the llvm-branch-commits mailing list