[llvm] 6c11b7e - [CodeGen] NFC: Change order of checks in MachineInstr->isDead() (#124207)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 24 07:23:28 PST 2025


Author: Jeffrey Byrnes
Date: 2025-01-24T07:23:22-08:00
New Revision: 6c11b7e689c89ff46e4472810dd555434eab1010

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

LOG: [CodeGen] NFC: Change order of checks in MachineInstr->isDead() (#124207)

[[Change-Id:
Ic349022bb99ef91f5396e462ade0366bc772ae02](https://github.com/llvm/llvm-project/pull/123531)](https://github.com/llvm/llvm-project/pull/123531)
moved isDead() from DeadMachineInstrElim to MachineInstr . In the
process of moving, I reordered the checks to improve chances of early
exit, but this has caused a slight increase in compile time.

This PR reverts back to the original order of checks.

Added: 
    

Modified: 
    llvm/lib/CodeGen/MachineInstr.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp
index 0f7f525fa479e8..a9f756b6843603 100644
--- a/llvm/lib/CodeGen/MachineInstr.cpp
+++ b/llvm/lib/CodeGen/MachineInstr.cpp
@@ -1353,18 +1353,6 @@ bool MachineInstr::wouldBeTriviallyDead() const {
 
 bool MachineInstr::isDead(const MachineRegisterInfo &MRI,
                           LiveRegUnits *LivePhysRegs) const {
-  // Technically speaking inline asm without side effects and no defs can still
-  // be deleted. But there is so much bad inline asm code out there, we should
-  // let them be.
-  if (isInlineAsm())
-    return false;
-
-  // If we suspect this instruction may have some side-effects, then we say
-  // this instruction cannot be dead.
-  // FIXME: See issue #105950 for why LIFETIME markers are considered dead here.
-  if (!isLifetimeMarker() && !wouldBeTriviallyDead())
-    return false;
-
   // Instructions without side-effects are dead iff they only define dead regs.
   // This function is hot and this loop returns early in the common case,
   // so only perform additional checks before this if absolutely necessary.
@@ -1385,7 +1373,19 @@ bool MachineInstr::isDead(const MachineRegisterInfo &MRI,
     }
   }
 
-  return true;
+  // Technically speaking inline asm without side effects and no defs can still
+  // be deleted. But there is so much bad inline asm code out there, we should
+  // let them be.
+  if (isInlineAsm())
+    return false;
+
+  // FIXME: See issue #105950 for why LIFETIME markers are considered dead here.
+  if (isLifetimeMarker())
+    return true;
+
+  // If there are no defs with uses, then we call the instruction dead so long
+  // as we do not suspect it may have sideeffects.
+  return wouldBeTriviallyDead();
 }
 
 static bool MemOperandsHaveAlias(const MachineFrameInfo &MFI,


        


More information about the llvm-commits mailing list