xref: /llvm-project/llvm/test/DebugInfo/MIR/InstrRef/x86-fp-stackifier-drop-locations.mir (revision 92b33822e989884d29465d34769b07d78aeb1a84)
1# RUN: llc %s -run-pass=x86-codegen -o - -experimental-debug-variable-locations | FileCheck %s --implicit-check-not=debug-instr-number
2#
3# The x87 FP instructions below have debug instr numbers attached -- but the
4# operands get rewritten when it's converted to stack-form. Rather than trying
5# to recover from this, drop any instruction numbers.
6#
7## We shouldn't drop numbers from _every_ call though:
8# CHECK:  CALLpcrel32 @ext, csr_32, implicit $esp, implicit $ssp, implicit-def $esp, implicit-def $ssp, debug-instr-number 101,
9#
10# Original program, command line 'clang ./test.c -O2 -g -m32 -o out.o -c'
11#
12# long double ext();
13#
14# long double glob = 1.234;
15#
16# long double foo(long double a, long double b, long double c) {
17#   a += b;
18#   b += c;
19#   a *= ext();
20#   b /= ext();
21#   if (a < 5.0)
22#     a += glob;
23#   return a - b;
24# }
25#
26
27--- |
28  ; ModuleID = 'out.ll'
29  source_filename = "./test.c"
30  target datalayout = "e-m:e-p:32:32-p270:32:32-p271:32:32-p272:64:64-f64:32:64-f80:32-n8:16:32-S128"
31  target triple = "i386-unknown-linux-gnu"
32
33  @glob = dso_local local_unnamed_addr global x86_fp80 0xK3FFF9DF3B645A1CAC000, align 4, !dbg !0
34
35  ; Function Attrs: nounwind
36  define dso_local x86_fp80 @foo(x86_fp80 %a, x86_fp80 %b, x86_fp80 %c) local_unnamed_addr !dbg !13 {
37  entry:
38    call void @llvm.dbg.value(metadata x86_fp80 %a, metadata !17, metadata !DIExpression()), !dbg !20
39    call void @llvm.dbg.value(metadata x86_fp80 %b, metadata !18, metadata !DIExpression()), !dbg !20
40    call void @llvm.dbg.value(metadata x86_fp80 %c, metadata !19, metadata !DIExpression()), !dbg !20
41    %add = fadd x86_fp80 %a, %b, !dbg !21
42    call void @llvm.dbg.value(metadata x86_fp80 %add, metadata !17, metadata !DIExpression()), !dbg !20
43    call void @llvm.dbg.value(metadata x86_fp80 undef, metadata !18, metadata !DIExpression()), !dbg !20
44    %call = tail call x86_fp80 @ext() #3, !dbg !22
45    %mul = fmul x86_fp80 %add, %call, !dbg !23
46    call void @llvm.dbg.value(metadata x86_fp80 %mul, metadata !17, metadata !DIExpression()), !dbg !20
47    %call2 = tail call x86_fp80 @ext() #3, !dbg !24
48    call void @llvm.dbg.value(metadata x86_fp80 undef, metadata !18, metadata !DIExpression()), !dbg !20
49    %cmp = fcmp olt x86_fp80 %mul, 0xK4001A000000000000000, !dbg !25
50    %0 = load x86_fp80, ptr @glob, align 4, !dbg !27
51    %add3 = fadd x86_fp80 %mul, %0, !dbg !27
52    %a.addr.0 = select i1 %cmp, x86_fp80 %add3, x86_fp80 %mul, !dbg !27
53    %add1 = fadd x86_fp80 %b, %c, !dbg !28
54    call void @llvm.dbg.value(metadata x86_fp80 %add1, metadata !18, metadata !DIExpression()), !dbg !20
55    %div = fdiv x86_fp80 %add1, %call2, !dbg !29
56    call void @llvm.dbg.value(metadata x86_fp80 %div, metadata !18, metadata !DIExpression()), !dbg !20
57    call void @llvm.dbg.value(metadata x86_fp80 %a.addr.0, metadata !17, metadata !DIExpression()), !dbg !20
58    %sub = fsub x86_fp80 %a.addr.0, %div, !dbg !30
59    ret x86_fp80 %sub, !dbg !31
60  }
61
62  declare dso_local x86_fp80 @ext(...) local_unnamed_addr
63
64  ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
65  declare void @llvm.dbg.value(metadata, metadata, metadata)
66
67  !llvm.dbg.cu = !{!2}
68  !llvm.module.flags = !{!8, !9, !10, !11}
69  !llvm.ident = !{!12}
70
71  !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
72  !1 = distinct !DIGlobalVariable(name: "glob", scope: !2, file: !6, line: 3, type: !7, isLocal: false, isDefinition: true)
73  !2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5, splitDebugInlining: false, nameTableKind: None)
74  !3 = !DIFile(filename: "test.c", directory: "/fast/fs/build34llvm4")
75  !4 = !{}
76  !5 = !{!0}
77  !6 = !DIFile(filename: "./test.c", directory: ".")
78  !7 = !DIBasicType(name: "long double", size: 96, encoding: DW_ATE_float)
79  !8 = !{i32 1, !"NumRegisterParameters", i32 0}
80  !9 = !{i32 7, !"Dwarf Version", i32 4}
81  !10 = !{i32 2, !"Debug Info Version", i32 3}
82  !11 = !{i32 1, !"wchar_size", i32 4}
83  !12 = !{!"clang"}
84  !13 = distinct !DISubprogram(name: "foo", scope: !6, file: !6, line: 5, type: !14, scopeLine: 5, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !16)
85  !14 = !DISubroutineType(types: !15)
86  !15 = !{!7, !7, !7, !7}
87  !16 = !{!17, !18, !19}
88  !17 = !DILocalVariable(name: "a", arg: 1, scope: !13, file: !6, line: 5, type: !7)
89  !18 = !DILocalVariable(name: "b", arg: 2, scope: !13, file: !6, line: 5, type: !7)
90  !19 = !DILocalVariable(name: "c", arg: 3, scope: !13, file: !6, line: 5, type: !7)
91  !20 = !DILocation(line: 0, scope: !13)
92  !21 = !DILocation(line: 6, column: 5, scope: !13)
93  !22 = !DILocation(line: 8, column: 8, scope: !13)
94  !23 = !DILocation(line: 8, column: 5, scope: !13)
95  !24 = !DILocation(line: 9, column: 8, scope: !13)
96  !25 = !DILocation(line: 10, column: 9, scope: !26)
97  !26 = distinct !DILexicalBlock(scope: !13, file: !6, line: 10, column: 7)
98  !27 = !DILocation(line: 10, column: 7, scope: !13)
99  !28 = !DILocation(line: 7, column: 5, scope: !13)
100  !29 = !DILocation(line: 9, column: 5, scope: !13)
101  !30 = !DILocation(line: 12, column: 12, scope: !13)
102  !31 = !DILocation(line: 12, column: 3, scope: !13)
103
104...
105---
106name:            foo
107alignment:       16
108tracksRegLiveness: true
109debugInstrRef: true
110frameInfo:
111  hasCalls:        true
112fixedStack:
113  - { id: 0, type: default, offset: 24, size: 10, alignment: 8, stack-id: default,
114      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
115      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
116  - { id: 1, type: default, offset: 12, size: 10, alignment: 4, stack-id: default,
117      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
118      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
119  - { id: 2, type: default, offset: 0, size: 10, alignment: 16, stack-id: default,
120      isImmutable: true, isAliased: false, callee-saved-register: '', callee-saved-restored: true,
121      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
122stack:
123  - { id: 0, name: '', type: spill-slot, offset: 0, size: 10, alignment: 4,
124      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
125      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
126  - { id: 1, name: '', type: spill-slot, offset: 0, size: 10, alignment: 4,
127      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
128      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
129  - { id: 2, name: '', type: spill-slot, offset: 0, size: 10, alignment: 4,
130      stack-id: default, callee-saved-register: '', callee-saved-restored: true,
131      debug-info-variable: '', debug-info-expression: '', debug-info-location: '' }
132callSites:       []
133debugValueSubstitutions: []
134constants:
135  - id:              0
136    value:           'float 5.000000e+00'
137    alignment:       4
138    isTargetSpecific: false
139machineFunctionInfo: {}
140body:             |
141  bb.0.entry:
142    renamable $fp0 = nofpexcept LD_Fp80m %fixed-stack.0, 1, $noreg, 0, $noreg, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 1 :: (load (s80) from %fixed-stack.0, align 8)
143    ST_FpP80m %stack.0, 1, $noreg, 0, $noreg, killed renamable $fp0, implicit-def $fpsw, implicit $fpcw, debug-instr-number 2 :: (store (s80) into %stack.0, align 4)
144    renamable $fp1 = nofpexcept LD_Fp80m %fixed-stack.1, 1, $noreg, 0, $noreg, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 3 :: (load (s80) from %fixed-stack.1, align 4)
145    ST_FpP80m %stack.1, 1, $noreg, 0, $noreg, renamable $fp1, implicit-def $fpsw, implicit $fpcw, debug-instr-number 4 :: (store (s80) into %stack.1, align 4)
146    renamable $fp0 = nofpexcept LD_Fp80m %fixed-stack.2, 1, $noreg, 0, $noreg, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 5 :: (load (s80) from %fixed-stack.2, align 16)
147    renamable $fp0 = nofpexcept ADD_Fp80 killed renamable $fp0, killed renamable $fp1, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 6, debug-location !21
148    ST_FpP80m %stack.2, 1, $noreg, 0, $noreg, killed renamable $fp0, implicit-def $fpsw, implicit $fpcw, debug-instr-number 7 :: (store (s80) into %stack.2, align 4)
149    ADJCALLSTACKDOWN32 0, 0, 0, implicit-def dead $esp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $esp, implicit $ssp, debug-location !22
150
151    ; This identical call (to the one below) does not touch the FP registers at
152    ; all. Therefore, it shouldn't have any debug instructions dropped.
153    CALLpcrel32 @ext, csr_32, implicit $esp, implicit $ssp, implicit-def $esp, implicit-def $ssp, debug-instr-number 101, debug-location !22
154
155    ; Original call: this should have it's location dropped, as it touches the
156    ; FP stack.
157    CALLpcrel32 @ext, csr_32, implicit $esp, implicit $ssp, implicit-def $esp, implicit-def $ssp, implicit-def $fp0, debug-instr-number 100, debug-location !22
158
159
160    ADJCALLSTACKUP32 0, 0, implicit-def dead $esp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $esp, implicit $ssp, debug-location !22
161    renamable $fp1 = LD_Fp80m %stack.2, 1, $noreg, 0, $noreg, implicit-def $fpsw, implicit $fpcw :: (load (s80) from %stack.2, align 4)
162    renamable $fp0 = nofpexcept MUL_Fp80 killed renamable $fp1, killed renamable $fp0, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 8, debug-location !23
163    ST_FpP80m %stack.2, 1, $noreg, 0, $noreg, killed renamable $fp0, implicit-def $fpsw, implicit $fpcw, debug-instr-number 9 :: (store (s80) into %stack.2, align 4)
164    ADJCALLSTACKDOWN32 0, 0, 0, implicit-def dead $esp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $esp, implicit $ssp, debug-location !24
165    CALLpcrel32 @ext, csr_32, implicit $esp, implicit $ssp, implicit-def $esp, implicit-def $ssp, implicit-def $fp0, debug-location !24
166    ADJCALLSTACKUP32 0, 0, implicit-def dead $esp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $esp, implicit $ssp, debug-location !24
167    renamable $fp1 = nofpexcept LD_Fp32m80 $noreg, 1, $noreg, %const.0, $noreg, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 10 :: (load (s32) from constant-pool)
168    renamable $fp2 = LD_Fp80m %stack.2, 1, $noreg, 0, $noreg, implicit-def $fpsw, implicit $fpcw, debug-instr-number 11 :: (load (s80) from %stack.2, align 4)
169    nofpexcept UCOM_FpIr80 killed renamable $fp1, renamable $fp2, implicit-def $eflags, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 12, debug-location !25
170    renamable $fp1 = nofpexcept LD_Fp80m $noreg, 1, $noreg, @glob, $noreg, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 13, debug-location !27 :: (dereferenceable load (s80) from @glob, align 4)
171    renamable $fp1 = nofpexcept ADD_Fp80 renamable $fp2, killed renamable $fp1, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 14, debug-location !27
172    renamable $fp2 = CMOVNBE_Fp80 killed renamable $fp2, killed renamable $fp1, implicit-def dead $fpsw, implicit killed $eflags, debug-instr-number 15, debug-location !27
173    renamable $fp3 = COPY killed renamable $fp2
174    renamable $fp1 = LD_Fp80m %stack.0, 1, $noreg, 0, $noreg, implicit-def $fpsw, implicit $fpcw, debug-instr-number 16 :: (load (s80) from %stack.0, align 4)
175    renamable $fp2 = LD_Fp80m %stack.1, 1, $noreg, 0, $noreg, implicit-def $fpsw, implicit $fpcw, debug-instr-number 17 :: (load (s80) from %stack.1, align 4)
176    renamable $fp1 = nofpexcept ADD_Fp80 killed renamable $fp2, killed renamable $fp1, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 18, debug-location !28
177    renamable $fp0 = nofpexcept DIV_Fp80 killed renamable $fp1, killed renamable $fp0, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 19, debug-location !29
178    renamable $fp0 = nofpexcept SUB_Fp80 killed renamable $fp3, killed renamable $fp0, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 20, debug-location !30
179    ;; Edited in:
180    renamable $fp0 = ADD_Fp64m killed renamable $fp0, killed $esp, 1, $noreg, 0, $noreg, implicit-def dead $fpsw, implicit $fpcw, debug-instr-number 21,  :: (load (s64) from `ptr undef`)
181    RET 0, killed renamable $fp0, debug-location !31
182
183...
184