[PATCH] D128553: [LiveIntervals] Fix incorrect range (re)construction from subranges.

Daniil Fukalov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 24 12:43:41 PDT 2022


dfukalov created this revision.
dfukalov added reviewers: rampitec, arsenm, qcolombet, MatzeB.
Herald added a subscriber: hiraditya.
Herald added a project: All.
dfukalov requested review of this revision.
Herald added a subscriber: wdng.
Herald added a project: LLVM.

After D82916 <https://reviews.llvm.org/D82916> `updateAllRanges()` started to fix holes in main range with
subranges but it fails on instructions with two subregs def which are parts of
one reg. The main range constructed with //all// subranges of subregs just after
processing the first operand. So the main range gets intervals from subranges
those are not updated yet.

The patch takes into account lane mask to update the main range.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128553

Files:
  llvm/lib/CodeGen/LiveIntervals.cpp
  llvm/unittests/MI/LiveIntervalTest.cpp


Index: llvm/unittests/MI/LiveIntervalTest.cpp
===================================================================
--- llvm/unittests/MI/LiveIntervalTest.cpp
+++ llvm/unittests/MI/LiveIntervalTest.cpp
@@ -532,6 +532,19 @@
   });
 }
 
+TEST(LiveIntervalTest, TestMoveSubRegsOfOneReg) {
+  liveIntervalTest(R"MIR(
+    INLINEASM &"", 0, 1835018, def undef %4.sub0:vreg_64, 1835018, def undef %4.sub1:vreg_64
+    %1:vreg_64 = COPY %4
+    undef %2.sub0:vreg_64 = V_MOV_B32_e32 0, implicit $exec
+    %2.sub1:vreg_64 = COPY %2.sub0
+    %3:vreg_64 = COPY %2
+)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
+    testHandleMove(MF, LIS, 1, 4);
+    testHandleMove(MF, LIS, 0, 3);
+  });
+}
+
 TEST(LiveIntervalTest, BundleUse) {
   liveIntervalTest(R"MIR(
     %0 = IMPLICIT_DEF
Index: llvm/lib/CodeGen/LiveIntervals.cpp
===================================================================
--- llvm/lib/CodeGen/LiveIntervals.cpp
+++ llvm/lib/CodeGen/LiveIntervals.cpp
@@ -1049,12 +1049,17 @@
         // we may end up with a main range not covering all subranges.
         // This is extremely rare case, so let's check and reconstruct the
         // main range.
-        for (LiveInterval::SubRange &S : LI.subranges()) {
-          if (LI.covers(S))
-            continue;
-          LI.clear();
-          LIS.constructMainRangeFromSubranges(LI);
-          break;
+        if (LI.hasSubRanges()) {
+          unsigned SubReg = MO.getSubReg();
+          LaneBitmask LaneMask = SubReg ? TRI.getSubRegIndexLaneMask(SubReg)
+                                        : MRI.getMaxLaneMaskForVReg(Reg);
+          for (LiveInterval::SubRange &S : LI.subranges()) {
+            if ((S.LaneMask & LaneMask).none() || LI.covers(S))
+              continue;
+            LI.clear();
+            LIS.constructMainRangeFromSubranges(LI);
+            break;
+          }
         }
 
         continue;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128553.439863.patch
Type: text/x-patch
Size: 1896 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220624/0e0b4c57/attachment.bin>


More information about the llvm-commits mailing list