[PATCH] D49270: [InstCombine] Preserve debug value when simplifying cast-of-select

Vedant Kumar via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 13 15:08:21 PDT 2018


vsk added a comment.

In https://reviews.llvm.org/D49270#1161213, @lebedev.ri wrote:

> Judging by the pattern, i would almost guess every single transform in instcombine will need such a fix?
>  Can this be generalized somehow, fixing the outer place which actually applies replacements?


There are general debug info salvage calls in InstCombine already (added in r297994 and r318320). These are pretty effective. I've measured that they ~halve the number of debug values dropped in InstCombine during an -O2 build of sqlite3.

However, there is a long tail of bugs that don't have a neat general solution (well, at least not one I can see :).

Fundamentally, after a combine is successfully applied the use counts of some instructions may drop to zero. The question is: what should the debug users of these instructions point to? It wouldn't be conservatively correct to simply point them to the newly-created value. Consider the following contrived combine:

  %A = add %x, %x
  dbg.value(%A, "my_var_1")
  
  %B = mul %A, 2
  dbg.value(%B, "my_var_2")
  
  =>
  
  %B = mul %A, 4
  dbg.value(?, "my_var_1")
  dbg.value(%B, "my_var_2")

We don't want to emit `dbg.value(%B, "my_var_1")`, because that would associate the wrong value with the variable "my_var_1". The correct thing to do would be to emit something like `dbg.value(%B, "my_var_1", {DW_OP_lit2, DW_OP_div, DW_OP_stack_value})`.

While I think there's more yet to be done with applying salvageDebugInfo, I do think we'll need targeted solutions like this one in the long haul.


https://reviews.llvm.org/D49270





More information about the llvm-commits mailing list