[PATCH] D85555: [InstCombine] Remove dbg.values describing contents of dead allocas

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 7 14:15:31 PDT 2020


vsk created this revision.
vsk added reviewers: aprantl, rnk.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
vsk requested review of this revision.

When InstCombine removes an alloca, it erases the dbg.{addr,declare}
instructions which refer to the alloca. It would be better to instead
remove all debug intrinsics which describe the contents of the dead
alloca, namely all `dbg.value(<dead alloca>, ..., DW_OP_deref)`'s.

This effectively undoes work performed in an InstCombine run earlier in
the pipeline by LowerDbgDeclare, which inserts DW_OP_deref dbg.values
before CallInst users of an alloca. The motivating example looks like:

   define void @foo(i32 %0) {
     %a = alloca i32              ; This alloca is erased.
     store i32 %0, i32* %a
     dbg.value(i32 %0, "arg0")    ; This dbg.value survives.
     dbg.value(i32* %a, "arg0", DW_OP_deref)
     call void @trivially_inlinable_no_op(i32* %a)
     ret void
  }

If the DW_OP_deref dbg.value is not erased, it becomes dbg.value(undef)
after inlining, making "arg0" unavailable. But we already have dbg.value
descriptions of the alloca's value (from LowerDbgDeclare), so the
DW_OP_deref dbg.value cannot serve its purpose of describing an
initialization of the alloca by some callee. It invalidates other useful
dbg.values for no reason, so it should be deleted.

OTOH, it wouldn't be correct to delete all dbg.value descriptions of an
alloca. Note that it's possible to describe a variable that takes on
different pointer values, e.g.:

   void use(int *);
   void t(int a, int b) {
     int *local = &a;     // dbg.value(i32* %a.addr, "local")
     local = &b;          // dbg.value(i32* undef, "local")
     use(&a);             //           (note: %b.addr is optimized out)
     local = &a;          // dbg.value(i32* %a.addr, "local")
  }

In this example, the alloca for "b" is erased, but we need to describe
the value of "local" as <unavailable> before the call to "use". This
prevents "local" from appearing to be equal to "&a" at the callsite.

rdar://66592859


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D85555

Files:
  llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
  llvm/test/Transforms/InstCombine/erase-dbg-values-at-dead-alloc-site.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85555.284054.patch
Type: text/x-patch
Size: 8400 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200807/597b952b/attachment.bin>


More information about the llvm-commits mailing list