From e1016f1bc793457867c6e91f1f13a61c50eab571 Mon Sep 17 00:00:00 2001 From: Tim Renouf Date: Tue, 17 Jul 2018 12:38:39 +0000 Subject: More fixes for subreg join failure in RegCoalescer Summary: Part of the adjustCopiesBackFrom method wasn't correctly dealing with SubRange intervals when updating. 2 changes. The first to ensure that bogus SubRange Segments aren't propagated when encountering Segments of the form [1234r, 1234d:0) when preparing to merge value numbers. These can be removed in this case. The second forces a shrinkToUses call if SubRanges end on the copy index (instead of just the parent register). V2: Addressed review comments, plus MIR test instead of ll test Subscribers: MatzeB, qcolombet, nhaehnle Differential Revision: https://reviews.llvm.org/D40308 Change-Id: I1d2b2b4beea802fce11da01edf71feb2064aab05 llvm-svn: 337273 --- llvm/lib/CodeGen/RegisterCoalescer.cpp | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) (limited to 'llvm/lib/CodeGen/RegisterCoalescer.cpp') diff --git a/llvm/lib/CodeGen/RegisterCoalescer.cpp b/llvm/lib/CodeGen/RegisterCoalescer.cpp index 02164d9afbe..5c5f8dc528c 100644 --- a/llvm/lib/CodeGen/RegisterCoalescer.cpp +++ b/llvm/lib/CodeGen/RegisterCoalescer.cpp @@ -589,6 +589,13 @@ bool RegisterCoalescer::adjustCopiesBackFrom(const CoalescerPair &CP, // Do the same for the subregister segments. for (LiveInterval::SubRange &S : IntB.subranges()) { + // Check for SubRange Segments of the form [1234r,1234d:0) which can be + // removed to prevent creating bogus SubRange Segments. + LiveInterval::iterator SS = S.FindSegmentContaining(CopyIdx); + if (SS != S.end() && SlotIndex::isSameInstr(SS->start, SS->end)) { + S.removeSegment(*SS, true); + continue; + } VNInfo *SubBValNo = S.getVNInfoAt(CopyIdx); S.addSegment(LiveInterval::Segment(FillerStart, FillerEnd, SubBValNo)); VNInfo *SubValSNo = S.getVNInfoAt(AValNo->def.getPrevSlot()); @@ -605,11 +612,21 @@ bool RegisterCoalescer::adjustCopiesBackFrom(const CoalescerPair &CP, ValSEndInst->getOperand(UIdx).setIsKill(false); } - // Rewrite the copy. If the copy instruction was killing the destination - // register before the merge, find the last use and trim the live range. That - // will also add the isKill marker. + // Rewrite the copy. CopyMI->substituteRegister(IntA.reg, IntB.reg, 0, *TRI); - if (AS->end == CopyIdx) + // If the copy instruction was killing the destination register or any + // subrange before the merge trim the live range. + bool RecomputeLiveRange = AS->end == CopyIdx; + if (!RecomputeLiveRange) { + for (LiveInterval::SubRange &S : IntA.subranges()) { + LiveInterval::iterator SS = S.FindSegmentContaining(CopyUseIdx); + if (SS != S.end() && SS->end == CopyIdx) { + RecomputeLiveRange = true; + break; + } + } + } + if (RecomputeLiveRange) shrinkToUses(&IntA); ++numExtends; -- cgit v1.2.3