[llvm] [MachineLateInstrsCleanup] Reuse redundant spill-slot reloads (PR #220180)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 8 03:53:37 PDT 2026


================
@@ -168,15 +175,98 @@ void MachineLateInstrsCleanup::removeRedundantDef(MachineInstr *MI) {
   ++NumRemoved;
 }
 
+// Return true if MI accesses a register-allocation spill slot through a single
+// memory operand, and if so also the frame index of that slot in FI.
+static bool isSingleSpillSlotAccess(const MachineInstr &MI,
+                                    const MachineFrameInfo &MFI, int &FI) {
+  if (!MI.hasOneMemOperand())
+    return false;
+  const MachineMemOperand *MMO = *MI.memoperands_begin();
+  const auto *PSV =
+      dyn_cast_or_null<FixedStackPseudoSourceValue>(MMO->getPseudoValue());
+  if (!PSV)
+    return false;
+  FI = PSV->getFrameIndex();
+  return MFI.isSpillSlotObjectIndex(FI);
+}
+
+// Return true unless MI provably cannot write the spill slot FI. The address of
+// a spill slot never escapes, so only an instruction that names the slot can
+// write it. An instruction whose memory effects are not fully described must
+// however be assumed to name it: a call may be a statepoint whose collector
+// rewrites the frame, and a frame-setup push stores with no memory operand at
+// all.
+static bool mayWriteSpillSlot(const MachineInstr &MI, int FI,
----------------
arsenm wrote:

Why not use TII::isStoreToStackSlot/isLoadFromStackSlot

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


More information about the llvm-commits mailing list