[PATCH] D133676: [X86] Simplify isReplaceable (NFC)

Kazu Hirata via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 11 11:43:12 PDT 2022


kazu created this revision.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
kazu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

isReplaceable checks to see if every use of the second LEA (called
"Last" in the function) is as the base address of a respective memory
access instruction.

The "for" loop being deleted in this patch potentially checks every
operand of the use instruction.

The patch simplifies the code by checking to see if every use is as
the base address of a respective memory access instruction, which we
can do with a quick pointer comparison.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D133676

Files:
  llvm/lib/Target/X86/X86OptimizeLEAs.cpp


Index: llvm/lib/Target/X86/X86OptimizeLEAs.cpp
===================================================================
--- llvm/lib/Target/X86/X86OptimizeLEAs.cpp
+++ llvm/lib/Target/X86/X86OptimizeLEAs.cpp
@@ -435,6 +435,10 @@
       MRI->getRegClass(Last.getOperand(0).getReg()))
     return false;
 
+  // We don't deal with physical registers.
+  if (Register::isPhysicalRegister(Last.getOperand(0).getReg()))
+    return false;
+
   // Get new address displacement.
   AddrDispShift = getAddrDispShift(Last, 1, First, 1);
 
@@ -455,18 +459,11 @@
 
     MemOpNo += X86II::getOperandBias(Desc);
 
-    // If the address base of the use instruction is not the LEA def register -
+    // If this use does not come from the address base of the use instruction,
     // the LEA is not replaceable.
-    if (!isIdenticalOp(MI.getOperand(MemOpNo + X86::AddrBaseReg), MO))
+    if (&MO != &MI.getOperand(MemOpNo + X86::AddrBaseReg))
       return false;
 
-    // If the LEA def register is used as any other operand of the use
-    // instruction - the LEA is not replaceable.
-    for (unsigned i = 0; i < MI.getNumOperands(); i++)
-      if (i != (unsigned)(MemOpNo + X86::AddrBaseReg) &&
-          isIdenticalOp(MI.getOperand(i), MO))
-        return false;
-
     // Check that the new address displacement will fit 4 bytes.
     if (MI.getOperand(MemOpNo + X86::AddrDisp).isImm() &&
         !isInt<32>(MI.getOperand(MemOpNo + X86::AddrDisp).getImm() +


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133676.459383.patch
Type: text/x-patch
Size: 1452 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220911/af5e35f7/attachment.bin>


More information about the llvm-commits mailing list