diff --git a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp --- a/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp +++ b/llvm/lib/CodeGen/TwoAddressInstructionPass.cpp @@ -955,12 +955,13 @@ nmi = End; MachineBasicBlock::iterator InsertPos = KillPos; if (LIS) { - // We have to move the copies first so that the MBB is still well-formed - // when calling handleMove(). + // We have to move the copies (and any interleaved debug instructions) + // first so that the MBB is still well-formed when calling handleMove(). for (MachineBasicBlock::iterator MBBI = AfterMI; MBBI != End;) { auto CopyMI = MBBI++; MBB->splice(InsertPos, MBB, CopyMI); - LIS->handleMove(*CopyMI); + if (!CopyMI->isDebugOrPseudoInstr()) + LIS->handleMove(*CopyMI); InsertPos = CopyMI; } End = std::next(MachineBasicBlock::iterator(MI)); diff --git a/llvm/test/DebugInfo/MIR/X86/mlicm-hoist-post-regalloc.mir b/llvm/test/DebugInfo/MIR/X86/mlicm-hoist-post-regalloc.mir --- a/llvm/test/DebugInfo/MIR/X86/mlicm-hoist-post-regalloc.mir +++ b/llvm/test/DebugInfo/MIR/X86/mlicm-hoist-post-regalloc.mir @@ -1,6 +1,7 @@ --- | ; REQUIRES: asserts ; RUN: llc -start-before=phi-node-elimination -stop-after=machinelicm -debug-only=machinelicm -o - %s | FileCheck %s + ; RUN: llc -start-before=phi-node-elimination -stop-after=machinelicm -debug-only=machinelicm -early-live-intervals -o - %s | FileCheck %s ; Ensure we execute machinelicm post register allocation. ; Line numbers should not be retained when loop invariant instructions are hoisted. ;