[llvm] [MachineCopyPropagation][NFC] Refactor EliminateSpillageCopies (PR #192609)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 17 12:29:58 PDT 2026
================
@@ -421,20 +421,35 @@ class CopyTracker {
if (!TRI.isSubRegisterEq(Dst, Reg))
return nullptr;
- for (const MachineInstr &MI :
- make_range(static_cast<const MachineInstr *>(DefCopy)->getIterator(),
- Current.getIterator()))
- for (const MachineOperand &MO : MI.operands())
- if (MO.isRegMask())
- if (MO.clobbersPhysReg(Dst)) {
- LLVM_DEBUG(dbgs() << "MCP: Removed tracking of "
- << printReg(Dst, &TRI) << "\n");
- return nullptr;
- }
-
return DefCopy;
}
+ void clobberNonPreservedRegs(const BitVector &PreservedRegUnits,
+ const TargetRegisterInfo &TRI,
+ const TargetInstrInfo &TII, bool UseCopyInstr) {
+ SmallVector<MCRegUnit, 8> UnitsToClobber;
+ for (auto &[Unit, _] : Copies)
+ if (!PreservedRegUnits.test(static_cast<unsigned>(Unit)))
+ UnitsToClobber.push_back(Unit);
+
+ for (MCRegUnit Unit : UnitsToClobber) {
+ // If we clobber the RegUnit, it will mark all the DefReg Units
+ // as unavailable, which leads to issues if the Destination Reg Unit is
+ // preserved, and used later. As such, only mark them as unavailable if
+ // they are not preserved.
+ auto RegUnitInfo = Copies.find(Unit);
+ if (RegUnitInfo == Copies.end())
+ continue;
+
+ for (MCRegister DstReg : RegUnitInfo->second.DefRegs)
----------------
arsenm wrote:
Braces
https://github.com/llvm/llvm-project/pull/192609
More information about the llvm-commits
mailing list