xref: /llvm-project/llvm/test/DebugInfo/X86/spill-nospill.ll (revision d53425e2a33a0ff7336c86d3f668b1855c47a6de)
1; RUN: llc < %s -experimental-debug-variable-locations=true | FileCheck %s
2; RUN: llc < %s -filetype=obj -experimental-debug-variable-locations=true | llvm-dwarfdump - | FileCheck %s --check-prefix=DWARF
3
4; This test creates two UserValues in LiveDebugVariables with one location
5; each. x must be spilled, but y will be allocated to a CSR. x's location
6; should be indirect, but y's should be direct.
7
8; C source:
9; #define FORCE_SPILL() \
10;   __asm volatile("" : : : \
11;                    "rax", "rbx", "rcx", "rdx", "rsi", "rdi", "rbp", "r8", \
12;                    "r9", "r10", "r11", "r12", "r13", "r14", "r15")
13; int g(int);
14; int f() {
15;   int x = g(0);
16;   FORCE_SPILL();
17;   int y = g(0);
18;   g(y);
19;   g(y);
20;   g(y);
21;   return x + y;
22; }
23
24; CHECK-LABEL: f: # @f
25; CHECK: callq   g
26; CHECK: movl    %eax, [[X_OFFS:[0-9]+]](%rsp)          # 4-byte Spill
27; CHECK: #DEBUG_VALUE: f:x <- [DW_OP_plus_uconst [[X_OFFS]], DW_OP_deref] $rsp
28; CHECK: #APP
29; CHECK: #NO_APP
30; CHECK: callq   g
31; CHECK: movl    %eax, %[[CSR:[^ ]*]]
32; CHECK: #DEBUG_VALUE: f:y <- $esi
33; CHECK: movl    %eax, %ecx
34; CHECK: callq   g
35; CHECK: movl    %[[CSR]], %ecx
36; CHECK: callq   g
37; CHECK: movl    %[[CSR]], %ecx
38; CHECK: callq   g
39; CHECK: movl    [[X_OFFS]](%rsp), %eax          # 4-byte Reload
40;; Variable value remains on stack, location left pointing there.
41; CHECK: addl    %[[CSR]], %eax
42
43; DWARF:      DW_TAG_variable
44; DWARF-NEXT:   DW_AT_location        (
45; DWARF-NEXT:      [{{.*}}, {{.*}}): DW_OP_breg7 RSP+36)
46; DWARF-NEXT:   DW_AT_name    ("x")
47
48; DWARF:      DW_TAG_variable
49; DWARF-NEXT:   DW_AT_location        (
50; DWARF-NEXT:      [{{.*}},  {{.*}}): DW_OP_reg4 RSI)
51; DWARF-NEXT:   DW_AT_name    ("y")
52
53; ModuleID = 'spill-nospill.c'
54source_filename = "spill-nospill.c"
55target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
56target triple = "x86_64-pc-windows-msvc19.0.24215"
57
58; Function Attrs: nounwind uwtable
59define i32 @f() local_unnamed_addr #0 !dbg !8 {
60entry:
61  %call = tail call i32 @g(i32 0) #3, !dbg !15
62  tail call void @llvm.dbg.value(metadata i32 %call, metadata !13, metadata !DIExpression()), !dbg !16
63  tail call void asm sideeffect "", "~{rax},~{rbx},~{rcx},~{rdx},~{rsi},~{rdi},~{rbp},~{r8},~{r9},~{r10},~{r11},~{r12},~{r13},~{r14},~{r15},~{dirflag},~{fpsr},~{flags}"() #3, !dbg !17, !srcloc !18
64  %call1 = tail call i32 @g(i32 0) #3, !dbg !19
65  tail call void @llvm.dbg.value(metadata i32 %call1, metadata !14, metadata !DIExpression()), !dbg !20
66  %call2 = tail call i32 @g(i32 %call1) #3, !dbg !21
67  %call3 = tail call i32 @g(i32 %call1) #3, !dbg !22
68  %call4 = tail call i32 @g(i32 %call1) #3, !dbg !23
69  %add = add nsw i32 %call1, %call, !dbg !24
70  ret i32 %add, !dbg !25
71}
72
73declare i32 @g(i32) local_unnamed_addr #1
74
75; Function Attrs: nounwind readnone speculatable
76declare void @llvm.dbg.value(metadata, metadata, metadata) #2
77
78attributes #0 = { nounwind uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
79attributes #1 = { "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2,+x87" "unsafe-fp-math"="false" "use-soft-float"="false" }
80attributes #2 = { nounwind readnone speculatable }
81attributes #3 = { nounwind }
82
83!llvm.dbg.cu = !{!0}
84!llvm.module.flags = !{!3, !4, !5, !6}
85!llvm.ident = !{!7}
86
87!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 6.0.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2)
88!1 = !DIFile(filename: "spill-nospill.c", directory: "C:\5Csrc\5Cllvm-project\5Cbuild")
89!2 = !{}
90!3 = !{i32 2, !"Dwarf Version", i32 4}
91!4 = !{i32 2, !"Debug Info Version", i32 3}
92!5 = !{i32 1, !"wchar_size", i32 2}
93!6 = !{i32 7, !"PIC Level", i32 2}
94!7 = !{!"clang version 6.0.0 "}
95!8 = distinct !DISubprogram(name: "f", scope: !1, file: !1, line: 8, type: !9, isLocal: false, isDefinition: true, scopeLine: 8, isOptimized: true, unit: !0, retainedNodes: !12)
96!9 = !DISubroutineType(types: !10)
97!10 = !{!11}
98!11 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
99!12 = !{!13, !14}
100!13 = !DILocalVariable(name: "x", scope: !8, file: !1, line: 9, type: !11)
101!14 = !DILocalVariable(name: "y", scope: !8, file: !1, line: 11, type: !11)
102!15 = !DILocation(line: 9, column: 11, scope: !8)
103!16 = !DILocation(line: 9, column: 7, scope: !8)
104!17 = !DILocation(line: 10, column: 3, scope: !8)
105!18 = !{i32 -2147472112}
106!19 = !DILocation(line: 11, column: 11, scope: !8)
107!20 = !DILocation(line: 11, column: 7, scope: !8)
108!21 = !DILocation(line: 12, column: 3, scope: !8)
109!22 = !DILocation(line: 13, column: 3, scope: !8)
110!23 = !DILocation(line: 14, column: 3, scope: !8)
111!24 = !DILocation(line: 15, column: 12, scope: !8)
112!25 = !DILocation(line: 15, column: 3, scope: !8)
113