Skip to content

Commit b546174

Browse files
committedMar 11, 2017
Fix subreg value numbers in handleMoveUp
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 llvm-svn: 297534
1 parent 31d01ba commit b546174

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed
 

‎llvm/lib/CodeGen/LiveIntervalAnalysis.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1232,10 +1232,12 @@ class LiveIntervals::HMEditor {
12321232
LiveRange::iterator NewIdxIn = NewIdxOut;
12331233
assert(NewIdxIn == LR.find(NewIdx.getBaseIndex()));
12341234
const SlotIndex SplitPos = NewIdxDef;
1235+
OldIdxVNI = OldIdxIn->valno;
12351236

12361237
// Merge the OldIdxIn and OldIdxOut segments into OldIdxOut.
1238+
OldIdxOut->valno->def = OldIdxIn->start;
12371239
*OldIdxOut = LiveRange::Segment(OldIdxIn->start, OldIdxOut->end,
1238-
OldIdxIn->valno);
1240+
OldIdxOut->valno);
12391241
// OldIdxIn and OldIdxVNI are now undef and can be overridden.
12401242
// We Slide [NewIdxIn, OldIdxIn) down one position.
12411243
// |- X0/NewIdxIn -| ... |- Xn-1 -||- Xn/OldIdxIn -||- OldIdxOut -|

‎llvm/unittests/MI/LiveIntervalTest.cpp

+18
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,24 @@ TEST(LiveIntervalTest, SubRegMoveDown) {
382382
});
383383
}
384384

385+
TEST(LiveIntervalTest, SubRegMoveUp) {
386+
// handleMoveUp had a bug not updating valno of segment incoming to bb.2
387+
// after swapping subreg definitions.
388+
liveIntervalTest(R"MIR(
389+
successors: %bb.1, %bb.2
390+
undef %0.sub0 = IMPLICIT_DEF
391+
%0.sub1 = IMPLICIT_DEF
392+
S_CBRANCH_VCCNZ %bb.2, implicit undef %vcc
393+
S_BRANCH %bb.1
394+
bb.1:
395+
S_NOP 0, implicit %0.sub1
396+
bb.2:
397+
S_NOP 0, implicit %0.sub1
398+
)MIR", [](MachineFunction &MF, LiveIntervals &LIS) {
399+
testHandleMove(MF, LIS, 1, 0);
400+
});
401+
}
402+
385403
int main(int argc, char **argv) {
386404
::testing::InitGoogleTest(&argc, argv);
387405
initLLVM();

0 commit comments

Comments
 (0)
Please sign in to comment.