1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -O0 -mtriple=aarch64 -run-pass=instruction-select -verify-machineinstrs %s -o - | FileCheck %s
4 # Verify the following:
6 # - We can fold compares into selects.
7 # - This only happens when the result of the compare is only used by selects.
9 # Also verify that, for now:
11 # - We only support condition flags that require a single instruction.
16 name: fcmp_more_than_one_user_no_fold
20 tracksRegLiveness: true
23 liveins: $s0, $s1, $w1
25 ; CHECK-LABEL: name: fcmp_more_than_one_user_no_fold
26 ; CHECK: liveins: $s0, $s1, $w1
27 ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
28 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s1
29 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
30 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
31 ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 1, implicit $nzcv
32 ; CHECK: [[COPY2:%[0-9]+]]:fpr32 = COPY [[CSINCWr]]
33 ; CHECK: [[COPY3:%[0-9]+]]:gpr32 = COPY [[COPY2]]
34 ; CHECK: [[ANDSWri:%[0-9]+]]:gpr32 = ANDSWri [[COPY3]], 0, implicit-def $nzcv
35 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[FMOVS0_]], [[COPY1]], 1, implicit $nzcv
36 ; CHECK: $w1 = COPY [[CSINCWr]]
37 ; CHECK: $s0 = COPY [[FCSELSrrr]]
38 ; CHECK: RET_ReallyLR implicit $s0
39 %0:fpr(s32) = COPY $s0
40 %1:fpr(s32) = COPY $s1
41 %2:fpr(s32) = G_FCONSTANT float 0.000000e+00
42 %5:gpr(s32) = G_FCMP floatpred(oeq), %0(s32), %2
43 %3:gpr(s1) = G_TRUNC %5(s32)
44 %6:fpr(s1) = COPY %3(s1)
45 %4:fpr(s32) = G_SELECT %6(s1), %2, %1
48 RET_ReallyLR implicit $s0
52 name: fcmp_more_than_one_select
56 tracksRegLiveness: true
59 liveins: $s0, $s1, $w1
61 ; CHECK-LABEL: name: fcmp_more_than_one_select
62 ; CHECK: liveins: $s0, $s1, $w1
63 ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
64 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s1
65 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
66 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
67 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[FMOVS0_]], [[COPY1]], 0, implicit $nzcv
68 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
69 ; CHECK: [[FCSELSrrr1:%[0-9]+]]:fpr32 = FCSELSrrr [[COPY1]], [[FMOVS0_]], 0, implicit $nzcv
70 ; CHECK: $s0 = COPY [[FCSELSrrr]]
71 ; CHECK: $s1 = COPY [[FCSELSrrr1]]
72 ; CHECK: RET_ReallyLR implicit $s0
73 %0:fpr(s32) = COPY $s0
74 %1:fpr(s32) = COPY $s1
75 %2:fpr(s32) = G_FCONSTANT float 0.000000e+00
76 %5:gpr(s32) = G_FCMP floatpred(oeq), %0(s32), %2
77 %3:gpr(s1) = G_TRUNC %5(s32)
78 %6:fpr(s1) = COPY %3(s1)
79 %4:fpr(s32) = G_SELECT %6(s1), %2, %1
80 %7:fpr(s32) = G_SELECT %6(s1), %1, %2
83 RET_ReallyLR implicit $s0
91 tracksRegLiveness: true
96 ; CHECK-LABEL: name: using_icmp
97 ; CHECK: liveins: $s0, $w0
98 ; CHECK: [[COPY:%[0-9]+]]:gpr32sp = COPY $w0
99 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s0
100 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
101 ; CHECK: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri [[COPY]], 0, 0, implicit-def $nzcv
102 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[COPY1]], [[FMOVS0_]], 0, implicit $nzcv
103 ; CHECK: $s0 = COPY [[FCSELSrrr]]
104 ; CHECK: RET_ReallyLR implicit $s0
105 %0:gpr(s32) = COPY $w0
106 %1:fpr(s32) = COPY $s0
107 %2:gpr(s32) = G_CONSTANT i32 0
108 %5:fpr(s32) = G_FCONSTANT float 0.000000e+00
109 %6:gpr(s32) = G_ICMP intpred(eq), %0(s32), %2
110 %3:gpr(s1) = G_TRUNC %6(s32)
111 %7:fpr(s1) = COPY %3(s1)
112 %4:fpr(s32) = G_SELECT %7(s1), %1, %5
114 RET_ReallyLR implicit $s0
121 regBankSelected: true
122 tracksRegLiveness: true
127 ; CHECK-LABEL: name: foeq
128 ; CHECK: liveins: $s0, $s1
129 ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
130 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s1
131 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
132 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
133 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[FMOVS0_]], [[COPY1]], 0, implicit $nzcv
134 ; CHECK: $s0 = COPY [[FCSELSrrr]]
135 ; CHECK: RET_ReallyLR implicit $s0
136 %0:fpr(s32) = COPY $s0
137 %1:fpr(s32) = COPY $s1
138 %2:fpr(s32) = G_FCONSTANT float 0.000000e+00
139 %5:gpr(s32) = G_FCMP floatpred(oeq), %0(s32), %2
140 %3:gpr(s1) = G_TRUNC %5(s32)
141 %6:fpr(s1) = COPY %3(s1)
142 %4:fpr(s32) = G_SELECT %6(s1), %2, %1
144 RET_ReallyLR implicit $s0
151 regBankSelected: true
152 tracksRegLiveness: true
157 ; CHECK-LABEL: name: fueq
158 ; CHECK: liveins: $s0, $s1
159 ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
160 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s1
161 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
162 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
163 ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 1, implicit $nzcv
164 ; CHECK: [[CSINCWr1:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 7, implicit $nzcv
165 ; CHECK: [[ORRWrr:%[0-9]+]]:gpr32 = ORRWrr [[CSINCWr]], [[CSINCWr1]]
166 ; CHECK: [[COPY2:%[0-9]+]]:fpr32 = COPY [[ORRWrr]]
167 ; CHECK: [[COPY3:%[0-9]+]]:gpr32 = COPY [[COPY2]]
168 ; CHECK: [[ANDSWri:%[0-9]+]]:gpr32 = ANDSWri [[COPY3]], 0, implicit-def $nzcv
169 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[FMOVS0_]], [[COPY1]], 1, implicit $nzcv
170 ; CHECK: $s0 = COPY [[FCSELSrrr]]
171 ; CHECK: RET_ReallyLR implicit $s0
172 %0:fpr(s32) = COPY $s0
173 %1:fpr(s32) = COPY $s1
174 %2:fpr(s32) = G_FCONSTANT float 0.000000e+00
175 %5:gpr(s32) = G_FCMP floatpred(ueq), %0(s32), %2
176 %3:gpr(s1) = G_TRUNC %5(s32)
177 %6:fpr(s1) = COPY %3(s1)
178 %4:fpr(s32) = G_SELECT %6(s1), %2, %1
180 RET_ReallyLR implicit $s0
187 regBankSelected: true
188 tracksRegLiveness: true
193 ; CHECK-LABEL: name: fone
194 ; CHECK: liveins: $s0, $s1
195 ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
196 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s1
197 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
198 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
199 ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 5, implicit $nzcv
200 ; CHECK: [[CSINCWr1:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 13, implicit $nzcv
201 ; CHECK: [[ORRWrr:%[0-9]+]]:gpr32 = ORRWrr [[CSINCWr]], [[CSINCWr1]]
202 ; CHECK: [[COPY2:%[0-9]+]]:fpr32 = COPY [[ORRWrr]]
203 ; CHECK: [[COPY3:%[0-9]+]]:gpr32 = COPY [[COPY2]]
204 ; CHECK: [[ANDSWri:%[0-9]+]]:gpr32 = ANDSWri [[COPY3]], 0, implicit-def $nzcv
205 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[COPY1]], [[FMOVS0_]], 1, implicit $nzcv
206 ; CHECK: $s0 = COPY [[FCSELSrrr]]
207 ; CHECK: RET_ReallyLR implicit $s0
208 %0:fpr(s32) = COPY $s0
209 %1:fpr(s32) = COPY $s1
210 %2:fpr(s32) = G_FCONSTANT float 0.000000e+00
211 %5:gpr(s32) = G_FCMP floatpred(one), %0(s32), %2
212 %3:gpr(s1) = G_TRUNC %5(s32)
213 %6:fpr(s1) = COPY %3(s1)
214 %4:fpr(s32) = G_SELECT %6(s1), %1, %2
216 RET_ReallyLR implicit $s0
223 regBankSelected: true
224 tracksRegLiveness: true
229 ; CHECK-LABEL: name: fune
230 ; CHECK: liveins: $s0, $s1
231 ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
232 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s1
233 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
234 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
235 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[COPY1]], [[FMOVS0_]], 1, implicit $nzcv
236 ; CHECK: $s0 = COPY [[FCSELSrrr]]
237 ; CHECK: RET_ReallyLR implicit $s0
238 %0:fpr(s32) = COPY $s0
239 %1:fpr(s32) = COPY $s1
240 %2:fpr(s32) = G_FCONSTANT float 0.000000e+00
241 %5:gpr(s32) = G_FCMP floatpred(une), %0(s32), %2
242 %3:gpr(s1) = G_TRUNC %5(s32)
243 %6:fpr(s1) = COPY %3(s1)
244 %4:fpr(s32) = G_SELECT %6(s1), %1, %2
246 RET_ReallyLR implicit $s0
253 regBankSelected: true
254 tracksRegLiveness: true
259 ; CHECK-LABEL: name: doeq
260 ; CHECK: liveins: $d0, $d1
261 ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
262 ; CHECK: [[COPY1:%[0-9]+]]:fpr64 = COPY $d1
263 ; CHECK: [[FMOVD0_:%[0-9]+]]:fpr64 = FMOVD0
264 ; CHECK: FCMPDri [[COPY]], implicit-def $nzcv
265 ; CHECK: [[FCSELDrrr:%[0-9]+]]:fpr64 = FCSELDrrr [[FMOVD0_]], [[COPY1]], 0, implicit $nzcv
266 ; CHECK: $d0 = COPY [[FCSELDrrr]]
267 ; CHECK: RET_ReallyLR implicit $d0
268 %0:fpr(s64) = COPY $d0
269 %1:fpr(s64) = COPY $d1
270 %2:fpr(s64) = G_FCONSTANT double 0.000000e+00
271 %5:gpr(s32) = G_FCMP floatpred(oeq), %0(s64), %2
272 %3:gpr(s1) = G_TRUNC %5(s32)
273 %6:fpr(s1) = COPY %3(s1)
274 %4:fpr(s64) = G_SELECT %6(s1), %2, %1
276 RET_ReallyLR implicit $d0
283 regBankSelected: true
284 tracksRegLiveness: true
289 ; CHECK-LABEL: name: dueq
290 ; CHECK: liveins: $d0, $d1
291 ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
292 ; CHECK: [[COPY1:%[0-9]+]]:fpr64 = COPY $d1
293 ; CHECK: [[FMOVD0_:%[0-9]+]]:fpr64 = FMOVD0
294 ; CHECK: FCMPDri [[COPY]], implicit-def $nzcv
295 ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 1, implicit $nzcv
296 ; CHECK: [[CSINCWr1:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 7, implicit $nzcv
297 ; CHECK: [[ORRWrr:%[0-9]+]]:gpr32 = ORRWrr [[CSINCWr]], [[CSINCWr1]]
298 ; CHECK: [[COPY2:%[0-9]+]]:fpr32 = COPY [[ORRWrr]]
299 ; CHECK: [[COPY3:%[0-9]+]]:gpr32 = COPY [[COPY2]]
300 ; CHECK: [[ANDSWri:%[0-9]+]]:gpr32 = ANDSWri [[COPY3]], 0, implicit-def $nzcv
301 ; CHECK: [[FCSELDrrr:%[0-9]+]]:fpr64 = FCSELDrrr [[FMOVD0_]], [[COPY1]], 1, implicit $nzcv
302 ; CHECK: $d0 = COPY [[FCSELDrrr]]
303 ; CHECK: RET_ReallyLR implicit $d0
304 %0:fpr(s64) = COPY $d0
305 %1:fpr(s64) = COPY $d1
306 %2:fpr(s64) = G_FCONSTANT double 0.000000e+00
307 %5:gpr(s32) = G_FCMP floatpred(ueq), %0(s64), %2
308 %3:gpr(s1) = G_TRUNC %5(s32)
309 %6:fpr(s1) = COPY %3(s1)
310 %4:fpr(s64) = G_SELECT %6(s1), %2, %1
312 RET_ReallyLR implicit $d0
319 regBankSelected: true
320 tracksRegLiveness: true
325 ; CHECK-LABEL: name: done
326 ; CHECK: liveins: $d0, $d1
327 ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
328 ; CHECK: [[COPY1:%[0-9]+]]:fpr64 = COPY $d1
329 ; CHECK: [[FMOVD0_:%[0-9]+]]:fpr64 = FMOVD0
330 ; CHECK: FCMPDri [[COPY]], implicit-def $nzcv
331 ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 5, implicit $nzcv
332 ; CHECK: [[CSINCWr1:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 13, implicit $nzcv
333 ; CHECK: [[ORRWrr:%[0-9]+]]:gpr32 = ORRWrr [[CSINCWr]], [[CSINCWr1]]
334 ; CHECK: [[COPY2:%[0-9]+]]:fpr32 = COPY [[ORRWrr]]
335 ; CHECK: [[COPY3:%[0-9]+]]:gpr32 = COPY [[COPY2]]
336 ; CHECK: [[ANDSWri:%[0-9]+]]:gpr32 = ANDSWri [[COPY3]], 0, implicit-def $nzcv
337 ; CHECK: [[FCSELDrrr:%[0-9]+]]:fpr64 = FCSELDrrr [[COPY1]], [[FMOVD0_]], 1, implicit $nzcv
338 ; CHECK: $d0 = COPY [[FCSELDrrr]]
339 ; CHECK: RET_ReallyLR implicit $d0
340 %0:fpr(s64) = COPY $d0
341 %1:fpr(s64) = COPY $d1
342 %2:fpr(s64) = G_FCONSTANT double 0.000000e+00
343 %5:gpr(s32) = G_FCMP floatpred(one), %0(s64), %2
344 %3:gpr(s1) = G_TRUNC %5(s32)
345 %6:fpr(s1) = COPY %3(s1)
346 %4:fpr(s64) = G_SELECT %6(s1), %1, %2
348 RET_ReallyLR implicit $d0
355 regBankSelected: true
356 tracksRegLiveness: true
361 ; CHECK-LABEL: name: dune
362 ; CHECK: liveins: $d0, $d1
363 ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
364 ; CHECK: [[COPY1:%[0-9]+]]:fpr64 = COPY $d1
365 ; CHECK: [[FMOVD0_:%[0-9]+]]:fpr64 = FMOVD0
366 ; CHECK: FCMPDri [[COPY]], implicit-def $nzcv
367 ; CHECK: [[FCSELDrrr:%[0-9]+]]:fpr64 = FCSELDrrr [[COPY1]], [[FMOVD0_]], 1, implicit $nzcv
368 ; CHECK: $d0 = COPY [[FCSELDrrr]]
369 ; CHECK: RET_ReallyLR implicit $d0
370 %0:fpr(s64) = COPY $d0
371 %1:fpr(s64) = COPY $d1
372 %2:fpr(s64) = G_FCONSTANT double 0.000000e+00
373 %5:gpr(s32) = G_FCMP floatpred(une), %0(s64), %2
374 %3:gpr(s1) = G_TRUNC %5(s32)
375 %6:fpr(s1) = COPY %3(s1)
376 %4:fpr(s64) = G_SELECT %6(s1), %1, %2
378 RET_ReallyLR implicit $d0
382 name: copy_from_physreg
385 regBankSelected: true
386 tracksRegLiveness: true
389 liveins: $s0, $w0, $w1
391 ; CHECK-LABEL: name: copy_from_physreg
392 ; CHECK: liveins: $s0, $w0, $w1
393 ; CHECK: [[COPY:%[0-9]+]]:gpr32 = COPY $w0
394 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s0
395 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
396 ; CHECK: BL @copy_from_physreg, implicit-def $w0
397 ; CHECK: [[ANDSWri:%[0-9]+]]:gpr32 = ANDSWri [[COPY]], 0, implicit-def $nzcv
398 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[COPY1]], [[FMOVS0_]], 1, implicit $nzcv
399 ; CHECK: BL @copy_from_physreg, implicit-def $w0
400 ; CHECK: $s0 = COPY [[FCSELSrrr]]
401 ; CHECK: RET_ReallyLR implicit $s0
402 %0:gpr(s32) = COPY $w0
403 %1:fpr(s32) = COPY $s0
404 %5:fpr(s32) = G_FCONSTANT float 0.000000e+00
405 BL @copy_from_physreg, implicit-def $w0
406 %3:gpr(s1) = G_TRUNC %0(s32)
407 %4:fpr(s32) = G_SELECT %3(s1), %1, %5
408 BL @copy_from_physreg, implicit-def $w0
410 RET_ReallyLR implicit $s0