Files
Shubham Sandeep Rastogi c6b245f168 [SelectionDAG] Reland debuginfo salvage for load/ext combines (#194700)
This relands fe5d5b762a, which salvages
debug info when folding load and zext/sext patterns in SelectionDAG.

Salvage debuginfo when combining load and z|s ext instrs.

SelectionDAG uses the DAGCombiner to fold a load followed by a sext to a
load and sext instruction. For example, in x86 we will see that

```
%1 = load i32, ptr @GlobArr
    #dbg_value(i32 %1, !43, !DIExpression(), !52)
%2 = sext i32 %1 to i64, !dbg !53
```

is converted to:

```
%0:gr64_nosp = MOVSX64rm32 $rip, 1, $noreg, @GlobArr, $noreg, debug-instr-number 1, debug-location !51
DBG_VALUE $noreg, $noreg, !"Idx", !DIExpression(), debug-location !52
```

The `DBG_VALUE` needs to be transferred correctly to the new combined
instruction, and it needs to be appended with a `DIExpression` which
contains a `DW_OP_LLVM_convert` expression, which correctly casts the
value in the virtual register to the correct size.

This patch fixes the above described problem.

The patch also accounts for multiple DW_OP_LLVM_arg's in a DIExpression
which had caused it to break tests on the sanitizer-x86_64-linux bot but
has now been fixed, with an added testcase called
selectionDAG-load-zext-multiple-args.ll which was reduced from the
broken test itself.

fe5d5b762a exposed a crash in
tryToFoldExtOfLoad(), which is described in
https://github.com/llvm/llvm-project/issues/193475

Fix that by replacing the folded node before deleting or rewriting the
old nodes, and by transferring debug values before entering the
replacement path.

Add an X86 regression test for the extload combine crash.
2026-04-30 00:45:29 -07:00
..