[llvm] CodeGen: Pass instruction to LiveRangeEdit::useIsKill (PR #219466)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 28 06:15:13 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/219466

The helper only used the operand to recover its parent instruction. Pass the
containing instruction directly so it no longer depends on the
MachineOperand parent.

Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>

>From ec11e4cb8395f42c84956b9cd649572bac62bb81 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Fri, 28 Aug 2026 01:25:49 +0200
Subject: [PATCH] CodeGen: Pass instruction to LiveRangeEdit::useIsKill

The helper only used the operand to recover its parent instruction. Pass the
containing instruction directly so it no longer depends on the
MachineOperand parent.

Co-authored-by: Claude (Claude-Opus-4.8) <noreply at anthropic.com>
---
 llvm/include/llvm/CodeGen/LiveRangeEdit.h | 5 +++--
 llvm/lib/CodeGen/LiveRangeEdit.cpp        | 5 ++---
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/llvm/include/llvm/CodeGen/LiveRangeEdit.h b/llvm/include/llvm/CodeGen/LiveRangeEdit.h
index 7f884dcbd9e8b..00e1b6623efb4 100644
--- a/llvm/include/llvm/CodeGen/LiveRangeEdit.h
+++ b/llvm/include/llvm/CodeGen/LiveRangeEdit.h
@@ -96,9 +96,10 @@ class LLVM_ABI LiveRangeEdit : private MachineRegisterInfo::Delegate {
   /// registers are created.
   void MRI_NoteNewVirtualRegister(Register VReg) override;
 
-  /// Check if MachineOperand \p MO is a last use/kill either in the
+  /// Check if operand \p MO of \p MI is a last use/kill either in the
   /// main live range of \p LI or in one of the matching subregister ranges.
-  bool useIsKill(const LiveInterval &LI, const MachineOperand &MO) const;
+  bool useIsKill(const LiveInterval &LI, const MachineInstr &MI,
+                 const MachineOperand &MO) const;
 
   /// Create a new empty interval based on OldReg.
   LiveInterval &createEmptyIntervalFrom(Register OldReg, bool createSubRanges);
diff --git a/llvm/lib/CodeGen/LiveRangeEdit.cpp b/llvm/lib/CodeGen/LiveRangeEdit.cpp
index 09152cafab668..1d6b835f16468 100644
--- a/llvm/lib/CodeGen/LiveRangeEdit.cpp
+++ b/llvm/lib/CodeGen/LiveRangeEdit.cpp
@@ -192,9 +192,8 @@ bool LiveRangeEdit::foldAsLoad(LiveInterval *LI,
   return true;
 }
 
-bool LiveRangeEdit::useIsKill(const LiveInterval &LI,
+bool LiveRangeEdit::useIsKill(const LiveInterval &LI, const MachineInstr &MI,
                               const MachineOperand &MO) const {
-  const MachineInstr &MI = *MO.getParent();
   SlotIndex Idx = LIS.getInstructionIndex(MI).getRegSlot();
   if (LI.Query(Idx).isKill())
     return true;
@@ -283,7 +282,7 @@ void LiveRangeEdit::eliminateDeadDef(MachineInstr *MI, ToShrinkSet &ToShrink) {
     // Always shrink COPY uses that probably come from live range splitting.
     if ((MI->readsVirtualRegister(Reg) &&
          (MO.isDef() || TII.isCopyInstr(*MI))) ||
-        (MO.readsReg() && (MRI.hasOneNonDBGUse(Reg) || useIsKill(LI, MO))))
+        (MO.readsReg() && (MRI.hasOneNonDBGUse(Reg) || useIsKill(LI, *MI, MO))))
       ToShrink.insert(&LI);
     else if (MO.readsReg())
       HasLiveVRegUses = true;



More information about the llvm-commits mailing list