diff --git a/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp --- a/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp @@ -556,9 +556,10 @@ unsigned Base = Loc.SpillLocation.SpillBase; auto *TRI = MF.getSubtarget().getRegisterInfo(); if (MI.isNonListDebugValue()) { - DIExpr = - TRI->prependOffsetExpression(DIExpr, DIExpression::ApplyOffset, - Loc.SpillLocation.SpillOffset); + auto Deref = Indirect ? DIExpression::DerefAfter : 0; + DIExpr = TRI->prependOffsetExpression( + DIExpr, DIExpression::ApplyOffset | Deref, + Loc.SpillLocation.SpillOffset); Indirect = true; } else { SmallVector Ops; diff --git a/llvm/test/DebugInfo/MIR/X86/live-debug-values-restore.mir b/llvm/test/DebugInfo/MIR/X86/live-debug-values-restore.mir --- a/llvm/test/DebugInfo/MIR/X86/live-debug-values-restore.mir +++ b/llvm/test/DebugInfo/MIR/X86/live-debug-values-restore.mir @@ -641,7 +641,7 @@ # CHECK-LABEL: bb.0.entry: # CHECK: DBG_VALUE $rdi, 0, ![[TVAR]], !DIExpression() # CHECK-LABEL: bb.1.if.then: -# CHECK: DBG_VALUE $rsp, 0, ![[TVAR]], !DIExpression(DW_OP_constu, 8, DW_OP_minus) +# CHECK: DBG_VALUE $rsp, 0, ![[TVAR]], !DIExpression(DW_OP_constu, 8, DW_OP_minus, DW_OP_deref) # CHECK: INLINEASM # CHECK: DBG_VALUE ${{[a-zA-Z0-9]+}}, 0, ![[TVAR]], !DIExpression() # CHECK-LABEL: bb.2.if.end