[PATCH] D141153: [LocalStackSlotAllocation] Minor simplifications. NFC

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 9 09:50:33 PST 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1153313c334a: [LocalStackSlotAllocation] Minor simplifications. NFC (authored by craig.topper).

Changed prior to commit:
  https://reviews.llvm.org/D141153?vs=486949&id=487487#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D141153/new/

https://reviews.llvm.org/D141153

Files:
  llvm/lib/CodeGen/LocalStackSlotAllocation.cpp


Index: llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
===================================================================
--- llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
+++ llvm/lib/CodeGen/LocalStackSlotAllocation.cpp
@@ -288,7 +288,6 @@
   // stack frame. If it wants one, re-use a suitable one we've previously
   // allocated, or if there isn't one that fits the bill, allocate a new one
   // and ask the target to create a defining instruction for it.
-  bool UsedBaseReg = false;
 
   MachineFrameInfo &MFI = Fn.getFrameInfo();
   const TargetRegisterInfo *TRI = Fn.getSubtarget().getRegisterInfo();
@@ -386,7 +385,7 @@
     // instruction itself will be taken into account by the target,
     // so we don't have to adjust for it here when reusing a base
     // register.
-    if (UsedBaseReg &&
+    if (BaseReg.isValid() &&
         lookupCandidateBaseReg(BaseReg, BaseOffset, FrameSizeAdjust,
                                LocalOffset, MI, TRI)) {
       LLVM_DEBUG(dbgs() << "  Reusing base register " << BaseReg << "\n");
@@ -396,8 +395,7 @@
       // No previously defined register was in range, so create a new one.
       int64_t InstrOffset = TRI->getFrameIndexInstrOffset(&MI, idx);
 
-      int64_t PrevBaseOffset = BaseOffset;
-      BaseOffset = FrameSizeAdjust + LocalOffset + InstrOffset;
+      int64_t CandBaseOffset = FrameSizeAdjust + LocalOffset + InstrOffset;
 
       // We'd like to avoid creating single-use virtual base registers.
       // Because the FrameRefs are in sorted order, and we've already
@@ -406,12 +404,13 @@
       // then don't bother creating it.
       if (ref + 1 >= e ||
           !lookupCandidateBaseReg(
-              BaseReg, BaseOffset, FrameSizeAdjust,
+              BaseReg, CandBaseOffset, FrameSizeAdjust,
               FrameReferenceInsns[ref + 1].getLocalOffset(),
-              *FrameReferenceInsns[ref + 1].getMachineInstr(), TRI)) {
-        BaseOffset = PrevBaseOffset;
+              *FrameReferenceInsns[ref + 1].getMachineInstr(), TRI))
         continue;
-      }
+
+      // Save the base offset.
+      BaseOffset = CandBaseOffset;
 
       // Tell the target to insert the instruction to initialize
       // the base register.
@@ -428,7 +427,6 @@
       Offset = -InstrOffset;
 
       ++NumBaseRegisters;
-      UsedBaseReg = true;
     }
     assert(BaseReg && "Unable to allocate virtual base register!");
 
@@ -440,5 +438,5 @@
     ++NumReplacements;
   }
 
-  return UsedBaseReg;
+  return BaseReg.isValid();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141153.487487.patch
Type: text/x-patch
Size: 2503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230109/e512767c/attachment.bin>


More information about the llvm-commits mailing list