LiveIntervalAnalysis: Fix handleMove() re-using the wrong value number

This fixes http://llvm.org/PR27856

llvm-svn: 270619
This commit is contained in:
Matthias Braun 2016-05-24 21:54:01 +00:00
parent 94ddce2c0e
commit fc4c8a1e46
2 changed files with 27 additions and 9 deletions

View File

@ -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 {

View File

@ -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();