[PATCH] D91424: [DebugInfo] Improve debug info accuracy for locals after inlining alloca uses [2/3]

Orlando Cazalet-Hyams via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 13 07:17:02 PST 2020


Orlando created this revision.
Orlando added reviewers: vsk, aprantl, dblaikie, rnk.
Orlando added projects: LLVM, debug-info.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya.
Orlando requested review of this revision.

See PR47946 <https://llvm.org/PR47946>.

Improve debug info accuracy for locals after inlining alloca uses by teaching
the inliner to run a localized LowerDbgDeclare over those uses.

We need to do this because InstCombine's LowerDbgDeclare marks variables backed
by an alloca as located in that alloca with a dbg.value+deref at call sites
using the alloca. These locations may be incorrect after inlining. For example,
it might become possible to eliminate some stores. It would be misleading to
use the alloca as the variable location after DSE has taken place because the
alloca location won't always hold the expected value. To counter this, we need
to track assignments to the caller's alloca-backed variables through the
inlined blocks, which we achieve with a localized LowerDbgDeclare.

Just as LowerDbgDeclare deletes the dbg.declare, InlineLowerDbgDeclare deletes
the dbg.value+deref as it's no longer always true that the variable lives on
the stack at this point. The example below illustrates why we must remove the
dbg.value+deref (marked XXX) after inlining. If we do not then we will emit
debug info saying that 'param' is located on the stack throughout the inlined
function and on line STEP, which isn't true due to DSE having removed the
redundant store 'param = 2'.

  int g;
  void escape(int*);
  __attribute__((__always_inline__))
  void no_deref(int* p) {
    if (p)
      g = 5;
  }
  int fun(int param) {
    param = 2;                   //< Store killed after inlining 'no_deref'.
  
    // XXX dbg.value(%param.alloca, "param", DW_OP_deref)
    no_deref(&param);
  
    volatile int step = 0;       //< STEP.
    param = 4;                   //< The killing store.
  
    escape(&param);
    return 0;
  }

debuginfo-test/dexter-test changes:
Added memvars/inlining-unused-param-dse.c
Added memvars/inlining-dse-alloca-survives.c
Added memvars/two-inlined-calls.c, currently XFAILS, addressed in next patch.
Fixed memvars/inlining-dse.c and remove XFAIL as this patch fixes the issue.

Testing:
No unexpected failures with 'ninja check-clang' and 'llvm-lit llvm/test'.
Added llvm/test/DebugInfo/Generic/inline-alloca-use.ll


https://reviews.llvm.org/D91424

Files:
  debuginfo-tests/dexter-tests/memvars/inlining-dse-alloca-survives.c
  debuginfo-tests/dexter-tests/memvars/inlining-dse.c
  debuginfo-tests/dexter-tests/memvars/inlining-unused-param-dse.c
  debuginfo-tests/dexter-tests/memvars/two-inlined-calls.c
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/include/llvm/Transforms/Utils/Local.h
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/lib/Transforms/Utils/Local.cpp
  llvm/test/DebugInfo/Generic/inline-alloca-use.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91424.305122.patch
Type: text/x-patch
Size: 27531 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201113/9408e073/attachment.bin>


More information about the llvm-commits mailing list