diff --git a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h --- a/llvm/include/llvm/CodeGen/MachineRegisterInfo.h +++ b/llvm/include/llvm/CodeGen/MachineRegisterInfo.h @@ -823,12 +823,13 @@ /// updateDbgUsersToReg - Update a collection of DBG_VALUE instructions /// to refer to the designated register. - void updateDbgUsersToReg(Register Reg, - ArrayRef Users) const { + void updateDbgUsersToReg(Register OldReg, Register NewReg, + ArrayRef Users) const { for (MachineInstr *MI : Users) { - assert(MI->isDebugInstr()); - assert(MI->getOperand(0).isReg()); - MI->getOperand(0).setReg(Reg); + assert(MI->isDebugValue()); + assert(MI->hasDebugOperandForReg(OldReg)); + for (auto &Op : MI->getDebugOperandsForReg(OldReg)) + Op.setReg(NewReg); } } diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp b/llvm/lib/CodeGen/MachineCopyPropagation.cpp --- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp +++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp @@ -734,7 +734,8 @@ // Update matching debug values, if any. assert(MaybeDead->isCopy()); Register SrcReg = MaybeDead->getOperand(1).getReg(); - MRI->updateDbgUsersToReg(SrcReg, CopyDbgUsers[MaybeDead]); + Register DestReg = MaybeDead->getOperand(0).getReg(); + MRI->updateDbgUsersToReg(DestReg, SrcReg, CopyDbgUsers[MaybeDead]); MaybeDead->eraseFromParent(); Changed = true;