diff --git a/llvm/lib/CodeGen/MachineBasicBlock.cpp b/llvm/lib/CodeGen/MachineBasicBlock.cpp --- a/llvm/lib/CodeGen/MachineBasicBlock.cpp +++ b/llvm/lib/CodeGen/MachineBasicBlock.cpp @@ -987,7 +987,7 @@ addLiveIns(*SplitBB, LiveRegs); if (LIS) - LIS->insertMBBInMaps(SplitBB, &MI); + LIS->insertMBBInMaps(SplitBB, &*SplitPoint); return SplitBB; } 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 @@ -149,6 +149,19 @@ LIS.handleMoveIntoNewBundle(*BundleStart, true); } +/** + * Split block numbered \p BlockNum at instruction \p SplitAt using + * MachineBasicBlock::splitAt updating liveness intervals. + */ +static void testSplitAt(MachineFunction &MF, LiveIntervals &LIS, + unsigned SplitAt, unsigned BlockNum) { + MachineInstr &SplitInstr = getMI(MF, SplitAt, BlockNum); + MachineBasicBlock &MBB = *SplitInstr.getParent(); + + // Split block and update live intervals + MBB.splitAt(SplitInstr, false, &LIS); +} + static void liveIntervalTest(StringRef MIRFunc, LiveIntervalTest T) { LLVMContext Context; std::unique_ptr TM = createTargetMachine(); @@ -608,6 +621,34 @@ }); } +TEST(LiveIntervalTest, SplitAtOneInstruction) { + liveIntervalTest(R"MIR( + successors: %bb.1 + %0 = IMPLICIT_DEF + S_BRANCH %bb.1 + bb.1: + S_NOP 0 +)MIR", [](MachineFunction &MF, LiveIntervals &LIS) { + testSplitAt(MF, LIS, 1, 0); + }); +} + +TEST(LiveIntervalTest, SplitAtMultiInstruction) { + liveIntervalTest(R"MIR( + successors: %bb.1 + %0 = IMPLICIT_DEF + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_NOP 0 + S_BRANCH %bb.1 + bb.1: + S_NOP 0 +)MIR", [](MachineFunction &MF, LiveIntervals &LIS) { + testSplitAt(MF, LIS, 0, 0); + }); +} + int main(int argc, char **argv) { ::testing::InitGoogleTest(&argc, argv); initLLVM();