[llvm] [TwoAddressInstruction][NPM] Conditionally preserve SlotIndexes in NPM (PR #173536)
Teja Alaghari via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 17 04:35:24 PST 2026
https://github.com/TejaX-Alaghari updated https://github.com/llvm/llvm-project/pull/173536
>From 2ee527df3d681487a107acb65b32d2e0c314e76b Mon Sep 17 00:00:00 2001
From: Teja Alaghari <teja.alaghari at amd.com>
Date: Thu, 25 Dec 2025 14:37:42 +0530
Subject: [PATCH] Conditionally preserve SlotIndexes in NPM
---
.../lib/CodeGen/TwoAddressInstructionPass.cpp | 22 +++++++++++++------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
index dbad06623754c..9669b2bf018ff 100644
--- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
+++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp
@@ -190,7 +190,8 @@ class TwoAddressInstructionImpl {
public:
TwoAddressInstructionImpl(MachineFunction &MF, MachineFunctionPass *P);
TwoAddressInstructionImpl(MachineFunction &MF,
- MachineFunctionAnalysisManager &MFAM);
+ MachineFunctionAnalysisManager &MFAM,
+ LiveIntervals *LIS);
void setOptLevel(CodeGenOptLevel Level) { OptLevel = Level; }
bool run();
};
@@ -233,7 +234,9 @@ TwoAddressInstructionPass::run(MachineFunction &MF,
MachineFunctionAnalysisManager &MFAM) {
// Disable optimizations if requested. We cannot skip the whole pass as some
// fixups are necessary for correctness.
- TwoAddressInstructionImpl Impl(MF, MFAM);
+ LiveIntervals *LIS = MFAM.getCachedResult<LiveIntervalsAnalysis>(MF);
+
+ TwoAddressInstructionImpl Impl(MF, MFAM, LIS);
if (MF.getFunction().hasOptNone())
Impl.setOptLevel(CodeGenOptLevel::None);
@@ -242,11 +245,16 @@ TwoAddressInstructionPass::run(MachineFunction &MF,
if (!Changed)
return PreservedAnalyses::all();
auto PA = getMachineFunctionPassPreservedAnalyses();
- PA.preserve<LiveIntervalsAnalysis>();
+
+ // SlotIndexes are only maintained when LiveIntervals is available. Only
+ // preserve SlotIndexes if we had LiveIntervals available and updated them.
+ if (LIS)
+ PA.preserve<SlotIndexesAnalysis>();
+
PA.preserve<LiveVariablesAnalysis>();
+ PA.preserve<LiveIntervalsAnalysis>();
PA.preserve<MachineDominatorTreeAnalysis>();
PA.preserve<MachineLoopAnalysis>();
- PA.preserve<SlotIndexesAnalysis>();
PA.preserveSet<CFGAnalyses>();
return PA;
}
@@ -259,13 +267,13 @@ INITIALIZE_PASS(TwoAddressInstructionLegacyPass, DEBUG_TYPE,
"Two-Address instruction pass", false, false)
TwoAddressInstructionImpl::TwoAddressInstructionImpl(
- MachineFunction &Func, MachineFunctionAnalysisManager &MFAM)
+ MachineFunction &Func, MachineFunctionAnalysisManager &MFAM,
+ LiveIntervals *LIS)
: MF(&Func), TII(Func.getSubtarget().getInstrInfo()),
TRI(Func.getSubtarget().getRegisterInfo()),
InstrItins(Func.getSubtarget().getInstrItineraryData()),
MRI(&Func.getRegInfo()),
- LV(MFAM.getCachedResult<LiveVariablesAnalysis>(Func)),
- LIS(MFAM.getCachedResult<LiveIntervalsAnalysis>(Func)),
+ LV(MFAM.getCachedResult<LiveVariablesAnalysis>(Func)), LIS(LIS),
OptLevel(Func.getTarget().getOptLevel()) {}
TwoAddressInstructionImpl::TwoAddressInstructionImpl(MachineFunction &Func,
More information about the llvm-commits
mailing list