diff options
author | Matthias Braun <matze@braunis.de> | 2016-05-24 21:54:01 +0000 |
---|---|---|
committer | Matthias Braun <matze@braunis.de> | 2016-05-24 21:54:01 +0000 |
commit | fc4c8a1e46ea2d92c0093b44d800955c2b87cdc0 (patch) | |
tree | 102f1f1f39bd198348714ca49a1ae97547e47fe7 | |
parent | 94ddce2c0e27d40813086823487eaabcccd97b7b (diff) | |
download | bcm5719-llvm-fc4c8a1e46ea2d92c0093b44d800955c2b87cdc0.tar.gz bcm5719-llvm-fc4c8a1e46ea2d92c0093b44d800955c2b87cdc0.zip |
LiveIntervalAnalysis: Fix handleMove() re-using the wrong value number
This fixes http://llvm.org/PR27856
llvm-svn: 270619
-rw-r--r-- | llvm/lib/CodeGen/LiveIntervalAnalysis.cpp | 10 | ||||
-rw-r--r-- | llvm/unittests/MI/LiveIntervalTest.cpp | 26 |
2 files changed, 27 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp b/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp index 16d0030a346..2358b0e7464 100644 --- a/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp +++ b/llvm/lib/CodeGen/LiveIntervalAnalysis.cpp @@ -1257,20 +1257,16 @@ private: // value. LiveRange::iterator NewSegment = NewIdxIn; LiveRange::iterator Next = std::next(NewSegment); - NewSegment->valno = OldIdxVNI; if (SlotIndex::isEarlierInstr(Next->start, NewIdx)) { // There is no gap between NewSegment and its predecessor. *NewSegment = LiveRange::Segment(Next->start, SplitPos, - NewSegment->valno); - NewSegment->valno->def = Next->start; - - *Next = LiveRange::Segment(SplitPos, Next->end, Next->valno); + Next->valno); + *Next = LiveRange::Segment(SplitPos, Next->end, OldIdxVNI); Next->valno->def = SplitPos; } else { // There is a gap between NewSegment and its predecessor // Value becomes live in. - *NewSegment = LiveRange::Segment(SplitPos, Next->start, - NewSegment->valno); + *NewSegment = LiveRange::Segment(SplitPos, Next->start, OldIdxVNI); NewSegment->valno->def = SplitPos; } } else { diff --git a/llvm/unittests/MI/LiveIntervalTest.cpp b/llvm/unittests/MI/LiveIntervalTest.cpp index dc555c1e610..e4567363d39 100644 --- a/llvm/unittests/MI/LiveIntervalTest.cpp +++ b/llvm/unittests/MI/LiveIntervalTest.cpp @@ -109,8 +109,8 @@ private: * update affected liveness intervals with LiveIntervalAnalysis::handleMove(). */ static void testHandleMove(MachineFunction &MF, LiveIntervals &LIS, - unsigned From, unsigned To) { - MachineBasicBlock &MBB = MF.front(); + unsigned From, unsigned To, unsigned BlockNum = 0) { + MachineBasicBlock &MBB = *MF.getBlockNumbered(BlockNum); unsigned I = 0; MachineInstr *FromInstr = nullptr; @@ -307,6 +307,28 @@ TEST(LiveIntervalTest, MoveUndefUse) { }); } +TEST(LiveIntervalTest, MoveUpValNos) { + // handleMoveUp() had a bug where it would reuse the value number of the + // destination segment, even though we have no guarntee that this valno wasn't + // used in other segments. + liveIntervalTest( +" successors: %bb.1, %bb.2\n" +" %0 = IMPLICIT_DEF\n" +" JG_1 %bb.2, implicit %eflags\n" +" JMP_1 %bb.1\n" +" bb.2:\n" +" NOOP implicit %0\n" +" bb.1:\n" +" successors: %bb.2\n" +" %0 = IMPLICIT_DEF implicit %0(tied-def 0)\n" +" %0 = IMPLICIT_DEF implicit %0(tied-def 0)\n" +" %0 = IMPLICIT_DEF implicit %0(tied-def 0)\n" +" JMP_1 %bb.2\n", + [](MachineFunction &MF, LiveIntervals &LIS) { + testHandleMove(MF, LIS, 2, 0, 2); + }); +} + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); initLLVM(); |