[PATCH] D26359: Don't assert on missing value from predecessor

Krzysztof Parzyszek via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 8 06:18:08 PST 2016


kparzysz updated this revision to Diff 77180.
kparzysz added a comment.

I found another instance of this problem, this time in extendPHIRanges.

The code in extendPHIRanges tries to extend a LiveRange that could be a subrange, but it checks the main range of the original LiveInterval to see whether it was live-on-exit in the predecessor. The liveness of the main range does not imply that every subrange was live, and the code may end up trying to extend a subrange that was not live (leading to an abort). Here's an example of how this could happen.

The new range is

  %vreg553 [100r,2092B:3)[2092B,2100r:4)[3788r,3872r:1)[3872r,3920B:2)[3920B,4160B:1)[4176B,5156r:2)[5288r,8048B:0)[8064B,9256B:0)  0 at 5288r 1 at 3788r 2 at 3872r 3 at 100r 4 at 2092B-phi   L00000002 [2092B,2100r:1)[3788r,3788d:2)[3872r,3920B:3)[4176B,5156r:3)[5288r,5288d:0)  0 at 5288r 1 at 2092B-phi 2 at 3788r 3 at 3872r   L00000001 [100r,2092B:1)[2092B,2100r:2)[3788r,4160B:3)[4176B,5156r:3)[5288r,8048B:0)[8064B,9256B:0)  0 at 5288r 1 at 100r 2 at 2092B-phi 3 at 3788r

The block starting at 2092 is a loop header, the preheader ends at 2036 (there is an unrelated block in between). The subrange for L0002 is live-on-entry to 2092, but it is not live in the preheader. The original range (for vreg458 shown below) is live-on-exit from the predecessor (preheader), i.e. it is live at 2036. An attempt is made to extend L0002 to 2036 and it fails with an assertion:

  llc: /w/src/llvm.m/lib/CodeGen/LiveRangeCalc.cpp:226: void llvm::LiveRangeCalc::updateFromLiveIns(): Assertion `I.Value && "No live-in value found"' failed.

The original live interval:

  %vreg458 [100r,2092B:0)[2092B,2100r:1)[3788r,3872r:2)[3872r,3920B:3)[3920B,4160B:2)[4176B,8048B:3)[8064B,9256B:3)  0 at 100r 1 at 2092B-phi 2 at 3788r 3 at 3872r   L00000001 [100r,2092B:1)[2092B,2100r:2)[3788r,4160B:0)[4176B,8048B:0)[8064B,9256B:0)  0 at 3788r 1 at 100r 2 at 2092B-phi   L00000002 [2092B,2100r:2)[3788r,3788d:0)[3872r,3920B:1)[4176B,8048B:1)[8064B,9256B:1)  0 at 3788r 1 at 3872r 2 at 2092B-phi


Repository:
  rL LLVM

https://reviews.llvm.org/D26359

Files:
  lib/CodeGen/LiveIntervalAnalysis.cpp
  lib/CodeGen/SplitKit.cpp
  lib/CodeGen/SplitKit.h


Index: lib/CodeGen/SplitKit.h
===================================================================
--- lib/CodeGen/SplitKit.h
+++ lib/CodeGen/SplitKit.h
@@ -386,10 +386,14 @@
   /// Return true if any ranges were skipped.
   bool transferValues();
 
-  /// Live range @p LR has a live PHI def at the beginning of block @p B.
-  /// Extend the range @p LR of all predecessor values that reach this def.
+  /// Live range @p LR corresponding to the lane Mask @p LM has a live
+  /// PHI def at the beginning of block @p B. Extend the range @p LR of
+  /// all predecessor values that reach this def. If @p LR is a subrange,
+  /// the array @p Undefs is the set of all locations where it is undefined
+  /// via <def,read-undef> in other subranges for the same register.
   void extendPHIRange(MachineBasicBlock &B, LiveRangeCalc &LRC,
-                      LiveRange &LR, ArrayRef<SlotIndex>);
+                      LiveRange &LR, LaneBitmask LM,
+                      ArrayRef<SlotIndex> Undefs);
 
   /// extendPHIKillRanges - Extend the ranges of all values killed by original
   /// parent PHIDefs.
Index: lib/CodeGen/SplitKit.cpp
===================================================================
--- lib/CodeGen/SplitKit.cpp
+++ lib/CodeGen/SplitKit.cpp
@@ -1092,13 +1092,19 @@
 }
 
 void SplitEditor::extendPHIRange(MachineBasicBlock &B, LiveRangeCalc &LRC,
-                                 LiveRange &LR, ArrayRef<SlotIndex> Undefs) {
+                                 LiveRange &LR, LaneBitmask LM,
+                                 ArrayRef<SlotIndex> Undefs) {
   for (MachineBasicBlock *P : B.predecessors()) {
     SlotIndex End = LIS.getMBBEndIdx(P);
     SlotIndex LastUse = End.getPrevSlot();
     // The predecessor may not have a live-out value. That is OK, like an
     // undef PHI operand.
-    if (Edit->getParent().liveAt(LastUse))
+    LiveInterval &PLI = Edit->getParent();
+    // Need the cast because the inputs to ?: would otherwise be deemed
+    // "incompatible": SubRange vs LiveInterval.
+    LiveRange &PSR = (LM != ~0u) ? getSubRangeForMask(LM, PLI)
+                                 : static_cast<LiveRange&>(PLI);
+    if (PSR.liveAt(LastUse))
       LRC.extend(LR, End, /*PhysReg=*/0, Undefs);
   }
 }
@@ -1120,7 +1126,7 @@
     LiveRangeCalc &LRC = getLRCalc(RegIdx);
     MachineBasicBlock &B = *LIS.getMBBFromIndex(V->def);
     if (!removeDeadSegment(V->def, LI))
-      extendPHIRange(B, LRC, LI, /*Undefs=*/{});
+      extendPHIRange(B, LRC, LI, ~0u, /*Undefs=*/{});
   }
 
   SmallVector<SlotIndex, 4> Undefs;
@@ -1141,7 +1147,7 @@
                    &LIS.getVNInfoAllocator());
       Undefs.clear();
       LI.computeSubRangeUndefs(Undefs, PS.LaneMask, MRI, *LIS.getSlotIndexes());
-      extendPHIRange(B, SubLRC, S, Undefs);
+      extendPHIRange(B, SubLRC, S, PS.LaneMask, Undefs);
     }
   }
 }
Index: lib/CodeGen/LiveIntervalAnalysis.cpp
===================================================================
--- lib/CodeGen/LiveIntervalAnalysis.cpp
+++ lib/CodeGen/LiveIntervalAnalysis.cpp
@@ -388,9 +388,11 @@
       if (!LiveOut.insert(Pred).second)
         continue;
       SlotIndex Stop = Indexes.getMBBEndIdx(Pred);
-      assert(OldRange.getVNInfoBefore(Stop) == VNI &&
-             "Wrong value out of predecessor");
-      WorkList.push_back(std::make_pair(Stop, VNI));
+      // The exit from a predecessor may be jointly dominated by undefs.
+      if (VNInfo *PVNI = OldRange.getVNInfoBefore(Stop)) {
+        assert(PVNI == VNI && "Wrong value out of predecessor");
+        WorkList.push_back(std::make_pair(Stop, VNI));
+      }
     }
   }
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26359.77180.patch
Type: text/x-patch
Size: 3617 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161108/56bc4647/attachment.bin>


More information about the llvm-commits mailing list