]> granicus.if.org Git - llvm/commitdiff
Fix subreg value numbers in handleMoveUp
authorStanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>
Sat, 11 Mar 2017 00:14:52 +0000 (00:14 +0000)
committerStanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>
Sat, 11 Mar 2017 00:14:52 +0000 (00:14 +0000)
The problem can occur in presence of subregs. If we are swapping two
instructions defining different subregs of the same register we will
get a new liveout from a block. We need to preserve value number for
block's liveout for successor block's livein to match.

Differential Revision: https://reviews.llvm.org/D30558

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@297534 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/LiveIntervalAnalysis.cpp
unittests/MI/LiveIntervalTest.cpp

index 2720609ab758a9a2d6186cee88d5fee0f7afe276..3f5b8e19d1f0cb7f710562e1a80b13f4186bdb37 100644 (file)
@@ -1232,10 +1232,12 @@ private:
           LiveRange::iterator NewIdxIn = NewIdxOut;
           assert(NewIdxIn == LR.find(NewIdx.getBaseIndex()));
           const SlotIndex SplitPos = NewIdxDef;
+          OldIdxVNI = OldIdxIn->valno;
 
           // Merge the OldIdxIn and OldIdxOut segments into OldIdxOut.
+          OldIdxOut->valno->def = OldIdxIn->start;
           *OldIdxOut = LiveRange::Segment(OldIdxIn->start, OldIdxOut->end,
-                                          OldIdxIn->valno);
+                                          OldIdxOut->valno);
           // OldIdxIn and OldIdxVNI are now undef and can be overridden.
           // We Slide [NewIdxIn, OldIdxIn) down one position.
           //    |- X0/NewIdxIn -| ... |- Xn-1 -||- Xn/OldIdxIn -||- OldIdxOut -|
index 2fd2baecc79b59f483cf47c08fb9a5a2da141cb8..026fb42d345f75300190f9d4baf2ab8d2280e203 100644 (file)
@@ -382,6 +382,24 @@ TEST(LiveIntervalTest, SubRegMoveDown) {
   });
 }
 
+TEST(LiveIntervalTest, SubRegMoveUp) {
+  // handleMoveUp had a bug not updating valno of segment incoming to bb.2
+  // after swapping subreg definitions.
+  liveIntervalTest(R"MIR(
+    successors: %bb.1, %bb.2
+    undef %0.sub0 = IMPLICIT_DEF
+    %0.sub1 = IMPLICIT_DEF
+    S_CBRANCH_VCCNZ %bb.2, implicit undef %vcc
+    S_BRANCH %bb.1
+  bb.1:
+    S_NOP 0, implicit %0.sub1
+  bb.2:
+    S_NOP 0, implicit %0.sub1
+)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
+    testHandleMove(MF, LIS, 1, 0);
+  });
+}
+
 int main(int argc, char **argv) {
   ::testing::InitGoogleTest(&argc, argv);
   initLLVM();