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 the select.
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: $wzr = 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
56 tracksRegLiveness: true
61 ; CHECK-LABEL: name: using_icmp
62 ; CHECK: liveins: $s0, $w0
63 ; CHECK: [[COPY:%[0-9]+]]:gpr32sp = COPY $w0
64 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s0
65 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
66 ; CHECK: $wzr = SUBSWri [[COPY]], 0, 0, implicit-def $nzcv
67 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[COPY1]], [[FMOVS0_]], 0, implicit $nzcv
68 ; CHECK: $s0 = COPY [[FCSELSrrr]]
69 ; CHECK: RET_ReallyLR implicit $s0
70 %0:gpr(s32) = COPY $w0
71 %1:fpr(s32) = COPY $s0
72 %2:gpr(s32) = G_CONSTANT i32 0
73 %5:fpr(s32) = G_FCONSTANT float 0.000000e+00
74 %6:gpr(s32) = G_ICMP intpred(eq), %0(s32), %2
75 %3:gpr(s1) = G_TRUNC %6(s32)
76 %7:fpr(s1) = COPY %3(s1)
77 %4:fpr(s32) = G_SELECT %7(s1), %1, %5
79 RET_ReallyLR implicit $s0
87 tracksRegLiveness: true
92 ; CHECK-LABEL: name: foeq
93 ; CHECK: liveins: $s0, $s1
94 ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
95 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s1
96 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
97 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
98 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[FMOVS0_]], [[COPY1]], 0, implicit $nzcv
99 ; CHECK: $s0 = COPY [[FCSELSrrr]]
100 ; CHECK: RET_ReallyLR implicit $s0
101 %0:fpr(s32) = COPY $s0
102 %1:fpr(s32) = COPY $s1
103 %2:fpr(s32) = G_FCONSTANT float 0.000000e+00
104 %5:gpr(s32) = G_FCMP floatpred(oeq), %0(s32), %2
105 %3:gpr(s1) = G_TRUNC %5(s32)
106 %6:fpr(s1) = COPY %3(s1)
107 %4:fpr(s32) = G_SELECT %6(s1), %2, %1
109 RET_ReallyLR implicit $s0
116 regBankSelected: true
117 tracksRegLiveness: true
122 ; CHECK-LABEL: name: fueq
123 ; CHECK: liveins: $s0, $s1
124 ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
125 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s1
126 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
127 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
128 ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 1, implicit $nzcv
129 ; CHECK: [[CSINCWr1:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 7, implicit $nzcv
130 ; CHECK: [[ORRWrr:%[0-9]+]]:gpr32 = ORRWrr [[CSINCWr]], [[CSINCWr1]]
131 ; CHECK: [[COPY2:%[0-9]+]]:fpr32 = COPY [[ORRWrr]]
132 ; CHECK: [[COPY3:%[0-9]+]]:gpr32 = COPY [[COPY2]]
133 ; CHECK: $wzr = ANDSWri [[COPY3]], 0, implicit-def $nzcv
134 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[FMOVS0_]], [[COPY1]], 1, implicit $nzcv
135 ; CHECK: $s0 = COPY [[FCSELSrrr]]
136 ; CHECK: RET_ReallyLR implicit $s0
137 %0:fpr(s32) = COPY $s0
138 %1:fpr(s32) = COPY $s1
139 %2:fpr(s32) = G_FCONSTANT float 0.000000e+00
140 %5:gpr(s32) = G_FCMP floatpred(ueq), %0(s32), %2
141 %3:gpr(s1) = G_TRUNC %5(s32)
142 %6:fpr(s1) = COPY %3(s1)
143 %4:fpr(s32) = G_SELECT %6(s1), %2, %1
145 RET_ReallyLR implicit $s0
152 regBankSelected: true
153 tracksRegLiveness: true
158 ; CHECK-LABEL: name: fone
159 ; CHECK: liveins: $s0, $s1
160 ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
161 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s1
162 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
163 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
164 ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 5, implicit $nzcv
165 ; CHECK: [[CSINCWr1:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 13, implicit $nzcv
166 ; CHECK: [[ORRWrr:%[0-9]+]]:gpr32 = ORRWrr [[CSINCWr]], [[CSINCWr1]]
167 ; CHECK: [[COPY2:%[0-9]+]]:fpr32 = COPY [[ORRWrr]]
168 ; CHECK: [[COPY3:%[0-9]+]]:gpr32 = COPY [[COPY2]]
169 ; CHECK: $wzr = ANDSWri [[COPY3]], 0, implicit-def $nzcv
170 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[COPY1]], [[FMOVS0_]], 1, implicit $nzcv
171 ; CHECK: $s0 = COPY [[FCSELSrrr]]
172 ; CHECK: RET_ReallyLR implicit $s0
173 %0:fpr(s32) = COPY $s0
174 %1:fpr(s32) = COPY $s1
175 %2:fpr(s32) = G_FCONSTANT float 0.000000e+00
176 %5:gpr(s32) = G_FCMP floatpred(one), %0(s32), %2
177 %3:gpr(s1) = G_TRUNC %5(s32)
178 %6:fpr(s1) = COPY %3(s1)
179 %4:fpr(s32) = G_SELECT %6(s1), %1, %2
181 RET_ReallyLR implicit $s0
188 regBankSelected: true
189 tracksRegLiveness: true
194 ; CHECK-LABEL: name: fune
195 ; CHECK: liveins: $s0, $s1
196 ; CHECK: [[COPY:%[0-9]+]]:fpr32 = COPY $s0
197 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s1
198 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
199 ; CHECK: FCMPSri [[COPY]], implicit-def $nzcv
200 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[COPY1]], [[FMOVS0_]], 1, implicit $nzcv
201 ; CHECK: $s0 = COPY [[FCSELSrrr]]
202 ; CHECK: RET_ReallyLR implicit $s0
203 %0:fpr(s32) = COPY $s0
204 %1:fpr(s32) = COPY $s1
205 %2:fpr(s32) = G_FCONSTANT float 0.000000e+00
206 %5:gpr(s32) = G_FCMP floatpred(une), %0(s32), %2
207 %3:gpr(s1) = G_TRUNC %5(s32)
208 %6:fpr(s1) = COPY %3(s1)
209 %4:fpr(s32) = G_SELECT %6(s1), %1, %2
211 RET_ReallyLR implicit $s0
218 regBankSelected: true
219 tracksRegLiveness: true
224 ; CHECK-LABEL: name: doeq
225 ; CHECK: liveins: $d0, $d1
226 ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
227 ; CHECK: [[COPY1:%[0-9]+]]:fpr64 = COPY $d1
228 ; CHECK: [[FMOVD0_:%[0-9]+]]:fpr64 = FMOVD0
229 ; CHECK: FCMPDri [[COPY]], implicit-def $nzcv
230 ; CHECK: [[FCSELDrrr:%[0-9]+]]:fpr64 = FCSELDrrr [[FMOVD0_]], [[COPY1]], 0, implicit $nzcv
231 ; CHECK: $d0 = COPY [[FCSELDrrr]]
232 ; CHECK: RET_ReallyLR implicit $d0
233 %0:fpr(s64) = COPY $d0
234 %1:fpr(s64) = COPY $d1
235 %2:fpr(s64) = G_FCONSTANT double 0.000000e+00
236 %5:gpr(s32) = G_FCMP floatpred(oeq), %0(s64), %2
237 %3:gpr(s1) = G_TRUNC %5(s32)
238 %6:fpr(s1) = COPY %3(s1)
239 %4:fpr(s64) = G_SELECT %6(s1), %2, %1
241 RET_ReallyLR implicit $d0
248 regBankSelected: true
249 tracksRegLiveness: true
254 ; CHECK-LABEL: name: dueq
255 ; CHECK: liveins: $d0, $d1
256 ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
257 ; CHECK: [[COPY1:%[0-9]+]]:fpr64 = COPY $d1
258 ; CHECK: [[FMOVD0_:%[0-9]+]]:fpr64 = FMOVD0
259 ; CHECK: FCMPDri [[COPY]], implicit-def $nzcv
260 ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 1, implicit $nzcv
261 ; CHECK: [[CSINCWr1:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 7, implicit $nzcv
262 ; CHECK: [[ORRWrr:%[0-9]+]]:gpr32 = ORRWrr [[CSINCWr]], [[CSINCWr1]]
263 ; CHECK: [[COPY2:%[0-9]+]]:fpr32 = COPY [[ORRWrr]]
264 ; CHECK: [[COPY3:%[0-9]+]]:gpr32 = COPY [[COPY2]]
265 ; CHECK: $wzr = ANDSWri [[COPY3]], 0, implicit-def $nzcv
266 ; CHECK: [[FCSELDrrr:%[0-9]+]]:fpr64 = FCSELDrrr [[FMOVD0_]], [[COPY1]], 1, implicit $nzcv
267 ; CHECK: $d0 = COPY [[FCSELDrrr]]
268 ; CHECK: RET_ReallyLR implicit $d0
269 %0:fpr(s64) = COPY $d0
270 %1:fpr(s64) = COPY $d1
271 %2:fpr(s64) = G_FCONSTANT double 0.000000e+00
272 %5:gpr(s32) = G_FCMP floatpred(ueq), %0(s64), %2
273 %3:gpr(s1) = G_TRUNC %5(s32)
274 %6:fpr(s1) = COPY %3(s1)
275 %4:fpr(s64) = G_SELECT %6(s1), %2, %1
277 RET_ReallyLR implicit $d0
284 regBankSelected: true
285 tracksRegLiveness: true
290 ; CHECK-LABEL: name: done
291 ; CHECK: liveins: $d0, $d1
292 ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
293 ; CHECK: [[COPY1:%[0-9]+]]:fpr64 = COPY $d1
294 ; CHECK: [[FMOVD0_:%[0-9]+]]:fpr64 = FMOVD0
295 ; CHECK: FCMPDri [[COPY]], implicit-def $nzcv
296 ; CHECK: [[CSINCWr:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 5, implicit $nzcv
297 ; CHECK: [[CSINCWr1:%[0-9]+]]:gpr32 = CSINCWr $wzr, $wzr, 13, implicit $nzcv
298 ; CHECK: [[ORRWrr:%[0-9]+]]:gpr32 = ORRWrr [[CSINCWr]], [[CSINCWr1]]
299 ; CHECK: [[COPY2:%[0-9]+]]:fpr32 = COPY [[ORRWrr]]
300 ; CHECK: [[COPY3:%[0-9]+]]:gpr32 = COPY [[COPY2]]
301 ; CHECK: $wzr = ANDSWri [[COPY3]], 0, implicit-def $nzcv
302 ; CHECK: [[FCSELDrrr:%[0-9]+]]:fpr64 = FCSELDrrr [[COPY1]], [[FMOVD0_]], 1, implicit $nzcv
303 ; CHECK: $d0 = COPY [[FCSELDrrr]]
304 ; CHECK: RET_ReallyLR implicit $d0
305 %0:fpr(s64) = COPY $d0
306 %1:fpr(s64) = COPY $d1
307 %2:fpr(s64) = G_FCONSTANT double 0.000000e+00
308 %5:gpr(s32) = G_FCMP floatpred(one), %0(s64), %2
309 %3:gpr(s1) = G_TRUNC %5(s32)
310 %6:fpr(s1) = COPY %3(s1)
311 %4:fpr(s64) = G_SELECT %6(s1), %1, %2
313 RET_ReallyLR implicit $d0
320 regBankSelected: true
321 tracksRegLiveness: true
326 ; CHECK-LABEL: name: dune
327 ; CHECK: liveins: $d0, $d1
328 ; CHECK: [[COPY:%[0-9]+]]:fpr64 = COPY $d0
329 ; CHECK: [[COPY1:%[0-9]+]]:fpr64 = COPY $d1
330 ; CHECK: [[FMOVD0_:%[0-9]+]]:fpr64 = FMOVD0
331 ; CHECK: FCMPDri [[COPY]], implicit-def $nzcv
332 ; CHECK: [[FCSELDrrr:%[0-9]+]]:fpr64 = FCSELDrrr [[COPY1]], [[FMOVD0_]], 1, implicit $nzcv
333 ; CHECK: $d0 = COPY [[FCSELDrrr]]
334 ; CHECK: RET_ReallyLR implicit $d0
335 %0:fpr(s64) = COPY $d0
336 %1:fpr(s64) = COPY $d1
337 %2:fpr(s64) = G_FCONSTANT double 0.000000e+00
338 %5:gpr(s32) = G_FCMP floatpred(une), %0(s64), %2
339 %3:gpr(s1) = G_TRUNC %5(s32)
340 %6:fpr(s1) = COPY %3(s1)
341 %4:fpr(s64) = G_SELECT %6(s1), %1, %2
343 RET_ReallyLR implicit $d0
347 name: copy_from_physreg
350 regBankSelected: true
351 tracksRegLiveness: true
354 liveins: $s0, $w0, $w1
356 ; CHECK-LABEL: name: copy_from_physreg
357 ; CHECK: liveins: $s0, $w0, $w1
358 ; CHECK: [[COPY:%[0-9]+]]:gpr32 = COPY $w0
359 ; CHECK: [[COPY1:%[0-9]+]]:fpr32 = COPY $s0
360 ; CHECK: [[FMOVS0_:%[0-9]+]]:fpr32 = FMOVS0
361 ; CHECK: BL @copy_from_physreg, implicit-def $w0
362 ; CHECK: $wzr = ANDSWri [[COPY]], 0, implicit-def $nzcv
363 ; CHECK: [[FCSELSrrr:%[0-9]+]]:fpr32 = FCSELSrrr [[COPY1]], [[FMOVS0_]], 1, implicit $nzcv
364 ; CHECK: BL @copy_from_physreg, implicit-def $w0
365 ; CHECK: $s0 = COPY [[FCSELSrrr]]
366 ; CHECK: RET_ReallyLR implicit $s0
367 %0:gpr(s32) = COPY $w0
368 %1:fpr(s32) = COPY $s0
369 %5:fpr(s32) = G_FCONSTANT float 0.000000e+00
370 BL @copy_from_physreg, implicit-def $w0
371 %3:gpr(s1) = G_TRUNC %0(s32)
372 %4:fpr(s32) = G_SELECT %3(s1), %1, %5
373 BL @copy_from_physreg, implicit-def $w0
375 RET_ReallyLR implicit $s0