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 @@ -1406,6 +1406,10 @@ return LQR_Dead; } + // Skip over debug instructions. + if (I != end() && I->isDebugInstr()) + ++I; + // If we reached the end, it is safe to clobber Reg at the end of a block of // no successor has it live in. if (I == end()) { @@ -1462,6 +1466,11 @@ } while (I != begin() && N > 0); } + // If all the instructions before this in the block are debug instructions, + // skip over them. + while (I != begin() && std::prev(I)->isDebugInstr()) + --I; + // Did we get to the start of the block? if (I == begin()) { // If so, the register's state is definitely defined by the live-in state. diff --git a/llvm/test/CodeGen/X86/leaFixup64.mir b/llvm/test/CodeGen/X86/leaFixup64.mir --- a/llvm/test/CodeGen/X86/leaFixup64.mir +++ b/llvm/test/CodeGen/X86/leaFixup64.mir @@ -148,6 +148,10 @@ ret i32 0 } + define i32 @pr43758() { + ret i32 0 + } + ... --- @@ -1129,6 +1133,62 @@ RETQ $ebp ... +--- +name: pr43758 +alignment: 16 +exposesReturnsTwice: false +legalized: false +regBankSelected: false +selected: false +tracksRegLiveness: true +liveins: + - { reg: '$rax' } + - { reg: '$rbp' } +frameInfo: + isFrameAddressTaken: false + isReturnAddressTaken: false + hasStackMap: false + hasPatchPoint: false + stackSize: 0 + offsetAdjustment: 0 + maxAlignment: 0 + adjustsStack: false + hasCalls: false + maxCallFrameSize: 0 + hasOpaqueSPAdjustment: false + hasVAStart: false + hasMustTailInVarArgFunc: false +body: | + bb.0 (%ir-block.0): + liveins: $rax, $rbp + + ; CHECK-LABEL: name: pr43758 + ; CHECK: liveins: $rax, $rbp + ; CHECK: DBG_VALUE 0, $noreg + ; CHECK: NOOP + ; CHECK: NOOP + ; CHECK: NOOP + ; CHECK: NOOP + ; CHECK: $ebp = ADD32rr $ebp, $eax, implicit-def $eflags, implicit $rbp, implicit $rax + ; CHECK: NOOP + ; CHECK: NOOP + ; CHECK: NOOP + ; CHECK: NOOP + ; CHECK: RETQ $ebp + DBG_VALUE 0, $noreg + NOOP + NOOP + NOOP + NOOP + $ebp = LEA64_32r killed $rbp, 1, killed $rax, 0, $noreg + NOOP + NOOP + NOOP + NOOP + RETQ $ebp + +... +...