Issue 235239
Summary [SPARC] load feeding an i32 return without signext gets the return's debug location
Labels new issue
Assignees
Reporter shalseth
    On sparc64, a load that feeds an `i32` return without `signext`/`zeroext` comes out of instruction selection with the return's debug location instead of its own. If the load was the only instruction in a lexical block, the block and its variables are then dropped. rustc doesn't put `signext` on `i32` returns, and together with #46473 this is what makes rustc's `tests/debuginfo/opt/dead_refs.rs` lose its variables on sparc64.

blk-min.ll:

```llvm
target datalayout = "E-m:e-i64:64-i128:128-n32:64-S128"
target triple = "sparc64-unknown-linux-gnu"

define i32 @get(ptr %p) !dbg !10 {
  %q = getelementptr inbounds i8, ptr %p, i64 8, !dbg !20
    #dbg_value(ptr %q, !15, !DIExpression(), !20)
  %r = load i32, ptr %q, align 4, !dbg !21
  ret i32 %r, !dbg !22
}

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4}

!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "hand-written", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
!1 = !DIFile(filename: "blk.c", directory: "/tmp")
!3 = !{i32 7, !"Dwarf Version", i32 5}
!4 = !{i32 2, !"Debug Info Version", i32 3}
!5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
!6 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !5, size: 64)
!9 = !DISubroutineType(types: !{!5, !6})
!10 = distinct !DISubprogram(name: "get", scope: !1, file: !1, line: 3, type: !9, scopeLine: 4, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !{})
!14 = distinct !DILexicalBlock(scope: !10, file: !1, line: 6, column: 2)
!15 = !DILocalVariable(name: "q", scope: !14, file: !1, line: 7, type: !6)
!20 = !DILocation(line: 7, column: 8, scope: !14)
!21 = !DILocation(line: 8, column: 7, scope: !14)
!22 = !DILocation(line: 10, column: 2, scope: !10)
```

```
$ llc -O2 -print-after=sparc-isel blk-min.ll -o /dev/null 2>&1 | grep '= LD'
 %1:i64regs = LDri %0:i64regs, 8, debug-location !14 :: (load (s32) from %ir.q); blk.c:10:2
```

With `define signext i32 @get` it keeps its own location:

```
  %1:i64regs = LDSWri %0:i64regs, 8, debug-location !13 :: (load (s32) from %ir.q); blk.c:8:7
```

and so does x86_64 with the original IR:

```
  %1:gr32 = MOV32rm %0:gr64, 1, $noreg, 8, $noreg, debug-location !13 :: (load (s32) from %ir.q); blk.c:8:7
```

With `-disable-sparc-delay-filler`, to keep the delay slot issue (#46473) out of the picture, the sparc64 object has no DW_TAG_lexical_block, the x86_64 one has one.

Both are needed for the rustc test. With rustc's IR for `dead_refs.rs`, adding `signext` to `test_ref` alone or building with `-disable-sparc-delay-filler` alone still leaves `ref_v0`-`ref_v2` out of the DWARF. With both, they're back in their lexical blocks with locations covering the breakpoint.

In the DAG combiner debug output (llc built from main), the `any_extend` that the return lowering adds is folded into the load, and the new load gets the extend's location:

```
    t9: i64 = any_extend t7, blk.c:10:2
Replacing.1 t9: i64 = any_extend t7, blk.c:10:2
With: t13: i64,ch = load<(load (s32) from %ir.q), anyext from i32> t0, t4, poison:i64, blk.c:10:2
```

whereas in the `signext` case the folded `sextload` keeps `blk.c:8:7`. I've only looked at sparc64, so I don't know if other targets that extend `i32` return values see the same thing.

LLVM 23.1.4 and main, UltraSPARC T4-1, Linux sparc64.

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to