From 536b9eb31e9333bcee3d20d694f7cb12d1ff3d89 Mon Sep 17 00:00:00 2001 From: Jeremy Morse Date: Thu, 25 Nov 2021 21:41:55 +0000 Subject: [PATCH] [DebugInfo][InstrRef] Add extra indirection for NRVO tests In some scenarios, usually involving NRVO, we can issue indirect DBG_VALUEs after SelectionDAG, even in instruction referencing mode (if the variable is an argument). If the corresponding argument value is spilt to the stack, then we have: * Indirection from it being on the stack, * Indirection from it being a dbg.declare or a dbg.addr. However InstrRefBasedLDV only emits one level of indirection. This patch adds the second, by adding an extra DW_OP_deref if necessary. The two tests modified fail otherwise -- they feature some NRVO, and require two levels of indirection to be correct. Differential Revision: https://reviews.llvm.org/D114364 --- llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp | 9 +++++++++ llvm/test/DebugInfo/X86/spill-indirect-nrvo.ll | 2 ++ llvm/test/DebugInfo/X86/spill-nontrivial-param.ll | 1 + 3 files changed, 12 insertions(+) diff --git a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp index eff8ec7..5b488d8 100644 --- a/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp +++ b/llvm/lib/CodeGen/LiveDebugValues/InstrRefBasedImpl.cpp @@ -836,6 +836,15 @@ MachineInstrBuilder MLocTracker::emitLoc(Optional MLoc, unsigned Base = Spill.SpillBase; MIB.addReg(Base); MIB.addImm(0); + + // Being on the stack makes this location indirect; if it was _already_ + // indirect though, we need to add extra indirection. See this test for + // a scenario where this happens: + // llvm/test/DebugInfo/X86/spill-nontrivial-param.ll + if (Properties.Indirect) { + std::vector Elts = {dwarf::DW_OP_deref}; + Expr = DIExpression::append(Expr, Elts); + } } else { // This is a stack location with a weird subregister offset: emit an undef // DBG_VALUE instead. diff --git a/llvm/test/DebugInfo/X86/spill-indirect-nrvo.ll b/llvm/test/DebugInfo/X86/spill-indirect-nrvo.ll index f47e6dc..a920f31 100644 --- a/llvm/test/DebugInfo/X86/spill-indirect-nrvo.ll +++ b/llvm/test/DebugInfo/X86/spill-indirect-nrvo.ll @@ -1,5 +1,7 @@ ; RUN: llc < %s -experimental-debug-variable-locations=false | FileCheck -check-prefixes=CHECK,OPT %s ; RUN: llc -O0 < %s -experimental-debug-variable-locations=false | FileCheck -check-prefixes=CHECK,OPTNONE %s +; RUN: llc < %s -experimental-debug-variable-locations=true | FileCheck -check-prefixes=CHECK,OPT %s +; RUN: llc -O0 < %s -experimental-debug-variable-locations=true | FileCheck -check-prefixes=CHECK,OPTNONE %s ; Make sure we insert DW_OP_deref when spilling indirect DBG_VALUE instructions. diff --git a/llvm/test/DebugInfo/X86/spill-nontrivial-param.ll b/llvm/test/DebugInfo/X86/spill-nontrivial-param.ll index 3dddb62..f6c0cb2 100644 --- a/llvm/test/DebugInfo/X86/spill-nontrivial-param.ll +++ b/llvm/test/DebugInfo/X86/spill-nontrivial-param.ll @@ -1,4 +1,5 @@ ; RUN: llc < %s -experimental-debug-variable-locations=false | FileCheck %s +; RUN: llc < %s -experimental-debug-variable-locations=true | FileCheck %s ; Make sure we insert DW_OP_deref when spilling indirect DBG_VALUE instructions. ; In this example, 'nt' is passed by address because it is not trivially -- 2.7.4