diff --git a/llvm/lib/CodeGen/PHIElimination.cpp b/llvm/lib/CodeGen/PHIElimination.cpp --- a/llvm/lib/CodeGen/PHIElimination.cpp +++ b/llvm/lib/CodeGen/PHIElimination.cpp @@ -515,9 +515,8 @@ // case, we should mark the last such terminator as being the killing // block, not the copy. MachineBasicBlock::iterator KillInst = opBlock.end(); - MachineBasicBlock::iterator FirstTerm = opBlock.getFirstTerminator(); - for (MachineBasicBlock::iterator Term = FirstTerm; - Term != opBlock.end(); ++Term) { + for (MachineBasicBlock::iterator Term = InsertPos; Term != opBlock.end(); + ++Term) { if (Term->readsRegister(SrcReg)) KillInst = Term; } @@ -527,7 +526,7 @@ if (reusedIncoming || !IncomingReg) { // We may have to rewind a bit if we didn't insert a copy this time. - KillInst = FirstTerm; + KillInst = InsertPos; while (KillInst != opBlock.begin()) { --KillInst; if (KillInst->isDebugInstr()) @@ -574,9 +573,8 @@ if (!isLiveOut) { MachineBasicBlock::iterator KillInst = opBlock.end(); - MachineBasicBlock::iterator FirstTerm = opBlock.getFirstTerminator(); - for (MachineBasicBlock::iterator Term = FirstTerm; - Term != opBlock.end(); ++Term) { + for (MachineBasicBlock::iterator Term = InsertPos; + Term != opBlock.end(); ++Term) { if (Term->readsRegister(SrcReg)) KillInst = Term; } @@ -586,7 +584,7 @@ if (reusedIncoming || !IncomingReg) { // We may have to rewind a bit if we didn't just insert a copy. - KillInst = FirstTerm; + KillInst = InsertPos; while (KillInst != opBlock.begin()) { --KillInst; if (KillInst->isDebugInstr()) diff --git a/llvm/test/CodeGen/X86/callbr-asm-kill.ll b/llvm/test/CodeGen/X86/callbr-asm-kill.ll --- a/llvm/test/CodeGen/X86/callbr-asm-kill.ll +++ b/llvm/test/CodeGen/X86/callbr-asm-kill.ll @@ -3,8 +3,9 @@ declare void @foo(i8*) -; FIXME: The COPY from [[MOV64rm]] should not be killed, because there is a -; subsequent use of [[MOV64rm]] in the INLINEASM_BR instruction. +; Check that the COPY from [[MOV64rm]] is not killed, because there is a +; subsequent use of [[MOV64rm]] in the INLINEASM_BR instruction which should be +; killed instead. define void @test1(i8* %arg, i8** %mem) nounwind { ; CHECK-LABEL: name: test1 ; CHECK: bb.0.entry: @@ -24,8 +25,8 @@ ; CHECK-NEXT: $rdi = COPY killed [[COPY3]] ; CHECK-NEXT: CALL64pcrel32 target-flags(x86-plt) @foo, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit-def $rsp, implicit-def $ssp ; CHECK-NEXT: ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp - ; CHECK-NEXT: [[COPY4:%[0-9]+]]:gr64 = COPY killed [[MOV64rm]] - ; CHECK-NEXT: INLINEASM_BR &"", 9 /* sideeffect mayload attdialect */, 196654 /* mem:m */, [[MOV64rm]], 1, $noreg, 0, $noreg, 13 /* imm */, blockaddress(@test1, %ir-block.loop) + ; CHECK-NEXT: [[COPY4:%[0-9]+]]:gr64 = COPY [[MOV64rm]] + ; CHECK-NEXT: INLINEASM_BR &"", 9 /* sideeffect mayload attdialect */, 196654 /* mem:m */, killed [[MOV64rm]], 1, $noreg, 0, $noreg, 13 /* imm */, blockaddress(@test1, %ir-block.loop) ; CHECK-NEXT: JMP_1 %bb.2 ; CHECK-NEXT: {{ $}} ; CHECK-NEXT: bb.2.end: