[PATCH] D36596: [InstCombine] Don't convert all dbg.declares to dbg.values

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 14 09:48:48 PDT 2017


rnk added a comment.

Long term, yes, I think we'll want to push the lifetime intrinsics down to MI so we can get better PC ranges for variable locations. I don't know when they are removed right now.

Trying to think more broadly, here's how things work today:

- In the C abstract machine, variables live in memory. LLVM's job is to erode that abstraction.
- dbg.declare says simply "this variable lives here in memory, its value changes whenever it is stored to"
- Any pass that deletes dead stores (or more generally dead memset/memcpy/writes) will cause the user to see a stale value in the debugger from a missed write
- dbg.value gives us a way to describe dead stores in debug info

The problem is that we can't mix dbg.value and dbg.declare. For variables that we can promote to SSA, we can describe all the stores with dbg.value, and that's good enough. It sounds like we have problems for values that are spilled from registers, but that's a QoI issue that doesn't require redesign.

For everything else, we need a way of describing the effects of more powerful optimizations like GVN, DSE, and memcpyopt. We need a way to say, "this variable usually lives in memory, but I deleted the store at .Ltmp1 because it was made dead by the store at .Ltmp2. The value at .Ltmp1 is 42, and at .Ltmp2 it is whatever is in memory." I'm starting to think we should basically use dbg.value with DW_OP_deref as a way to say "at this program point, the variable lives in memory". If that works, we could probably eliminate dbg.declare in favor of dbg.value+DW_OP_deref.  Most store-eliminating optimizations know exactly what makes the store dead (free, lifetime.end, memset, or plain store), so they know where to insert the dbg.value+DW_OP_deref to put the variable back in memory.



================
Comment at: llvm/lib/Transforms/InstCombine/InstructionCombining.cpp:2061
-          case Intrinsic::dbg_declare:
-          case Intrinsic::dbg_value:
           case Intrinsic::invariant_start:
----------------
aprantl wrote:
> What's the effect of this change?
Now that we have `ValueAsMetadata`, these no longer appear in use lists. These case labels are just stale. I'll just commit this separately.


https://reviews.llvm.org/D36596





More information about the llvm-commits mailing list