Issue 71052
Summary Call site info: Missing DW_AT_call_value opportunity - spilled value stack slot not used
Labels new issue
Assignees
Reporter OCHyams
    clang version 18.0.0 (bc41b0a)
Target: x86_64-unknown-linux-gnu

There is no `DW_AT_call_site_parameter` entry for the call to `f1` in this reproducer:
```
float f1(float p1);
float fun(float *f) {
  float v = *f;
  return f1(v) + v;
}
```
```
$ clang -O2 -g -c test.cpp -o - | llvm-dwarfdump - --name=fun --show-children
-:	file format elf64-x86-64

0x00000027: DW_TAG_subprogram
              DW_AT_name	("fun")
 ...

0x00000037:   DW_TAG_formal_parameter
 ...

0x00000040:   DW_TAG_variable
 ...

0x00000049:   DW_TAG_call_site
 DW_AT_call_origin	(0x00000050)
 DW_AT_call_return_pc	(0x0000000000000010)

0x0000004f: NULL
```
```
$ clang -O2 -g -c test.cpp -o - | llvm-objdump -d -
Disassembly of section .text:

0000000000000000 <_Z3funPf>:
 0: 50                           pushq %rax
       1: f3 0f 10 07 movss (%rdi), %xmm0           # xmm0 = mem[0],zero,zero,zero
 5: f3 0f 11 44 24 04            movss %xmm0, 0x4(%rsp)        # spill xmm0
       b: e8 00 00 00 00               callq 0x10 <_Z3funPf+0x10>
 10: f3 0f 58 44 24 04            addss 0x4(%rsp), %xmm0
      16: 58 popq  %rax
      17: c3 retq
```

It looks like currently only loads and copies are interpreted to build `DW_AT_call_value` expressions.

If a parameter register value has been spilled to the stack before the call, I believe we should be able to use the spilled value in the `DW_AT_call_value` _expression_.

I think we should/could have a `DW_AT_call_site_parameter` DIE like this for this reproducer:
```
DW_TAG_call_site_parameter
 DW_AT_location   (DW_OP_reg<XMM0>)
   DW_AT_call_value (DW_OP_breg<RSP>+4, DW_OP_deref_size, 0x4)
```

Here's the optimized IR to reproduce the issue with `llc`:
```
; ModuleID = 'test.cpp'
source_filename = "test.cpp"
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"

; Function Attrs: mustprogress uwtable
define dso_local noundef float @_Z3funPf(ptr nocapture noundef readonly %f) local_unnamed_addr #0 !dbg !10 {
entry:
  call void @llvm.dbg.value(metadata ptr %f, metadata !16, metadata !DIExpression()), !dbg !18
  %0 = load float, ptr %f, align 4, !dbg !19, !tbaa !20
  call void @llvm.dbg.value(metadata float %0, metadata !17, metadata !DIExpression()), !dbg !18
  %call = tail call noundef float @_Z2f1f(float noundef %0), !dbg !24
  %add = fadd float %0, %call, !dbg !25
  ret float %add, !dbg !26
}

declare !dbg !27 noundef float @_Z2f1f(float noundef) local_unnamed_addr #1

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare void @llvm.dbg.value(metadata, metadata, metadata) #2

attributes #0 = { mustprogress uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #1 = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" }
attributes #2 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }

!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
!llvm.ident = !{!9}

!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 18.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
!1 = !DIFile(filename: "test.cpp", directory: "/")
!2 = !{i32 7, !"Dwarf Version", i32 5}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 1, !"wchar_size", i32 4}
!5 = !{i32 8, !"PIC Level", i32 2}
!6 = !{i32 7, !"PIE Level", i32 2}
!7 = !{i32 7, !"uwtable", i32 2}
!8 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
!9 = !{!"clang version 18.0.0"}
!10 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funPf", scope: !1, file: !1, line: 2, type: !11, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !15)
!11 = !DISubroutineType(types: !12)
!12 = !{!13, !14}
!13 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
!14 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !13, size: 64)
!15 = !{!16, !17}
!16 = !DILocalVariable(name: "f", arg: 1, scope: !10, file: !1, line: 2, type: !14)
!17 = !DILocalVariable(name: "v", scope: !10, file: !1, line: 3, type: !13)
!18 = !DILocation(line: 0, scope: !10)
!19 = !DILocation(line: 3, column: 13, scope: !10)
!20 = !{!21, !21, i64 0}
!21 = !{!"float", !22, i64 0}
!22 = !{!"omnipotent char", !23, i64 0}
!23 = !{!"Simple C++ TBAA"}
!24 = !DILocation(line: 4, column: 10, scope: !10)
!25 = !DILocation(line: 4, column: 16, scope: !10)
!26 = !DILocation(line: 4, column: 3, scope: !10)
!27 = !DISubprogram(name: "f1", linkageName: "_Z2f1f", scope: !1, file: !1, line: 1, type: !28, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
!28 = !DISubroutineType(types: !29)
!29 = !{!13, !13}
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to