Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp =================================================================== --- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -1166,12 +1166,21 @@ // inserted after the definition of Val when emitting the instructions // after ISel. An alternative could be to teach // ScheduleDAGSDNodes::EmitSchedule to delay the insertion properly. - LLVM_DEBUG(if (ValSDNodeOrder > DbgSDNodeOrder) dbgs() - << "changing SDNodeOrder from " << DbgSDNodeOrder << " to " - << ValSDNodeOrder << "\n"); - SDV = getDbgValue(Val, Variable, Expr, dl, - std::max(DbgSDNodeOrder, ValSDNodeOrder)); - DAG.AddDbgValue(SDV, Val.getNode(), false); + + auto *Node = Val.getNode(); + if (Node->getOpcode() == ISD::CopyFromReg) { + RegisterSDNode *RN = dyn_cast(Node->getOperand(1)); + SDV = DAG.getVRegDbgValue(Variable, Expr, RN->getReg(), false, dl, + DbgSDNodeOrder); + DAG.AddDbgValue(SDV, nullptr, false); + } else { + LLVM_DEBUG(if (ValSDNodeOrder > DbgSDNodeOrder) dbgs() + << "changing SDNodeOrder from " << DbgSDNodeOrder << " to " + << ValSDNodeOrder << "\n"); + SDV = getDbgValue(Val, Variable, Expr, dl, + std::max(DbgSDNodeOrder, ValSDNodeOrder)); + DAG.AddDbgValue(SDV, Val.getNode(), false); + } } else LLVM_DEBUG(dbgs() << "Resolved dangling debug info for " << *DI << "in EmitFuncArgumentDbgValue\n"); Index: test/DebugInfo/COFF/register-variables.ll =================================================================== --- test/DebugInfo/COFF/register-variables.ll +++ test/DebugInfo/COFF/register-variables.ll @@ -32,9 +32,6 @@ ; ASM: #DEBUG_VALUE: f:p <- $esi ; ASM: callq getint ; ASM: [[after_getint:\.Ltmp.*]]: -; ASM: #DEBUG_VALUE: a <- $eax -; ASM: #DEBUG_VALUE: inlineinc:a <- $eax -; ASM: #DEBUG_VALUE: c <- $eax ; ASM: testl %esi, %esi ; ASM: je .LBB0_2 ; ASM: [[after_je:\.Ltmp.*]]: @@ -45,16 +42,17 @@ ; ASM: addl $1, %eax ; ASM: [[after_inc_eax:\.Ltmp.*]]: ; ASM: #DEBUG_VALUE: inlineinc:b <- $eax -; ASM: #DEBUG_VALUE: b <- $eax ; ASM: addl $1, x(%rip) ; ASM: [[after_if:\.Ltmp.*]]: ; ASM: .LBB0_2: # %if.else ; ASM: #DEBUG_VALUE: f:p <- $esi +; ASM: #DEBUG_VALUE: c <- $eax ; ASM: movl %eax, %ecx ; ASM: addq $32, %rsp ; ASM: popq %rsi ; ASM: [[func_end:\.Ltmp.*]]: ; ASM: jmp putint # TAILCALL +; ASM: [[func_finished:\.Ltmp.*]]: ; ASM: .short 4414 # Record kind: S_LOCAL ; ASM: .asciz "p" @@ -62,18 +60,15 @@ ; ASM: .cv_def_range [[p_ecx_esi]] [[func_end]], "A\021\027\000\000\000" ; ASM: .short 4414 # Record kind: S_LOCAL ; ASM: .asciz "c" -; ASM: .cv_def_range [[after_getint]] [[after_je]], "A\021\021\000\000\000" +; ASM: .cv_def_range [[after_if]] [[func_finished]], "A\021\021\000\000\000" ; ASM: .short 4414 # Record kind: S_LOCAL ; ASM: .asciz "a" -; ASM: .cv_def_range [[after_getint]] [[after_inc_eax]], "A\021\021\000\000\000" -; ASM: .short 4414 # Record kind: S_LOCAL -; ASM: .asciz "b" -; ASM: .cv_def_range [[after_inc_eax]] [[after_if]], "A\021\021\000\000\000" +; ASM: .cv_def_range [[after_je]] [[after_inc_eax]], "A\021\021\000\000\000" ; ASM: .short 4429 # Record kind: S_INLINESITE ; ASM: .short 4414 # Record kind: S_LOCAL ; ASM: .asciz "a" -; ASM: .cv_def_range [[after_getint]] [[after_inc_eax]], "A\021\021\000\000\000" +; ASM: .cv_def_range [[after_je]] [[after_inc_eax]], "A\021\021\000\000\000" ; ASM: .short 4414 # Record kind: S_LOCAL ; ASM: .asciz "b" ; ASM: .cv_def_range [[after_inc_eax]] [[after_if]], "A\021\021\000\000\000" @@ -116,9 +111,9 @@ ; OBJ: DefRangeRegisterSym { ; OBJ: Register: EAX (0x11) ; OBJ: LocalVariableAddrRange { -; OBJ: OffsetStart: .text+0xC +; OBJ: OffsetStart: .text+0x1A ; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x4 +; OBJ: Range: 0xC ; OBJ: } ; OBJ: } ; OBJ: LocalSym { @@ -130,23 +125,9 @@ ; OBJ: DefRangeRegisterSym { ; OBJ: Register: EAX (0x11) ; OBJ: LocalVariableAddrRange { -; OBJ: OffsetStart: .text+0xC -; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x7 -; OBJ: } -; OBJ: } -; OBJ: LocalSym { -; OBJ: Type: int (0x74) -; OBJ: Flags [ (0x0) -; OBJ: ] -; OBJ: VarName: b -; OBJ: } -; OBJ: DefRangeRegisterSym { -; OBJ: Register: EAX (0x11) -; OBJ: MayHaveNoName: 0 -; OBJ: OffsetStart: .text+0x13 +; OBJ: OffsetStart: .text+0x10 ; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x7 +; OBJ: Range: 0x3 ; OBJ: } ; OBJ: } ; OBJ: InlineSiteSym { @@ -164,9 +145,9 @@ ; OBJ: DefRangeRegisterSym { ; OBJ: Register: EAX (0x11) ; OBJ: LocalVariableAddrRange { -; OBJ: OffsetStart: .text+0xC +; OBJ: OffsetStart: .text+0x10 ; OBJ: ISectStart: 0x0 -; OBJ: Range: 0x7 +; OBJ: Range: 0x3 ; OBJ: } ; OBJ: } ; OBJ: LocalSym {