diff --git a/llvm/lib/CodeGen/LiveIntervals.cpp b/llvm/lib/CodeGen/LiveIntervals.cpp --- a/llvm/lib/CodeGen/LiveIntervals.cpp +++ b/llvm/lib/CodeGen/LiveIntervals.cpp @@ -1662,7 +1662,7 @@ ArrayRef OrigRegs) { // Find anchor points, which are at the beginning/end of blocks or at // instructions that already have indexes. - while (Begin != MBB->begin() && !Indexes->hasIndex(*Begin)) + while (Begin != MBB->begin() && !Indexes->hasIndex(*std::prev(Begin))) --Begin; while (End != MBB->end() && !Indexes->hasIndex(*End)) ++End; diff --git a/llvm/lib/CodeGen/SlotIndexes.cpp b/llvm/lib/CodeGen/SlotIndexes.cpp --- a/llvm/lib/CodeGen/SlotIndexes.cpp +++ b/llvm/lib/CodeGen/SlotIndexes.cpp @@ -179,21 +179,12 @@ void SlotIndexes::repairIndexesInRange(MachineBasicBlock *MBB, MachineBasicBlock::iterator Begin, MachineBasicBlock::iterator End) { - // FIXME: Is this really necessary? The only caller repairIntervalsForRange() - // does the same thing. - // Find anchor points, which are at the beginning/end of blocks or at - // instructions that already have indexes. - while (Begin != MBB->begin() && !hasIndex(*Begin)) - --Begin; - while (End != MBB->end() && !hasIndex(*End)) - ++End; - bool includeStart = (Begin == MBB->begin()); SlotIndex startIdx; if (includeStart) startIdx = getMBBStartIdx(MBB); else - startIdx = getInstructionIndex(*Begin); + startIdx = getInstructionIndex(*--Begin); SlotIndex endIdx; if (End == MBB->end()) diff --git a/llvm/test/CodeGen/Hexagon/mulhs.ll b/llvm/test/CodeGen/Hexagon/mulhs.ll --- a/llvm/test/CodeGen/Hexagon/mulhs.ll +++ b/llvm/test/CodeGen/Hexagon/mulhs.ll @@ -1,4 +1,5 @@ ; RUN: llc -march=hexagon < %s | FileCheck %s +; RUN: llc -march=hexagon -early-live-intervals -verify-machineinstrs < %s | FileCheck %s ; CHECK: mpy ; CHECK-NOT: call diff --git a/llvm/unittests/MI/LiveIntervalTest.cpp b/llvm/unittests/MI/LiveIntervalTest.cpp --- a/llvm/unittests/MI/LiveIntervalTest.cpp +++ b/llvm/unittests/MI/LiveIntervalTest.cpp @@ -662,6 +662,27 @@ }); } +TEST(LiveIntervalTest, RepairIntervals) { + liveIntervalTest(R"MIR( + %1:sgpr_32 = IMPLICIT_DEF + dead %2:sgpr_32 = COPY undef %3.sub0:sgpr_128 + undef %4.sub2:sgpr_128 = COPY %1:sgpr_32 + %5:sgpr_32 = COPY %4.sub2:sgpr_128 +)MIR", [](MachineFunction &MF, LiveIntervals &LIS) { + MachineInstr &Instr1 = getMI(MF, 1, 0); + MachineInstr &Instr2 = getMI(MF, 2, 0); + MachineInstr &Instr3 = getMI(MF, 3, 0); + LIS.RemoveMachineInstrFromMaps(Instr2); + MachineBasicBlock *MBB = Instr1.getParent(); + SmallVector OrigRegs{ + Instr1.getOperand(0).getReg(), + Instr2.getOperand(0).getReg(), + Instr2.getOperand(1).getReg(), + }; + LIS.repairIntervalsInRange(MBB, Instr2, Instr3, OrigRegs); + }); +} + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); initLLVM();