xref: /llvm-project/llvm/test/DebugInfo/MIR/InstrRef/stack-coloring-dbg-phi.mir (revision 7564566779eb07e9daf41a351b09cf7607871845)
1# RUN: llc %s -o - -start-before=phi-node-elimination \
2# RUN:     -stop-after=stack-slot-coloring -simplify-mir \
3# RUN:     -experimental-debug-variable-locations=true \
4# RUN: | FileCheck %s --check-prefix=DBGPHIS
5#
6# Test that DBG_PHI instructions do not add "weight" to stack slots and cause
7# their coalescing / coloring to change. This is hard to trigger, because it's
8# closely coupled with the register allocator. Thus, the test is very
9# complicated and hard to reduce.
10#
11# Future register allocator changes might change the slot; in that case, just
12# update the slot number, so long as it's the same between each RUN.
13#
14# DBGPHIS: DBG_PHI %stack.4,
15
16--- |
17  target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
18  target triple = "x86_64-unknown-linux-gnu"
19
20  define hidden fastcc i64 @amd64_push_arguments(ptr %regcache, ptr %args) unnamed_addr !dbg !4 {
21    ret i64 0
22  }
23
24  ; Function Attrs: nofree nosync nounwind readnone speculatable willreturn
25  declare void @llvm.dbg.value(metadata, metadata, metadata)
26
27  !llvm.module.flags = !{!0, !1}
28  !llvm.dbg.cu = !{!2}
29
30  !0 = !{i32 2, !"Debug Info Version", i32 3}
31  !1 = !{i32 2, !"Dwarf Version", i32 4}
32  !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "beards", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
33  !3 = !DIFile(filename: "bees.cpp", directory: ".")
34  !4 = distinct !DISubprogram(name: "nope", scope: !3, file: !3, line: 1, type: !5, spFlags: DISPFlagDefinition, unit: !2, retainedNodes: !8)
35  !5 = !DISubroutineType(types: !6)
36  !6 = !{!7}
37  !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
38  !8 = !{}
39  !9 = !DILocation(line: 0, scope: !4)
40  !10 = !DILocalVariable(name: "flannel", scope: !4, file: !3, line: 1, type: !7)
41...
42---
43name:            amd64_push_arguments
44alignment:       16
45tracksRegLiveness: true
46debugInstrRef: true
47registers:
48  - { id: 0, class: gr32 }
49  - { id: 1, class: gr32 }
50  - { id: 2, class: gr32 }
51  - { id: 3, class: gr64 }
52  - { id: 4, class: gr32 }
53  - { id: 5, class: gr32 }
54  - { id: 6, class: gr32 }
55  - { id: 7, class: gr32 }
56  - { id: 8, class: gr64 }
57  - { id: 9, class: gr32 }
58  - { id: 10, class: gr32 }
59  - { id: 11, class: gr64 }
60  - { id: 12, class: gr32 }
61  - { id: 13, class: gr64 }
62  - { id: 14, class: gr32 }
63  - { id: 15, class: gr64 }
64  - { id: 16, class: gr64 }
65  - { id: 17, class: gr64 }
66  - { id: 18, class: gr32 }
67  - { id: 19, class: gr8 }
68  - { id: 20, class: gr64 }
69  - { id: 21, class: gr32 }
70  - { id: 22, class: gr32 }
71  - { id: 23, class: gr8 }
72  - { id: 24, class: gr32 }
73  - { id: 25, class: gr32 }
74  - { id: 26, class: gr32 }
75  - { id: 27, class: gr32 }
76  - { id: 28, class: gr8 }
77  - { id: 29, class: gr32 }
78  - { id: 30, class: gr8 }
79  - { id: 31, class: gr32 }
80  - { id: 32, class: gr32 }
81  - { id: 33, class: gr32 }
82  - { id: 34, class: gr8 }
83  - { id: 35, class: gr32 }
84  - { id: 36, class: gr64 }
85  - { id: 37, class: gr32 }
86  - { id: 38, class: gr32 }
87  - { id: 39, class: gr8 }
88  - { id: 40, class: gr32 }
89  - { id: 41, class: gr8 }
90  - { id: 42, class: gr32 }
91  - { id: 43, class: gr32 }
92  - { id: 44, class: gr64_nosp }
93  - { id: 45, class: gr64 }
94  - { id: 46, class: gr32 }
95  - { id: 47, class: gr64 }
96  - { id: 48, class: gr32 }
97  - { id: 49, class: gr32 }
98  - { id: 50, class: gr64 }
99  - { id: 51, class: gr64 }
100  - { id: 52, class: gr64 }
101  - { id: 53, class: gr64 }
102  - { id: 54, class: gr32 }
103  - { id: 55, class: gr64 }
104  - { id: 56, class: gr32 }
105liveins:
106  - { reg: '$rdi', virtual-reg: '%15' }
107frameInfo:
108  maxAlignment:    8
109  adjustsStack:    true
110  hasCalls:        true
111stack:
112  - { id: 0, size: 8, alignment: 8 }
113  - { id: 1, type: variable-sized, alignment: 1 }
114machineFunctionInfo: {}
115body:             |
116  bb.0:
117    successors: %bb.2(0x00000800), %bb.1(0x7ffff800)
118    liveins: $rdi
119
120    %15:gr64 = COPY killed $rdi
121    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !9
122    ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !9
123    %18:gr32 = MOV32r0 implicit-def dead $eflags
124    %19:gr8 = COPY killed %18.sub_8bit
125    TEST8rr killed %19, %19, implicit-def $eflags, debug-location !9
126    JCC_1 %bb.2, 5, implicit killed $eflags, debug-location !9
127    JMP_1 %bb.1, debug-location !9
128
129  bb.1:
130    RET 0, undef $rax
131
132  bb.2:
133    %27:gr32 = MOV32r0 implicit-def dead $eflags
134    %50:gr64 = LEA64r %stack.0, 1, $noreg, 0, $noreg
135    %54:gr32 = MOV32ri 8
136
137  bb.3:
138    successors: %bb.4, %bb.5
139
140    %0:gr32 = PHI undef %21:gr32, %bb.2, %0, %bb.5, %0, %bb.6, %0, %bb.8, %0, %bb.10, %10, %bb.21
141    %23:gr8 = COPY %27.sub_8bit
142    TEST8rr killed %23, %23, implicit-def $eflags, debug-location !9
143    JCC_1 %bb.5, 5, implicit killed $eflags, debug-location !9
144    JMP_1 %bb.4, debug-location !9
145
146  bb.4:
147    %24:gr32 = MOV32ri 1
148
149  bb.5:
150    successors: %bb.3(0x20000000), %bb.6(0x60000000)
151
152    %1:gr32 = PHI %27, %bb.3, %24, %bb.4, debug-location !9
153    %25:gr32 = nsw ADD32rr %1, %0, implicit-def dead $eflags, debug-location !9
154    CMP32ri killed %25, 6, implicit-def $eflags, debug-location !9
155    JCC_1 %bb.3, 7, implicit killed $eflags, debug-location !9
156    JMP_1 %bb.6, debug-location !9
157
158  bb.6:
159    successors: %bb.3(0x2aaaaaab), %bb.7(0x55555555)
160
161    %28:gr8 = COPY %27.sub_8bit
162    TEST8rr killed %28, %28, implicit-def $eflags, debug-location !9
163    JCC_1 %bb.3, 5, implicit killed $eflags, debug-location !9
164    JMP_1 %bb.7, debug-location !9
165
166  bb.7:
167    successors: %bb.8(0x60000000), %bb.9(0x20000000)
168
169    TEST32rr killed %1, %1, implicit-def $eflags, debug-location !9
170    JCC_1 %bb.9, 5, implicit killed $eflags, debug-location !9
171    JMP_1 %bb.8, debug-location !9
172
173  bb.8:
174    successors: %bb.3(0x55555555), %bb.9(0x2aaaaaab)
175
176    %30:gr8 = COPY %27.sub_8bit
177    TEST8rr killed %30, %30, implicit-def $eflags, debug-location !9
178    JCC_1 %bb.3, 5, implicit killed $eflags, debug-location !9
179    JMP_1 %bb.9, debug-location !9
180
181  bb.9:
182    successors: %bb.10(0x80000000), %bb.12(0x00000000)
183
184    CMP32ri undef %32:gr32, 16, implicit-def $eflags, debug-location !9
185    JCC_1 %bb.12, 15, implicit killed $eflags, debug-location !9
186    JMP_1 %bb.10, debug-location !9
187
188  bb.10:
189    successors: %bb.11, %bb.3
190
191    %34:gr8 = COPY %27.sub_8bit
192    TEST8rr killed %34, %34, implicit-def $eflags, debug-location !9
193    JCC_1 %bb.3, 5, implicit killed $eflags, debug-location !9
194    JMP_1 %bb.11, debug-location !9
195
196  bb.11:
197    %36:gr64 = SUBREG_TO_REG 0, %27, %subreg.sub_32bit
198    JMP_1 %bb.13, debug-location !9
199
200  bb.12:
201    successors:
202
203
204  bb.13:
205    successors: %bb.18(0x2aaaaaab), %bb.14(0x55555555)
206
207    %2:gr32 = PHI undef %35:gr32, %bb.11, %14, %bb.21
208    %3:gr64 = PHI %36, %bb.11, %13, %bb.21
209    %4:gr32 = PHI %0, %bb.11, %10, %bb.21, debug-instr-number 1
210    %5:gr32 = PHI undef %35:gr32, %bb.11, %9, %bb.21
211    DBG_INSTR_REF !10, !DIExpression(DW_OP_LLVM_arg, 0), dbg-instr-ref(1, 0), debug-location !9
212    %39:gr8 = COPY %27.sub_8bit
213    TEST8rr killed %39, %39, implicit-def $eflags, debug-location !9
214    JCC_1 %bb.18, 5, implicit killed $eflags, debug-location !9
215    JMP_1 %bb.14, debug-location !9
216
217  bb.14:
218    successors: %bb.17(0x40000001), %bb.15(0x3fffffff)
219
220    %41:gr8 = COPY %27.sub_8bit
221    TEST8rr killed %41, %41, implicit-def $eflags, debug-location !9
222    JCC_1 %bb.17, 5, implicit killed $eflags, debug-location !9
223    JMP_1 %bb.15, debug-location !9
224
225  bb.15:
226
227  bb.16:
228    %6:gr32 = nsw INC32r killed %4, implicit-def dead $eflags, debug-location !9
229    %48:gr32 = MOV32r0 implicit-def dead $eflags
230    JMP_1 %bb.21, debug-location !9
231
232  bb.17:
233    %7:gr32 = nsw INC32r killed %5, implicit-def dead $eflags, debug-location !9
234    %46:gr32 = MOV32r0 implicit-def dead $eflags
235    JMP_1 %bb.21, debug-location !9
236
237  bb.18:
238    successors: %bb.20(0x80000000), %bb.19(0x00000000)
239
240    TEST32rr %5, %5, implicit-def $eflags, debug-location !9
241    JCC_1 %bb.20, 15, implicit killed $eflags, debug-location !9
242    JMP_1 %bb.19, debug-location !9
243
244  bb.19:
245    successors:
246
247
248  bb.20:
249    %43:gr32 = nsw DEC32r %5, implicit-def dead $eflags, debug-location !9
250    %44:gr64_nosp = SUBREG_TO_REG 0, killed %43, %subreg.sub_32bit
251    ; Fiddled with to morph into llvm test,
252    %8:gr64 = LEA64r $noreg, 4, killed %44, @amd64_push_arguments, $noreg, debug-location !9
253    %42:gr32 = MOV32ri 8
254    JMP_1 %bb.21, debug-location !9
255
256  bb.21:
257    successors: %bb.13(0x7c000000), %bb.3(0x04000000)
258
259    %9:gr32 = PHI %5, %bb.20, %7, %bb.17, %5, %bb.16, debug-location !9
260    %10:gr32 = PHI %4, %bb.20, %4, %bb.17, %6, %bb.16, debug-location !9
261    %11:gr64 = PHI %8, %bb.20, undef %45:gr64, %bb.17, undef %47:gr64, %bb.16
262    %12:gr32 = PHI %42, %bb.20, %46, %bb.17, %48, %bb.16, debug-location !9
263    %49:gr32 = MOV32rm killed %11, 1, $noreg, 0, $noreg, debug-location !9 :: (load (s32) from `ptr undef`)
264    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !9
265    $rdi = COPY %50, debug-location !9
266    CALL64pcrel32 target-flags(x86-plt) &memcpy, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit undef $rsi, implicit undef $rdx, implicit-def $rsp, implicit-def $ssp, implicit-def dead $rax, debug-location !9
267    ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !9
268    ADJCALLSTACKDOWN64 0, 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !9
269    $rdi = COPY %15, debug-location !9
270    $esi = COPY killed %49, debug-location !9
271    $edx = COPY killed %12, debug-location !9
272    $ecx = COPY %54, debug-location !9
273    $r8 = COPY %50, debug-location !9
274    CALL64r undef %55:gr64, csr_64, implicit $rsp, implicit $ssp, implicit killed $rdi, implicit killed $esi, implicit killed $edx, implicit killed $ecx, implicit killed $r8, implicit-def $rsp, implicit-def $ssp, debug-location !9
275    ADJCALLSTACKUP64 0, 0, implicit-def dead $rsp, implicit-def dead $eflags, implicit-def dead $ssp, implicit $rsp, implicit $ssp, debug-location !9
276    %13:gr64 = nuw nsw INC64r killed %3, implicit-def dead $eflags, debug-location !9
277    %14:gr32 = ADD32ri killed %2, -8, implicit-def dead $eflags, debug-location !9
278    CMP32ri %14, 8, implicit-def $eflags, debug-location !9
279    JCC_1 %bb.13, 15, implicit killed $eflags, debug-location !9
280    JMP_1 %bb.3, debug-location !9
281
282...
283