[PATCH] D110332: [DebugInfo] Limit the size of DIExpressions that we will salvage up to

David Blaikie via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 27 18:49:43 PDT 2021


dblaikie added a comment.

In D110332#3018752 <https://reviews.llvm.org/D110332#3018752>, @StephenTozer wrote:

> In D110332#3018654 <https://reviews.llvm.org/D110332#3018654>, @dblaikie wrote:
>
>> (would need test coverage - which might help answer my main question: What sort of large expressions are observed in practice? Could they be simplified, rather than dropped? (I think it's probably still right/good to have a limit, but if hitting the limit is often reflective of some suboptimal representational choice in how the dwarf expression is formed, that could be optimized down to something more compact - that's something to be aware of/keep an eye on probably))
>
> In the bug above, the limit is hit due to this loop:
>
>   for (*f = 4; *f <= 33; *f += 1)
>     for (b = -27; b <= 48; b++) {
>       int16_t g;
>       int32_t *i = e;
>       (c -= 10) % (g = c ^= i != 0);
>       a &= b;
>     }
>
> This loop is ultimately unrolled and optimized into a chain of ~4000 add and xor instructions, for which every xor has an associated debug value:
>
>   %sub.29.5 = add nsw i32 %xor.29.4, -10, !dbg !51
>   %xor.29.5 = xor i32 %sub.29.5, 1, !dbg !52
>   call void @llvm.dbg.value(metadata i32 %xor.29.5, metadata !31, metadata !DIExpression(DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_LLVM_convert, 16, DW_ATE_unsigned, DW_OP_stack_value)), !dbg !50
>   %sub.29.6 = add nsw i32 %xor.29.5, -10, !dbg !51
>   %xor.29.6 = xor i32 %sub.29.6, 1, !dbg !52
>   call void @llvm.dbg.value(metadata i32 %xor.29.6, metadata !31, metadata !DIExpression(DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_LLVM_convert, 16, DW_ATE_unsigned, DW_OP_stack_value)), !dbg !5
>   etc...
>
> InstCombine shuffles these instructions around, and due to the way that we handle lost debug values this results in us trying to salvage back down this chain of instructions. This is what we would actually want to do in a lot of real cases, it just happens that in this case there is a prohibitive number of instructions we would have to salvage through in order to recover the debug value. I would definitely be in favour of implementing const-folding in expressions as a means of preventing us from hitting the limit, but it doesn't seem possible in this case.
>
> For what it's worth , in this specific case the salvaged dbg.values //are// also useless since they form into a huge consecutive block with no instructions in-between - but 1) I think the IR could be modified such that this wasn't the case for at least some of the intrinsics, and 2) without making a much larger change to InstCombine, I don't think we can know that the intrinsics will be useless before we've finished the salvaging.

Fair enough - thanks for bearing with me!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D110332/new/

https://reviews.llvm.org/D110332



More information about the llvm-commits mailing list