[llvm] [MIPS] Move dead register hack to MIPSSEISelDAGtoDAG (PR #204980)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 21 08:30:59 PDT 2026
https://github.com/AZero13 updated https://github.com/llvm/llvm-project/pull/204980
>From 8c62bfc9d0eafb8840f229a05a95230d2cd14c60 Mon Sep 17 00:00:00 2001
From: AZero13 <gfunni234 at gmail.com>
Date: Sun, 21 Jun 2026 11:21:11 -0400
Subject: [PATCH] [MIPS] Move dead register hack to MIPSSEISelDAGtoDAG
The old Implicit | Undef hack explicitly told the compiler to ignore the use dependency, which disabled proper liveness tracking and could have caused the definition to be incorrectly deleted by later passes. By using genuine Implicit uses and manually stripping the dead flags after ISel, we allow LiveVariables and LiveIntervals to construct a correct, unbroken live range.
---
llvm/lib/CodeGen/LiveVariables.cpp | 4 ---
llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp | 34 +++++++++++++++++++--
2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/CodeGen/LiveVariables.cpp b/llvm/lib/CodeGen/LiveVariables.cpp
index 246d538332af7..407b22abd353e 100644
--- a/llvm/lib/CodeGen/LiveVariables.cpp
+++ b/llvm/lib/CodeGen/LiveVariables.cpp
@@ -506,10 +506,6 @@ void LiveVariables::runOnInstr(MachineInstr &MI,
UseRegs.push_back(MOReg);
} else {
assert(MO.isDef());
- // FIXME: We should not remove any dead flags. However the MIPS RDDSP
- // instruction needs it at the moment: http://llvm.org/PR27116.
- if (MOReg.isPhysical() && !MRI->isReserved(MOReg))
- MO.setIsDead(false);
DefRegs.push_back(MOReg);
}
}
diff --git a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
index 8c60824a42a26..b295f698ffe9d 100644
--- a/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
+++ b/llvm/lib/Target/Mips/MipsSEISelDAGToDAG.cpp
@@ -48,8 +48,7 @@ void MipsSEDAGToDAGISel::addDSPCtrlRegOperands(bool IsDef, MachineInstr &MI,
MachineFunction &MF) {
MachineInstrBuilder MIB(MF, &MI);
unsigned Mask = MI.getOperand(1).getImm();
- RegState Flag =
- IsDef ? RegState::ImplicitDefine : RegState::Implicit | RegState::Undef;
+ RegState Flag = IsDef ? RegState::ImplicitDefine : RegState::Implicit;
if (Mask & 1)
MIB.addReg(Mips::DSPPos, Flag);
@@ -147,6 +146,25 @@ void MipsSEDAGToDAGISel::emitMCountABI(MachineInstr &MI, MachineBasicBlock &MBB,
}
}
+static bool isDSPControlReg(Register Reg) {
+ switch (Reg) {
+ case Mips::DSPPos:
+ case Mips::DSPSCount:
+ case Mips::DSPCarry:
+ case Mips::DSPOutFlag:
+ case Mips::DSPCCond:
+ case Mips::DSPEFI:
+ case Mips::DSPOutFlag16_19:
+ case Mips::DSPOutFlag20:
+ case Mips::DSPOutFlag21:
+ case Mips::DSPOutFlag22:
+ case Mips::DSPOutFlag23:
+ return true;
+ default:
+ return false;
+ }
+}
+
void MipsSEDAGToDAGISel::processFunctionAfterISel(MachineFunction &MF) {
MF.getInfo<MipsFunctionInfo>()->initGlobalBaseReg(MF);
@@ -195,6 +213,18 @@ void MipsSEDAGToDAGISel::processFunctionAfterISel(MachineFunction &MF) {
default:
replaceUsesWithZeroReg(MRI, MI);
}
+
+ // MIPS DSP intrinsics don't explicitly model their dependencies
+ // in the SelectionDAG, which causes InstrEmitter to mistakenly mark them
+ // as dead. We clear the dead flags here so that LiveVariables will
+ // compute liveness correctly, avoiding MachineDeadInstrElim from deleting
+ // the definitions.
+ for (MachineOperand &MO : MI.operands()) {
+ if (MO.isReg() && MO.isDef() && MO.getReg().isPhysical() &&
+ isDSPControlReg(MO.getReg())) {
+ MO.setIsDead(false);
+ }
+ }
}
}
}
More information about the llvm-commits
mailing list