[llvm] bdb4012 - [CodeGen] Remove parameter from LiveRangeEdit::canRematerializeAt [NFC]

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 14 09:12:23 PDT 2025


Author: Philip Reames
Date: 2025-03-14T09:12:07-07:00
New Revision: bdb4012fe3f9e30e2ea3e1d92524ad7725b2957e

URL: https://github.com/llvm/llvm-project/commit/bdb4012fe3f9e30e2ea3e1d92524ad7725b2957e
DIFF: https://github.com/llvm/llvm-project/commit/bdb4012fe3f9e30e2ea3e1d92524ad7725b2957e.diff

LOG: [CodeGen] Remove parameter from LiveRangeEdit::canRematerializeAt [NFC]

Only one caller cares about the true case of this parameter, so move
the check to that single caller.  Note that RegisterCoalescer seems
like it should care, but it already duplicates the check several
lines above.

Added: 
    

Modified: 
    llvm/include/llvm/CodeGen/LiveRangeEdit.h
    llvm/lib/CodeGen/InlineSpiller.cpp
    llvm/lib/CodeGen/LiveRangeEdit.cpp
    llvm/lib/CodeGen/RegisterCoalescer.cpp
    llvm/lib/CodeGen/SplitKit.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/CodeGen/LiveRangeEdit.h b/llvm/include/llvm/CodeGen/LiveRangeEdit.h
index 3a4a76d99c5c2..3d5df194c71c9 100644
--- a/llvm/include/llvm/CodeGen/LiveRangeEdit.h
+++ b/llvm/include/llvm/CodeGen/LiveRangeEdit.h
@@ -200,9 +200,7 @@ class LiveRangeEdit : private MachineRegisterInfo::Delegate {
 
   /// canRematerializeAt - Determine if ParentVNI can be rematerialized at
   /// UseIdx. It is assumed that parent_.getVNINfoAt(UseIdx) == ParentVNI.
-  /// When cheapAsAMove is set, only cheap remats are allowed.
-  bool canRematerializeAt(Remat &RM, VNInfo *OrigVNI, SlotIndex UseIdx,
-                          bool cheapAsAMove);
+  bool canRematerializeAt(Remat &RM, VNInfo *OrigVNI, SlotIndex UseIdx);
 
   /// rematerializeAt - Rematerialize RM.ParentVNI into DestReg by inserting an
   /// instruction into MBB before MI. The new instruction is mapped, but

diff  --git a/llvm/lib/CodeGen/InlineSpiller.cpp b/llvm/lib/CodeGen/InlineSpiller.cpp
index 4a49665ada3c2..ec71d504ebab4 100644
--- a/llvm/lib/CodeGen/InlineSpiller.cpp
+++ b/llvm/lib/CodeGen/InlineSpiller.cpp
@@ -644,7 +644,7 @@ bool InlineSpiller::reMaterializeFor(LiveInterval &VirtReg, MachineInstr &MI) {
   LiveRangeEdit::Remat RM(ParentVNI);
   RM.OrigMI = LIS.getInstructionFromIndex(OrigVNI->def);
 
-  if (!Edit->canRematerializeAt(RM, OrigVNI, UseIdx, false)) {
+  if (!Edit->canRematerializeAt(RM, OrigVNI, UseIdx)) {
     markValueUsed(&VirtReg, ParentVNI);
     LLVM_DEBUG(dbgs() << "\tcannot remat for " << UseIdx << '\t' << MI);
     return false;

diff  --git a/llvm/lib/CodeGen/LiveRangeEdit.cpp b/llvm/lib/CodeGen/LiveRangeEdit.cpp
index 0b637bf8a9c56..a3858efbdc5e1 100644
--- a/llvm/lib/CodeGen/LiveRangeEdit.cpp
+++ b/llvm/lib/CodeGen/LiveRangeEdit.cpp
@@ -156,7 +156,7 @@ bool LiveRangeEdit::allUsesAvailableAt(const MachineInstr *OrigMI,
 }
 
 bool LiveRangeEdit::canRematerializeAt(Remat &RM, VNInfo *OrigVNI,
-                                       SlotIndex UseIdx, bool cheapAsAMove) {
+                                       SlotIndex UseIdx) {
   assert(ScannedRemattable && "Call anyRematerializable first");
 
   // Use scanRemattable info.
@@ -168,10 +168,6 @@ bool LiveRangeEdit::canRematerializeAt(Remat &RM, VNInfo *OrigVNI,
   assert(RM.OrigMI && "No defining instruction for remattable value");
   DefIdx = LIS.getInstructionIndex(*RM.OrigMI);
 
-  // If only cheap remats were requested, bail out early.
-  if (cheapAsAMove && !TII.isAsCheapAsAMove(*RM.OrigMI))
-    return false;
-
   // Verify that all used registers are available with the same values.
   if (!allUsesAvailableAt(RM.OrigMI, DefIdx, UseIdx))
     return false;

diff  --git a/llvm/lib/CodeGen/RegisterCoalescer.cpp b/llvm/lib/CodeGen/RegisterCoalescer.cpp
index 74606e66d4e4b..dbd354f2ca2c4 100644
--- a/llvm/lib/CodeGen/RegisterCoalescer.cpp
+++ b/llvm/lib/CodeGen/RegisterCoalescer.cpp
@@ -1398,7 +1398,7 @@ bool RegisterCoalescer::reMaterializeTrivialDef(const CoalescerPair &CP,
 
   LiveRangeEdit::Remat RM(ValNo);
   RM.OrigMI = DefMI;
-  if (!Edit.canRematerializeAt(RM, ValNo, CopyIdx, true))
+  if (!Edit.canRematerializeAt(RM, ValNo, CopyIdx))
     return false;
 
   DebugLoc DL = CopyMI->getDebugLoc();

diff  --git a/llvm/lib/CodeGen/SplitKit.cpp b/llvm/lib/CodeGen/SplitKit.cpp
index bdccbffe90f9f..e55dfaebd028e 100644
--- a/llvm/lib/CodeGen/SplitKit.cpp
+++ b/llvm/lib/CodeGen/SplitKit.cpp
@@ -591,9 +591,6 @@ SlotIndex SplitEditor::buildCopy(Register FromReg, Register ToReg,
 bool SplitEditor::rematWillIncreaseRestriction(const MachineInstr *DefMI,
                                                MachineBasicBlock &MBB,
                                                SlotIndex UseIdx) const {
-  if (!DefMI)
-    return false;
-
   const MachineInstr *UseMI = LIS.getInstructionFromIndex(UseIdx);
   if (!UseMI)
     return false;
@@ -640,7 +637,8 @@ VNInfo *SplitEditor::defFromParent(unsigned RegIdx, const VNInfo *ParentVNI,
   if (OrigVNI) {
     LiveRangeEdit::Remat RM(ParentVNI);
     RM.OrigMI = LIS.getInstructionFromIndex(OrigVNI->def);
-    if (Edit->canRematerializeAt(RM, OrigVNI, UseIdx, true)) {
+    if (RM.OrigMI && TII.isAsCheapAsAMove(*RM.OrigMI) &&
+        Edit->canRematerializeAt(RM, OrigVNI, UseIdx)) {
       if (!rematWillIncreaseRestriction(RM.OrigMI, MBB, UseIdx)) {
         SlotIndex Def = Edit->rematerializeAt(MBB, I, Reg, RM, TRI, Late);
         ++NumRemats;


        


More information about the llvm-commits mailing list