[PATCH] D110182: [LiveIntervals] Find better anchoring end points when repairing ranges

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 18 11:37:37 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGdbed4326dd9c: [LiveIntervals] Find better anchoring end points when repairing ranges (authored by foad).

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D110182

Files:
  llvm/lib/CodeGen/LiveIntervals.cpp
  llvm/lib/CodeGen/SlotIndexes.cpp
  llvm/test/CodeGen/Hexagon/mulhs.ll
  llvm/unittests/MI/LiveIntervalTest.cpp


Index: llvm/unittests/MI/LiveIntervalTest.cpp
===================================================================
--- llvm/unittests/MI/LiveIntervalTest.cpp
+++ llvm/unittests/MI/LiveIntervalTest.cpp
@@ -662,6 +662,27 @@
   });
 }
 
+TEST(LiveIntervalTest, RepairIntervals) {
+  liveIntervalTest(R"MIR(
+  %1:sgpr_32 = IMPLICIT_DEF
+  dead %2:sgpr_32 = COPY undef %3.sub0:sgpr_128
+  undef %4.sub2:sgpr_128 = COPY %1:sgpr_32
+  %5:sgpr_32 = COPY %4.sub2:sgpr_128
+)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
+    MachineInstr &Instr1 = getMI(MF, 1, 0);
+    MachineInstr &Instr2 = getMI(MF, 2, 0);
+    MachineInstr &Instr3 = getMI(MF, 3, 0);
+    LIS.RemoveMachineInstrFromMaps(Instr2);
+    MachineBasicBlock *MBB = Instr1.getParent();
+    SmallVector<Register> OrigRegs{
+      Instr1.getOperand(0).getReg(),
+      Instr2.getOperand(0).getReg(),
+      Instr2.getOperand(1).getReg(),
+    };
+    LIS.repairIntervalsInRange(MBB, Instr2, Instr3, OrigRegs);
+  });
+}
+
 int main(int argc, char **argv) {
   ::testing::InitGoogleTest(&argc, argv);
   initLLVM();
Index: llvm/test/CodeGen/Hexagon/mulhs.ll
===================================================================
--- llvm/test/CodeGen/Hexagon/mulhs.ll
+++ llvm/test/CodeGen/Hexagon/mulhs.ll
@@ -1,4 +1,5 @@
 ; RUN: llc -march=hexagon < %s | FileCheck %s
+; RUN: llc -march=hexagon -early-live-intervals -verify-machineinstrs < %s | FileCheck %s
 
 ; CHECK: mpy
 ; CHECK-NOT: call
Index: llvm/lib/CodeGen/SlotIndexes.cpp
===================================================================
--- llvm/lib/CodeGen/SlotIndexes.cpp
+++ llvm/lib/CodeGen/SlotIndexes.cpp
@@ -179,21 +179,12 @@
 void SlotIndexes::repairIndexesInRange(MachineBasicBlock *MBB,
                                        MachineBasicBlock::iterator Begin,
                                        MachineBasicBlock::iterator End) {
-  // FIXME: Is this really necessary? The only caller repairIntervalsForRange()
-  // does the same thing.
-  // Find anchor points, which are at the beginning/end of blocks or at
-  // instructions that already have indexes.
-  while (Begin != MBB->begin() && !hasIndex(*Begin))
-    --Begin;
-  while (End != MBB->end() && !hasIndex(*End))
-    ++End;
-
   bool includeStart = (Begin == MBB->begin());
   SlotIndex startIdx;
   if (includeStart)
     startIdx = getMBBStartIdx(MBB);
   else
-    startIdx = getInstructionIndex(*Begin);
+    startIdx = getInstructionIndex(*--Begin);
 
   SlotIndex endIdx;
   if (End == MBB->end())
Index: llvm/lib/CodeGen/LiveIntervals.cpp
===================================================================
--- llvm/lib/CodeGen/LiveIntervals.cpp
+++ llvm/lib/CodeGen/LiveIntervals.cpp
@@ -1662,7 +1662,7 @@
                                       ArrayRef<Register> OrigRegs) {
   // Find anchor points, which are at the beginning/end of blocks or at
   // instructions that already have indexes.
-  while (Begin != MBB->begin() && !Indexes->hasIndex(*Begin))
+  while (Begin != MBB->begin() && !Indexes->hasIndex(*std::prev(Begin)))
     --Begin;
   while (End != MBB->end() && !Indexes->hasIndex(*End))
     ++End;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D110182.445582.patch
Type: text/x-patch
Size: 3124 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220718/588064f4/attachment.bin>


More information about the llvm-commits mailing list