1 # NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py
2 # RUN: llc -mtriple=aarch64 -run-pass=aarch64-postlegalizer-lowering -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=LOWER
3 # RUN: llc -mtriple=aarch64 -global-isel -start-before=aarch64-postlegalizer-lowering -stop-after=instruction-select -verify-machineinstrs %s -o - | FileCheck %s --check-prefix=SELECT
5 # Verify that we will adjust the constant + predicate of a compare when it will
6 # allow us to fold an immediate into a compare.
11 tracksRegLiveness: true
16 ; x slt c => x sle c - 1
18 ; log_2(4096) == 12, so we can represent this as a 12 bit value with a
21 ; LOWER-LABEL: name: slt_to_sle_s32
24 ; LOWER-NEXT: %reg:_(s32) = COPY $w0
25 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 4096
26 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sle), %reg(s32), [[C]]
27 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
28 ; LOWER-NEXT: RET_ReallyLR implicit $w0
29 ; SELECT-LABEL: name: slt_to_sle_s32
30 ; SELECT: liveins: $w0
32 ; SELECT-NEXT: %reg:gpr32sp = COPY $w0
33 ; SELECT-NEXT: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri %reg, 1, 12, implicit-def $nzcv
34 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 12, implicit $nzcv
35 ; SELECT-NEXT: $w0 = COPY %cmp
36 ; SELECT-NEXT: RET_ReallyLR implicit $w0
37 %reg:_(s32) = COPY $w0
38 %cst:_(s32) = G_CONSTANT i32 4097
39 %cmp:_(s32) = G_ICMP intpred(slt), %reg(s32), %cst
41 RET_ReallyLR implicit $w0
47 tracksRegLiveness: true
52 ; x slt c => x sle c - 1
54 ; log_2(4096) == 12, so we can represent this as a 12 bit value with a
57 ; LOWER-LABEL: name: slt_to_sle_s64
60 ; LOWER-NEXT: %reg:_(s64) = COPY $x0
61 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 4096
62 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sle), %reg(s64), [[C]]
63 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
64 ; LOWER-NEXT: RET_ReallyLR implicit $w0
65 ; SELECT-LABEL: name: slt_to_sle_s64
66 ; SELECT: liveins: $x0
68 ; SELECT-NEXT: %reg:gpr64sp = COPY $x0
69 ; SELECT-NEXT: [[SUBSXri:%[0-9]+]]:gpr64 = SUBSXri %reg, 1, 12, implicit-def $nzcv
70 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 12, implicit $nzcv
71 ; SELECT-NEXT: $w0 = COPY %cmp
72 ; SELECT-NEXT: RET_ReallyLR implicit $w0
73 %reg:_(s64) = COPY $x0
74 %cst:_(s64) = G_CONSTANT i64 4097
75 %cmp:_(s32) = G_ICMP intpred(slt), %reg(s64), %cst
77 RET_ReallyLR implicit $w0
83 tracksRegLiveness: true
88 ; x sge c => x sgt c - 1
90 ; log_2(4096) == 12, so we can represent this as a 12 bit value with a
93 ; LOWER-LABEL: name: sge_to_sgt_s32
96 ; LOWER-NEXT: %reg:_(s32) = COPY $w0
97 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 4096
98 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sgt), %reg(s32), [[C]]
99 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
100 ; LOWER-NEXT: RET_ReallyLR implicit $w0
101 ; SELECT-LABEL: name: sge_to_sgt_s32
102 ; SELECT: liveins: $w0
103 ; SELECT-NEXT: {{ $}}
104 ; SELECT-NEXT: %reg:gpr32sp = COPY $w0
105 ; SELECT-NEXT: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri %reg, 1, 12, implicit-def $nzcv
106 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 13, implicit $nzcv
107 ; SELECT-NEXT: $w0 = COPY %cmp
108 ; SELECT-NEXT: RET_ReallyLR implicit $w0
109 %reg:_(s32) = COPY $w0
110 %cst:_(s32) = G_CONSTANT i32 4097
111 %cmp:_(s32) = G_ICMP intpred(sge), %reg(s32), %cst
113 RET_ReallyLR implicit $w0
119 tracksRegLiveness: true
124 ; x sge c => x sgt c - 1
126 ; log_2(4096) == 12, so we can represent this as a 12 bit value with a
129 ; LOWER-LABEL: name: sge_to_sgt_s64
130 ; LOWER: liveins: $x0
132 ; LOWER-NEXT: %reg:_(s64) = COPY $x0
133 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 4096
134 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sgt), %reg(s64), [[C]]
135 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
136 ; LOWER-NEXT: RET_ReallyLR implicit $w0
137 ; SELECT-LABEL: name: sge_to_sgt_s64
138 ; SELECT: liveins: $x0
139 ; SELECT-NEXT: {{ $}}
140 ; SELECT-NEXT: %reg:gpr64sp = COPY $x0
141 ; SELECT-NEXT: [[SUBSXri:%[0-9]+]]:gpr64 = SUBSXri %reg, 1, 12, implicit-def $nzcv
142 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 13, implicit $nzcv
143 ; SELECT-NEXT: $w0 = COPY %cmp
144 ; SELECT-NEXT: RET_ReallyLR implicit $w0
145 %reg:_(s64) = COPY $x0
146 %cst:_(s64) = G_CONSTANT i64 4097
147 %cmp:_(s32) = G_ICMP intpred(sge), %reg(s64), %cst
149 RET_ReallyLR implicit $w0
155 tracksRegLiveness: true
160 ; x ult c => x ule c - 1
162 ; log_2(4096) == 12, so we can represent this as a 12 bit value with a
165 ; LOWER-LABEL: name: ult_to_ule_s32
166 ; LOWER: liveins: $w0
168 ; LOWER-NEXT: %reg:_(s32) = COPY $w0
169 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 4096
170 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(ule), %reg(s32), [[C]]
171 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
172 ; LOWER-NEXT: RET_ReallyLR implicit $w0
173 ; SELECT-LABEL: name: ult_to_ule_s32
174 ; SELECT: liveins: $w0
175 ; SELECT-NEXT: {{ $}}
176 ; SELECT-NEXT: %reg:gpr32sp = COPY $w0
177 ; SELECT-NEXT: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri %reg, 1, 12, implicit-def $nzcv
178 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 8, implicit $nzcv
179 ; SELECT-NEXT: $w0 = COPY %cmp
180 ; SELECT-NEXT: RET_ReallyLR implicit $w0
181 %reg:_(s32) = COPY $w0
182 %cst:_(s32) = G_CONSTANT i32 4097
183 %cmp:_(s32) = G_ICMP intpred(ult), %reg(s32), %cst
185 RET_ReallyLR implicit $w0
191 tracksRegLiveness: true
196 ; x ult c => x ule c - 1
198 ; log_2(4096) == 12, so we can represent this as a 12 bit value with a
201 ; LOWER-LABEL: name: ult_to_ule_s64
202 ; LOWER: liveins: $x0
204 ; LOWER-NEXT: %reg:_(s64) = COPY $x0
205 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 4096
206 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(ule), %reg(s64), [[C]]
207 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
208 ; LOWER-NEXT: RET_ReallyLR implicit $w0
209 ; SELECT-LABEL: name: ult_to_ule_s64
210 ; SELECT: liveins: $x0
211 ; SELECT-NEXT: {{ $}}
212 ; SELECT-NEXT: %reg:gpr64sp = COPY $x0
213 ; SELECT-NEXT: [[SUBSXri:%[0-9]+]]:gpr64 = SUBSXri %reg, 1, 12, implicit-def $nzcv
214 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 8, implicit $nzcv
215 ; SELECT-NEXT: $w0 = COPY %cmp
216 ; SELECT-NEXT: RET_ReallyLR implicit $w0
217 %reg:_(s64) = COPY $x0
218 %cst:_(s64) = G_CONSTANT i64 4097
219 %cmp:_(s32) = G_ICMP intpred(ult), %reg(s64), %cst
221 RET_ReallyLR implicit $w0
227 tracksRegLiveness: true
232 ; x uge c => x ugt c - 1
234 ; log_2(4096) == 12, so we can represent this as a 12 bit value with a
237 ; LOWER-LABEL: name: uge_to_ugt_s32
238 ; LOWER: liveins: $w0
240 ; LOWER-NEXT: %reg:_(s32) = COPY $w0
241 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 4096
242 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(ugt), %reg(s32), [[C]]
243 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
244 ; LOWER-NEXT: RET_ReallyLR implicit $w0
245 ; SELECT-LABEL: name: uge_to_ugt_s32
246 ; SELECT: liveins: $w0
247 ; SELECT-NEXT: {{ $}}
248 ; SELECT-NEXT: %reg:gpr32sp = COPY $w0
249 ; SELECT-NEXT: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri %reg, 1, 12, implicit-def $nzcv
250 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 9, implicit $nzcv
251 ; SELECT-NEXT: $w0 = COPY %cmp
252 ; SELECT-NEXT: RET_ReallyLR implicit $w0
253 %reg:_(s32) = COPY $w0
254 %cst:_(s32) = G_CONSTANT i32 4097
255 %cmp:_(s32) = G_ICMP intpred(uge), %reg(s32), %cst
257 RET_ReallyLR implicit $w0
263 tracksRegLiveness: true
268 ; x uge c => x ugt c - 1
270 ; log_2(4096) == 12, so we can represent this as a 12 bit value with a
273 ; LOWER-LABEL: name: uge_to_ugt_s64
274 ; LOWER: liveins: $x0
276 ; LOWER-NEXT: %reg:_(s64) = COPY $x0
277 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 4096
278 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(ugt), %reg(s64), [[C]]
279 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
280 ; LOWER-NEXT: RET_ReallyLR implicit $w0
281 ; SELECT-LABEL: name: uge_to_ugt_s64
282 ; SELECT: liveins: $x0
283 ; SELECT-NEXT: {{ $}}
284 ; SELECT-NEXT: %reg:gpr64sp = COPY $x0
285 ; SELECT-NEXT: [[SUBSXri:%[0-9]+]]:gpr64 = SUBSXri %reg, 1, 12, implicit-def $nzcv
286 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 9, implicit $nzcv
287 ; SELECT-NEXT: $w0 = COPY %cmp
288 ; SELECT-NEXT: RET_ReallyLR implicit $w0
289 %reg:_(s64) = COPY $x0
290 %cst:_(s64) = G_CONSTANT i64 4097
291 %cmp:_(s32) = G_ICMP intpred(uge), %reg(s64), %cst
293 RET_ReallyLR implicit $w0
299 tracksRegLiveness: true
304 ; x sle c => x slt c + 1
306 ; log_2(8192) == 13, so we can represent this as a 12 bit value with a
309 ; (We can't use 4095 here, because that's a legal arithmetic immediate.)
311 ; LOWER-LABEL: name: sle_to_slt_s32
312 ; LOWER: liveins: $w0
314 ; LOWER-NEXT: %reg:_(s32) = COPY $w0
315 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 8192
316 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(slt), %reg(s32), [[C]]
317 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
318 ; LOWER-NEXT: RET_ReallyLR implicit $w0
319 ; SELECT-LABEL: name: sle_to_slt_s32
320 ; SELECT: liveins: $w0
321 ; SELECT-NEXT: {{ $}}
322 ; SELECT-NEXT: %reg:gpr32sp = COPY $w0
323 ; SELECT-NEXT: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri %reg, 2, 12, implicit-def $nzcv
324 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 10, implicit $nzcv
325 ; SELECT-NEXT: $w0 = COPY %cmp
326 ; SELECT-NEXT: RET_ReallyLR implicit $w0
327 %reg:_(s32) = COPY $w0
328 %cst:_(s32) = G_CONSTANT i32 8191
329 %cmp:_(s32) = G_ICMP intpred(sle), %reg(s32), %cst
331 RET_ReallyLR implicit $w0
337 tracksRegLiveness: true
342 ; x sle c => x slt c + 1
344 ; log_2(8192) == 13, so we can represent this as a 12 bit value with a
347 ; LOWER-LABEL: name: sle_to_slt_s64
348 ; LOWER: liveins: $x0
350 ; LOWER-NEXT: %reg:_(s64) = COPY $x0
351 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 8192
352 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(slt), %reg(s64), [[C]]
353 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
354 ; LOWER-NEXT: RET_ReallyLR implicit $w0
355 ; SELECT-LABEL: name: sle_to_slt_s64
356 ; SELECT: liveins: $x0
357 ; SELECT-NEXT: {{ $}}
358 ; SELECT-NEXT: %reg:gpr64sp = COPY $x0
359 ; SELECT-NEXT: [[SUBSXri:%[0-9]+]]:gpr64 = SUBSXri %reg, 2, 12, implicit-def $nzcv
360 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 10, implicit $nzcv
361 ; SELECT-NEXT: $w0 = COPY %cmp
362 ; SELECT-NEXT: RET_ReallyLR implicit $w0
363 %reg:_(s64) = COPY $x0
364 %cst:_(s64) = G_CONSTANT i64 8191
365 %cmp:_(s32) = G_ICMP intpred(sle), %reg(s64), %cst
367 RET_ReallyLR implicit $w0
373 tracksRegLiveness: true
378 ; x sgt c => s sge c + 1
380 ; log_2(8192) == 13, so we can represent this as a 12 bit value with a
383 ; LOWER-LABEL: name: sgt_to_sge_s32
384 ; LOWER: liveins: $w0
386 ; LOWER-NEXT: %reg:_(s32) = COPY $w0
387 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 8192
388 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sge), %reg(s32), [[C]]
389 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
390 ; LOWER-NEXT: RET_ReallyLR implicit $w0
391 ; SELECT-LABEL: name: sgt_to_sge_s32
392 ; SELECT: liveins: $w0
393 ; SELECT-NEXT: {{ $}}
394 ; SELECT-NEXT: %reg:gpr32sp = COPY $w0
395 ; SELECT-NEXT: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri %reg, 2, 12, implicit-def $nzcv
396 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 11, implicit $nzcv
397 ; SELECT-NEXT: $w0 = COPY %cmp
398 ; SELECT-NEXT: RET_ReallyLR implicit $w0
399 %reg:_(s32) = COPY $w0
400 %cst:_(s32) = G_CONSTANT i32 8191
401 %cmp:_(s32) = G_ICMP intpred(sgt), %reg(s32), %cst
403 RET_ReallyLR implicit $w0
409 tracksRegLiveness: true
414 ; x sgt c => s sge c + 1
416 ; log_2(8192) == 13, so we can represent this as a 12 bit value with a
419 ; LOWER-LABEL: name: sgt_to_sge_s64
420 ; LOWER: liveins: $x0
422 ; LOWER-NEXT: %reg:_(s64) = COPY $x0
423 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s64) = G_CONSTANT i64 8192
424 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sge), %reg(s64), [[C]]
425 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
426 ; LOWER-NEXT: RET_ReallyLR implicit $w0
427 ; SELECT-LABEL: name: sgt_to_sge_s64
428 ; SELECT: liveins: $x0
429 ; SELECT-NEXT: {{ $}}
430 ; SELECT-NEXT: %reg:gpr64sp = COPY $x0
431 ; SELECT-NEXT: [[SUBSXri:%[0-9]+]]:gpr64 = SUBSXri %reg, 2, 12, implicit-def $nzcv
432 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 11, implicit $nzcv
433 ; SELECT-NEXT: $w0 = COPY %cmp
434 ; SELECT-NEXT: RET_ReallyLR implicit $w0
435 %reg:_(s64) = COPY $x0
436 %cst:_(s64) = G_CONSTANT i64 8191
437 %cmp:_(s32) = G_ICMP intpred(sgt), %reg(s64), %cst
439 RET_ReallyLR implicit $w0
443 name: no_opt_int32_min
445 tracksRegLiveness: true
450 ; The cmp should not change.
452 ; If we subtract 1 from the constant, it will wrap around, and so it's not
455 ; x slt c => x sle c - 1
456 ; x sge c => x sgt c - 1
458 ; LOWER-LABEL: name: no_opt_int32_min
459 ; LOWER: liveins: $w0
461 ; LOWER-NEXT: %reg:_(s32) = COPY $w0
462 ; LOWER-NEXT: %cst:_(s32) = G_CONSTANT i32 -2147483648
463 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(slt), %reg(s32), %cst
464 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
465 ; LOWER-NEXT: RET_ReallyLR implicit $w0
466 ; SELECT-LABEL: name: no_opt_int32_min
467 ; SELECT: liveins: $w0
468 ; SELECT-NEXT: {{ $}}
469 ; SELECT-NEXT: %reg:gpr32 = COPY $w0
470 ; SELECT-NEXT: %cst:gpr32 = MOVi32imm -2147483648
471 ; SELECT-NEXT: [[SUBSWrr:%[0-9]+]]:gpr32 = SUBSWrr %reg, %cst, implicit-def $nzcv
472 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 10, implicit $nzcv
473 ; SELECT-NEXT: $w0 = COPY %cmp
474 ; SELECT-NEXT: RET_ReallyLR implicit $w0
475 %reg:_(s32) = COPY $w0
476 %cst:_(s32) = G_CONSTANT i32 -2147483648
477 %cmp:_(s32) = G_ICMP intpred(slt), %reg(s32), %cst
479 RET_ReallyLR implicit $w0
483 name: no_opt_int64_min
485 tracksRegLiveness: true
490 ; The cmp should not change.
492 ; If we subtract 1 from the constant, it will wrap around, and so it's not
495 ; x slt c => x sle c - 1
496 ; x sge c => x sgt c - 1
498 ; LOWER-LABEL: name: no_opt_int64_min
499 ; LOWER: liveins: $x0
501 ; LOWER-NEXT: %reg:_(s64) = COPY $x0
502 ; LOWER-NEXT: %cst:_(s64) = G_CONSTANT i64 -9223372036854775808
503 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(slt), %reg(s64), %cst
504 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
505 ; LOWER-NEXT: RET_ReallyLR implicit $w0
506 ; SELECT-LABEL: name: no_opt_int64_min
507 ; SELECT: liveins: $x0
508 ; SELECT-NEXT: {{ $}}
509 ; SELECT-NEXT: %reg:gpr64 = COPY $x0
510 ; SELECT-NEXT: %cst:gpr64 = MOVi64imm -9223372036854775808
511 ; SELECT-NEXT: [[SUBSXrr:%[0-9]+]]:gpr64 = SUBSXrr %reg, %cst, implicit-def $nzcv
512 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 10, implicit $nzcv
513 ; SELECT-NEXT: $w0 = COPY %cmp
514 ; SELECT-NEXT: RET_ReallyLR implicit $w0
515 %reg:_(s64) = COPY $x0
516 %cst:_(s64) = G_CONSTANT i64 -9223372036854775808
517 %cmp:_(s32) = G_ICMP intpred(slt), %reg(s64), %cst
519 RET_ReallyLR implicit $w0
523 name: no_opt_int32_max
525 tracksRegLiveness: true
530 ; The cmp should not change.
532 ; If we add 1 to the constant, it will wrap around, and so it's not true
535 ; x slt c => x sle c - 1
536 ; x sge c => x sgt c - 1
538 ; LOWER-LABEL: name: no_opt_int32_max
539 ; LOWER: liveins: $w0
541 ; LOWER-NEXT: %reg:_(s32) = COPY $w0
542 ; LOWER-NEXT: %cst:_(s32) = G_CONSTANT i32 2147483647
543 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sle), %reg(s32), %cst
544 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
545 ; LOWER-NEXT: RET_ReallyLR implicit $w0
546 ; SELECT-LABEL: name: no_opt_int32_max
547 ; SELECT: liveins: $w0
548 ; SELECT-NEXT: {{ $}}
549 ; SELECT-NEXT: %reg:gpr32 = COPY $w0
550 ; SELECT-NEXT: %cst:gpr32 = MOVi32imm 2147483647
551 ; SELECT-NEXT: [[SUBSWrr:%[0-9]+]]:gpr32 = SUBSWrr %reg, %cst, implicit-def $nzcv
552 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 12, implicit $nzcv
553 ; SELECT-NEXT: $w0 = COPY %cmp
554 ; SELECT-NEXT: RET_ReallyLR implicit $w0
555 %reg:_(s32) = COPY $w0
556 %cst:_(s32) = G_CONSTANT i32 2147483647
557 %cmp:_(s32) = G_ICMP intpred(sle), %reg(s32), %cst
559 RET_ReallyLR implicit $w0
563 name: no_opt_int64_max
565 tracksRegLiveness: true
570 ; The cmp should not change.
572 ; If we add 1 to the constant, it will wrap around, and so it's not true
575 ; x slt c => x sle c - 1
576 ; x sge c => x sgt c - 1
579 ; LOWER-LABEL: name: no_opt_int64_max
580 ; LOWER: liveins: $x0
582 ; LOWER-NEXT: %reg:_(s64) = COPY $x0
583 ; LOWER-NEXT: %cst:_(s64) = G_CONSTANT i64 9223372036854775807
584 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(sle), %reg(s64), %cst
585 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
586 ; LOWER-NEXT: RET_ReallyLR implicit $w0
587 ; SELECT-LABEL: name: no_opt_int64_max
588 ; SELECT: liveins: $x0
589 ; SELECT-NEXT: {{ $}}
590 ; SELECT-NEXT: %reg:gpr64 = COPY $x0
591 ; SELECT-NEXT: %cst:gpr64 = MOVi64imm 9223372036854775807
592 ; SELECT-NEXT: [[SUBSXrr:%[0-9]+]]:gpr64 = SUBSXrr %reg, %cst, implicit-def $nzcv
593 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 12, implicit $nzcv
594 ; SELECT-NEXT: $w0 = COPY %cmp
595 ; SELECT-NEXT: RET_ReallyLR implicit $w0
596 %reg:_(s64) = COPY $x0
597 %cst:_(s64) = G_CONSTANT i64 9223372036854775807
598 %cmp:_(s32) = G_ICMP intpred(sle), %reg(s64), %cst
600 RET_ReallyLR implicit $w0
606 tracksRegLiveness: true
611 ; The cmp should not change during the lowering pass.
613 ; This is an unsigned comparison, so when the constant is 0, the following
616 ; x slt c => x sle c - 1
617 ; x sge c => x sgt c - 1
619 ; LOWER-LABEL: name: no_opt_zero
620 ; LOWER: liveins: $x0
622 ; LOWER-NEXT: %reg:_(s64) = COPY $x0
623 ; LOWER-NEXT: %cst:_(s64) = G_CONSTANT i64 0
624 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(ult), %reg(s64), %cst
625 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
626 ; LOWER-NEXT: RET_ReallyLR implicit $w0
627 ; SELECT-LABEL: name: no_opt_zero
628 ; SELECT: liveins: $x0
629 ; SELECT-NEXT: {{ $}}
630 ; SELECT-NEXT: %reg:gpr64sp = COPY $x0
631 ; SELECT-NEXT: [[SUBSXri:%[0-9]+]]:gpr64 = SUBSXri %reg, 0, 0, implicit-def $nzcv
632 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 2, implicit $nzcv
633 ; SELECT-NEXT: $w0 = COPY %cmp
634 ; SELECT-NEXT: RET_ReallyLR implicit $w0
635 %reg:_(s64) = COPY $x0
636 %cst:_(s64) = G_CONSTANT i64 0
637 %cmp:_(s32) = G_ICMP intpred(ult), %reg(s64), %cst
639 RET_ReallyLR implicit $w0
645 tracksRegLiveness: true
649 ; The G_ICMP is optimized here to be a slt comparison by adding 1 to the
650 ; constant. So, the CSELWr should use the predicate code 11, rather than
653 ; LOWER-LABEL: name: cmp_and_select
654 ; LOWER: liveins: $w0, $w1
656 ; LOWER-NEXT: %reg0:_(s32) = COPY $w0
657 ; LOWER-NEXT: %reg1:_(s32) = COPY $w1
658 ; LOWER-NEXT: [[C:%[0-9]+]]:_(s32) = G_CONSTANT i32 0
659 ; LOWER-NEXT: %cmp:_(s32) = G_ICMP intpred(slt), %reg0(s32), [[C]]
660 ; LOWER-NEXT: %select:_(s32) = G_SELECT %cmp(s32), %reg0, %reg1
661 ; LOWER-NEXT: $w0 = COPY %select(s32)
662 ; LOWER-NEXT: RET_ReallyLR implicit $w0
663 ; SELECT-LABEL: name: cmp_and_select
664 ; SELECT: liveins: $w0, $w1
665 ; SELECT-NEXT: {{ $}}
666 ; SELECT-NEXT: %reg0:gpr32common = COPY $w0
667 ; SELECT-NEXT: %reg1:gpr32 = COPY $w1
668 ; SELECT-NEXT: [[SUBSWri:%[0-9]+]]:gpr32 = SUBSWri %reg0, 0, 0, implicit-def $nzcv
669 ; SELECT-NEXT: %select:gpr32 = CSELWr %reg0, %reg1, 11, implicit $nzcv
670 ; SELECT-NEXT: $w0 = COPY %select
671 ; SELECT-NEXT: RET_ReallyLR implicit $w0
672 %reg0:_(s32) = COPY $w0
673 %reg1:_(s32) = COPY $w1
674 %cst:_(s32) = G_CONSTANT i32 -1
675 %cmp:_(s32) = G_ICMP intpred(sle), %reg0(s32), %cst
676 %select:_(s32) = G_SELECT %cmp, %reg0, %reg1
677 $w0 = COPY %select(s32)
678 RET_ReallyLR implicit $w0
684 tracksRegLiveness: true
688 ; Show that we can select a tst/ands by optimizing the G_ICMP in the
691 ; LOWER-LABEL: name: andsxri
692 ; LOWER: liveins: $x0
694 ; LOWER-NEXT: %reg0:gpr(s64) = COPY $x0
695 ; LOWER-NEXT: %bit:gpr(s64) = G_CONSTANT i64 8
696 ; LOWER-NEXT: %and:gpr(s64) = G_AND %reg0, %bit
697 ; LOWER-NEXT: [[C:%[0-9]+]]:gpr(s64) = G_CONSTANT i64 0
698 ; LOWER-NEXT: %cmp:gpr(s32) = G_ICMP intpred(sge), %and(s64), [[C]]
699 ; LOWER-NEXT: $w0 = COPY %cmp(s32)
700 ; LOWER-NEXT: RET_ReallyLR implicit $w0
701 ; SELECT-LABEL: name: andsxri
702 ; SELECT: liveins: $x0
703 ; SELECT-NEXT: {{ $}}
704 ; SELECT-NEXT: %reg0:gpr64 = COPY $x0
705 ; SELECT-NEXT: [[ANDSXri:%[0-9]+]]:gpr64 = ANDSXri %reg0, 8000, implicit-def $nzcv
706 ; SELECT-NEXT: %cmp:gpr32 = CSINCWr $wzr, $wzr, 11, implicit $nzcv
707 ; SELECT-NEXT: $w0 = COPY %cmp
708 ; SELECT-NEXT: RET_ReallyLR implicit $w0
709 %reg0:gpr(s64) = COPY $x0
710 %bit:gpr(s64) = G_CONSTANT i64 8
711 %and:gpr(s64) = G_AND %reg0, %bit
712 %cst:gpr(s64) = G_CONSTANT i64 -1
713 %cmp:gpr(s32) = G_ICMP intpred(sgt), %and(s64), %cst
715 RET_ReallyLR implicit $w0