Index: llvm/lib/CodeGen/RegisterCoalescer.cpp =================================================================== --- llvm/lib/CodeGen/RegisterCoalescer.cpp +++ llvm/lib/CodeGen/RegisterCoalescer.cpp @@ -1416,6 +1416,8 @@ // $edi = MOV32r0 implicit-def dead $eflags, implicit-def $rdi // undef %0.sub_32bit = MOV32r0 implicit-def dead $eflags, implicit-def %0 + bool NewMIDefinesFullReg = false; + SmallVector NewMIImplDefs; for (unsigned i = NewMI.getDesc().getNumOperands(), e = NewMI.getNumOperands(); @@ -1424,6 +1426,9 @@ if (MO.isReg() && MO.isDef()) { assert(MO.isImplicit()); if (MO.getReg().isPhysical()) { + if (MO.getReg() == DstReg) + NewMIDefinesFullReg = true; + assert(MO.isImplicit() && MO.getReg().isPhysical() && (MO.isDead() || (DefSubIdx && (TRI->getSubReg(MO.getReg(), DefSubIdx) == @@ -1552,8 +1557,12 @@ assert(DstReg.isPhysical() && "Only expect virtual or physical registers in remat"); NewMI.getOperand(0).setIsDead(true); - NewMI.addOperand(MachineOperand::CreateReg( - CopyDstReg, true /*IsDef*/, true /*IsImp*/, false /*IsKill*/)); + + if (!NewMIDefinesFullReg) { + NewMI.addOperand(MachineOperand::CreateReg( + CopyDstReg, true /*IsDef*/, true /*IsImp*/, false /*IsKill*/)); + } + // Record small dead def live-ranges for all the subregisters // of the destination register. // Otherwise, variables that live through may miss some Index: llvm/test/CodeGen/X86/rematerialize-sub-super-reg.mir =================================================================== --- llvm/test/CodeGen/X86/rematerialize-sub-super-reg.mir +++ llvm/test/CodeGen/X86/rematerialize-sub-super-reg.mir @@ -116,8 +116,6 @@ # Handle that rematerializing an instruction with an implicit def of a # virtual super register into a physical register works. -# -# FIXME: Resulting rematerializing has a redundant implicit-def --- name: rematerialize_subregister_into_superreg_def_with_impdef_physreg tracksRegLiveness: true @@ -134,7 +132,7 @@ ; CHECK-NEXT: bb.1: ; CHECK-NEXT: successors: %bb.1(0x80000000) ; CHECK-NEXT: {{ $}} - ; CHECK-NEXT: dead $eax = MOV32ri -11, implicit-def $rax, implicit-def $rax + ; CHECK-NEXT: dead $eax = MOV32ri -11, implicit-def $rax ; CHECK-NEXT: CMP64ri8 %t3, 1, implicit-def $eflags ; CHECK-NEXT: JCC_1 %bb.1, 4, implicit killed $eflags ; CHECK-NEXT: RET 0, $rax