1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32I
5 define i32 @icmp_eq(i32 %a, i32 %b) nounwind {
6 ; RV32I-LABEL: icmp_eq:
8 ; RV32I-NEXT: xor a0, a0, a1
9 ; RV32I-NEXT: seqz a0, a0
11 %1 = icmp eq i32 %a, %b
12 %2 = zext i1 %1 to i32
16 define i32 @icmp_eq_constant(i32 %a) nounwind {
17 ; RV32I-LABEL: icmp_eq_constant:
19 ; RV32I-NEXT: addi a0, a0, -42
20 ; RV32I-NEXT: seqz a0, a0
22 %1 = icmp eq i32 %a, 42
23 %2 = zext i1 %1 to i32
27 define i32 @icmp_eq_constant_2049(i32 %a) nounwind {
28 ; RV32I-LABEL: icmp_eq_constant_2049:
30 ; RV32I-NEXT: lui a1, 1
31 ; RV32I-NEXT: addi a1, a1, -2047
32 ; RV32I-NEXT: xor a0, a0, a1
33 ; RV32I-NEXT: seqz a0, a0
35 %1 = icmp eq i32 %a, 2049
36 %2 = zext i1 %1 to i32
40 define i32 @icmp_eq_constant_2048(i32 %a) nounwind {
41 ; RV32I-LABEL: icmp_eq_constant_2048:
43 ; RV32I-NEXT: addi a0, a0, -2048
44 ; RV32I-NEXT: seqz a0, a0
46 %1 = icmp eq i32 %a, 2048
47 %2 = zext i1 %1 to i32
51 define i32 @icmp_eq_constant_neg_2048(i32 %a) nounwind {
52 ; RV32I-LABEL: icmp_eq_constant_neg_2048:
54 ; RV32I-NEXT: xori a0, a0, -2048
55 ; RV32I-NEXT: seqz a0, a0
57 %1 = icmp eq i32 %a, -2048
58 %2 = zext i1 %1 to i32
62 define i32 @icmp_eq_constant_neg_2047(i32 %a) nounwind {
63 ; RV32I-LABEL: icmp_eq_constant_neg_2047:
65 ; RV32I-NEXT: addi a0, a0, 2047
66 ; RV32I-NEXT: seqz a0, a0
68 %1 = icmp eq i32 %a, -2047
69 %2 = zext i1 %1 to i32
73 define i32 @icmp_eqz(i32 %a) nounwind {
74 ; RV32I-LABEL: icmp_eqz:
76 ; RV32I-NEXT: seqz a0, a0
78 %1 = icmp eq i32 %a, 0
79 %2 = zext i1 %1 to i32
83 define i32 @icmp_ne(i32 %a, i32 %b) nounwind {
84 ; RV32I-LABEL: icmp_ne:
86 ; RV32I-NEXT: xor a0, a0, a1
87 ; RV32I-NEXT: snez a0, a0
89 %1 = icmp ne i32 %a, %b
90 %2 = zext i1 %1 to i32
94 define i32 @icmp_ne_constant(i32 %a) nounwind {
95 ; RV32I-LABEL: icmp_ne_constant:
97 ; RV32I-NEXT: addi a0, a0, -42
98 ; RV32I-NEXT: snez a0, a0
100 %1 = icmp ne i32 %a, 42
101 %2 = zext i1 %1 to i32
105 define i32 @icmp_ne_constant_2049(i32 %a) nounwind {
106 ; RV32I-LABEL: icmp_ne_constant_2049:
108 ; RV32I-NEXT: lui a1, 1
109 ; RV32I-NEXT: addi a1, a1, -2047
110 ; RV32I-NEXT: xor a0, a0, a1
111 ; RV32I-NEXT: snez a0, a0
113 %1 = icmp ne i32 %a, 2049
114 %2 = zext i1 %1 to i32
118 define i32 @icmp_ne_constant_2048(i32 %a) nounwind {
119 ; RV32I-LABEL: icmp_ne_constant_2048:
121 ; RV32I-NEXT: addi a0, a0, -2048
122 ; RV32I-NEXT: snez a0, a0
124 %1 = icmp ne i32 %a, 2048
125 %2 = zext i1 %1 to i32
129 define i32 @icmp_ne_constant_neg_2048(i32 %a) nounwind {
130 ; RV32I-LABEL: icmp_ne_constant_neg_2048:
132 ; RV32I-NEXT: xori a0, a0, -2048
133 ; RV32I-NEXT: snez a0, a0
135 %1 = icmp ne i32 %a, -2048
136 %2 = zext i1 %1 to i32
140 define i32 @icmp_ne_constant_neg_2047(i32 %a) nounwind {
141 ; RV32I-LABEL: icmp_ne_constant_neg_2047:
143 ; RV32I-NEXT: addi a0, a0, 2047
144 ; RV32I-NEXT: snez a0, a0
146 %1 = icmp ne i32 %a, -2047
147 %2 = zext i1 %1 to i32
151 define i32 @icmp_nez(i32 %a) nounwind {
152 ; RV32I-LABEL: icmp_nez:
154 ; RV32I-NEXT: snez a0, a0
156 %1 = icmp ne i32 %a, 0
157 %2 = zext i1 %1 to i32
161 define i32 @icmp_ne_neg_1(i32 %a) nounwind {
162 ; RV32I-LABEL: icmp_ne_neg_1:
164 ; RV32I-NEXT: sltiu a0, a0, -1
166 %1 = icmp ne i32 %a, -1
167 %2 = zext i1 %1 to i32
171 define i32 @icmp_ugt(i32 %a, i32 %b) nounwind {
172 ; RV32I-LABEL: icmp_ugt:
174 ; RV32I-NEXT: sltu a0, a1, a0
176 %1 = icmp ugt i32 %a, %b
177 %2 = zext i1 %1 to i32
181 define i32 @icmp_ugt_constant_zero(i32 %a) nounwind {
182 ; RV32I-LABEL: icmp_ugt_constant_zero:
184 ; RV32I-NEXT: snez a0, a0
186 %1 = icmp ugt i32 %a, 0
187 %2 = zext i1 %1 to i32
191 define i32 @icmp_ugt_constant_2047(i32 %a) nounwind {
192 ; RV32I-LABEL: icmp_ugt_constant_2047:
194 ; RV32I-NEXT: li a1, 2047
195 ; RV32I-NEXT: sltu a0, a1, a0
197 %1 = icmp ugt i32 %a, 2047
198 %2 = zext i1 %1 to i32
202 define i32 @icmp_ugt_constant_2046(i32 %a) nounwind {
203 ; RV32I-LABEL: icmp_ugt_constant_2046:
205 ; RV32I-NEXT: sltiu a0, a0, 2047
206 ; RV32I-NEXT: xori a0, a0, 1
208 %1 = icmp ugt i32 %a, 2046
209 %2 = zext i1 %1 to i32
213 define i32 @icmp_ugt_constant_neg_2049(i32 %a) nounwind {
214 ; RV32I-LABEL: icmp_ugt_constant_neg_2049:
216 ; RV32I-NEXT: sltiu a0, a0, -2048
217 ; RV32I-NEXT: xori a0, a0, 1
219 ; 4294965247 signed extend is -2049
220 %1 = icmp ugt i32 %a, 4294965247
221 %2 = zext i1 %1 to i32
225 define i32 @icmp_ugt_constant_neg_2050(i32 %a) nounwind {
226 ; RV32I-LABEL: icmp_ugt_constant_neg_2050:
228 ; RV32I-NEXT: lui a1, 1048575
229 ; RV32I-NEXT: addi a1, a1, 2046
230 ; RV32I-NEXT: sltu a0, a1, a0
232 ; 4294965246 signed extend is -2050
233 %1 = icmp ugt i32 %a, 4294965246
234 %2 = zext i1 %1 to i32
238 define i32 @icmp_uge(i32 %a, i32 %b) nounwind {
239 ; RV32I-LABEL: icmp_uge:
241 ; RV32I-NEXT: sltu a0, a0, a1
242 ; RV32I-NEXT: xori a0, a0, 1
244 %1 = icmp uge i32 %a, %b
245 %2 = zext i1 %1 to i32
249 define i32 @icmp_uge_constant_zero(i32 %a) nounwind {
250 ; RV32I-LABEL: icmp_uge_constant_zero:
252 ; RV32I-NEXT: li a0, 1
254 %1 = icmp uge i32 %a, 0
255 %2 = zext i1 %1 to i32
259 define i32 @icmp_uge_constant_2047(i32 %a) nounwind {
260 ; RV32I-LABEL: icmp_uge_constant_2047:
262 ; RV32I-NEXT: sltiu a0, a0, 2047
263 ; RV32I-NEXT: xori a0, a0, 1
265 %1 = icmp uge i32 %a, 2047
266 %2 = zext i1 %1 to i32
270 define i32 @icmp_uge_constant_2048(i32 %a) nounwind {
271 ; RV32I-LABEL: icmp_uge_constant_2048:
273 ; RV32I-NEXT: li a1, 2047
274 ; RV32I-NEXT: sltu a0, a1, a0
276 %1 = icmp uge i32 %a, 2048
277 %2 = zext i1 %1 to i32
281 define i32 @icmp_uge_constant_neg_2048(i32 %a) nounwind {
282 ; RV32I-LABEL: icmp_uge_constant_neg_2048:
284 ; RV32I-NEXT: sltiu a0, a0, -2048
285 ; RV32I-NEXT: xori a0, a0, 1
287 ; 4294965248 signed extend is -2048
288 %1 = icmp uge i32 %a, 4294965248
289 %2 = zext i1 %1 to i32
293 define i32 @icmp_uge_constant_neg_2049(i32 %a) nounwind {
294 ; RV32I-LABEL: icmp_uge_constant_neg_2049:
296 ; RV32I-NEXT: lui a1, 1048575
297 ; RV32I-NEXT: addi a1, a1, 2046
298 ; RV32I-NEXT: sltu a0, a1, a0
300 ; 4294965247 signed extend is -2049
301 %1 = icmp uge i32 %a, 4294965247
302 %2 = zext i1 %1 to i32
306 define i32 @icmp_ult(i32 %a, i32 %b) nounwind {
307 ; RV32I-LABEL: icmp_ult:
309 ; RV32I-NEXT: sltu a0, a0, a1
311 %1 = icmp ult i32 %a, %b
312 %2 = zext i1 %1 to i32
316 define i32 @icmp_ult_constant_zero(i32 %a) nounwind {
317 ; RV32I-LABEL: icmp_ult_constant_zero:
319 ; RV32I-NEXT: li a0, 0
321 %1 = icmp ult i32 %a, 0
322 %2 = zext i1 %1 to i32
326 define i32 @icmp_ult_constant_2047(i32 %a) nounwind {
327 ; RV32I-LABEL: icmp_ult_constant_2047:
329 ; RV32I-NEXT: sltiu a0, a0, 2047
331 %1 = icmp ult i32 %a, 2047
332 %2 = zext i1 %1 to i32
336 define i32 @icmp_ult_constant_2048(i32 %a) nounwind {
337 ; RV32I-LABEL: icmp_ult_constant_2048:
339 ; RV32I-NEXT: srli a0, a0, 11
340 ; RV32I-NEXT: seqz a0, a0
342 %1 = icmp ult i32 %a, 2048
343 %2 = zext i1 %1 to i32
347 define i32 @icmp_ult_constant_neg_2048(i32 %a) nounwind {
348 ; RV32I-LABEL: icmp_ult_constant_neg_2048:
350 ; RV32I-NEXT: sltiu a0, a0, -2048
352 ; 4294965248 signed extend is -2048
353 %1 = icmp ult i32 %a, 4294965248
354 %2 = zext i1 %1 to i32
358 define i32 @icmp_ult_constant_neg_2049(i32 %a) nounwind {
359 ; RV32I-LABEL: icmp_ult_constant_neg_2049:
361 ; RV32I-NEXT: lui a1, 1048575
362 ; RV32I-NEXT: addi a1, a1, 2047
363 ; RV32I-NEXT: sltu a0, a0, a1
365 ; 4294965247 signed extend is -2049
366 %1 = icmp ult i32 %a, 4294965247
367 %2 = zext i1 %1 to i32
371 define i32 @icmp_ule(i32 %a, i32 %b) nounwind {
372 ; RV32I-LABEL: icmp_ule:
374 ; RV32I-NEXT: sltu a0, a1, a0
375 ; RV32I-NEXT: xori a0, a0, 1
377 %1 = icmp ule i32 %a, %b
378 %2 = zext i1 %1 to i32
382 define i32 @icmp_ule_constant_zero(i32 %a) nounwind {
383 ; RV32I-LABEL: icmp_ule_constant_zero:
385 ; RV32I-NEXT: seqz a0, a0
387 %1 = icmp ule i32 %a, 0
388 %2 = zext i1 %1 to i32
392 define i32 @icmp_ule_constant_2046(i32 %a) nounwind {
393 ; RV32I-LABEL: icmp_ule_constant_2046:
395 ; RV32I-NEXT: sltiu a0, a0, 2047
397 %1 = icmp ule i32 %a, 2046
398 %2 = zext i1 %1 to i32
402 define i32 @icmp_ule_constant_2047(i32 %a) nounwind {
403 ; RV32I-LABEL: icmp_ule_constant_2047:
405 ; RV32I-NEXT: srli a0, a0, 11
406 ; RV32I-NEXT: seqz a0, a0
408 %1 = icmp ule i32 %a, 2047
409 %2 = zext i1 %1 to i32
413 define i32 @icmp_ule_constant_neg_2049(i32 %a) nounwind {
414 ; RV32I-LABEL: icmp_ule_constant_neg_2049:
416 ; RV32I-NEXT: sltiu a0, a0, -2048
418 ; 4294965247 signed extend is -2049
419 %1 = icmp ule i32 %a, 4294965247
420 %2 = zext i1 %1 to i32
424 define i32 @icmp_ule_constant_neg_2050(i32 %a) nounwind {
425 ; RV32I-LABEL: icmp_ule_constant_neg_2050:
427 ; RV32I-NEXT: lui a1, 1048575
428 ; RV32I-NEXT: addi a1, a1, 2047
429 ; RV32I-NEXT: sltu a0, a0, a1
431 ; 4294965246 signed extend is -2050
432 %1 = icmp ule i32 %a, 4294965246
433 %2 = zext i1 %1 to i32
437 define i32 @icmp_sgt(i32 %a, i32 %b) nounwind {
438 ; RV32I-LABEL: icmp_sgt:
440 ; RV32I-NEXT: slt a0, a1, a0
442 %1 = icmp sgt i32 %a, %b
443 %2 = zext i1 %1 to i32
447 define i32 @icmp_sgt_constant_zero(i32 %a) nounwind {
448 ; RV32I-LABEL: icmp_sgt_constant_zero:
450 ; RV32I-NEXT: sgtz a0, a0
452 %1 = icmp sgt i32 %a, 0
453 %2 = zext i1 %1 to i32
457 define i32 @icmp_sgt_constant_2046(i32 %a) nounwind {
458 ; RV32I-LABEL: icmp_sgt_constant_2046:
460 ; RV32I-NEXT: slti a0, a0, 2047
461 ; RV32I-NEXT: xori a0, a0, 1
463 %1 = icmp sgt i32 %a, 2046
464 %2 = zext i1 %1 to i32
468 define i32 @icmp_sgt_constant_2047(i32 %a) nounwind {
469 ; RV32I-LABEL: icmp_sgt_constant_2047:
471 ; RV32I-NEXT: li a1, 2047
472 ; RV32I-NEXT: slt a0, a1, a0
474 %1 = icmp sgt i32 %a, 2047
475 %2 = zext i1 %1 to i32
479 define i32 @icmp_sgt_constant_neg_2049(i32 %a) nounwind {
480 ; RV32I-LABEL: icmp_sgt_constant_neg_2049:
482 ; RV32I-NEXT: slti a0, a0, -2048
483 ; RV32I-NEXT: xori a0, a0, 1
485 %1 = icmp sgt i32 %a, -2049
486 %2 = zext i1 %1 to i32
490 define i32 @icmp_sgt_constant_neg_2050(i32 %a) nounwind {
491 ; RV32I-LABEL: icmp_sgt_constant_neg_2050:
493 ; RV32I-NEXT: lui a1, 1048575
494 ; RV32I-NEXT: addi a1, a1, 2046
495 ; RV32I-NEXT: slt a0, a1, a0
497 %1 = icmp sgt i32 %a, -2050
498 %2 = zext i1 %1 to i32
502 define i32 @icmp_sge(i32 %a, i32 %b) nounwind {
503 ; RV32I-LABEL: icmp_sge:
505 ; RV32I-NEXT: slt a0, a0, a1
506 ; RV32I-NEXT: xori a0, a0, 1
508 %1 = icmp sge i32 %a, %b
509 %2 = zext i1 %1 to i32
513 define i32 @icmp_sge_constant_zero(i32 %a) nounwind {
514 ; RV32I-LABEL: icmp_sge_constant_zero:
516 ; RV32I-NEXT: not a0, a0
517 ; RV32I-NEXT: srli a0, a0, 31
519 %1 = icmp sge i32 %a, 0
520 %2 = zext i1 %1 to i32
524 define i32 @icmp_sge_constant_2047(i32 %a) nounwind {
525 ; RV32I-LABEL: icmp_sge_constant_2047:
527 ; RV32I-NEXT: slti a0, a0, 2047
528 ; RV32I-NEXT: xori a0, a0, 1
530 %1 = icmp sge i32 %a, 2047
531 %2 = zext i1 %1 to i32
535 define i32 @icmp_sge_constant_2048(i32 %a) nounwind {
536 ; RV32I-LABEL: icmp_sge_constant_2048:
538 ; RV32I-NEXT: li a1, 2047
539 ; RV32I-NEXT: slt a0, a1, a0
541 %1 = icmp sge i32 %a, 2048
542 %2 = zext i1 %1 to i32
546 define i32 @icmp_sge_constant_neg_2047(i32 %a) nounwind {
547 ; RV32I-LABEL: icmp_sge_constant_neg_2047:
549 ; RV32I-NEXT: slti a0, a0, -2047
550 ; RV32I-NEXT: xori a0, a0, 1
552 %1 = icmp sge i32 %a, -2047
553 %2 = zext i1 %1 to i32
557 define i32 @icmp_sge_constant_neg_2048(i32 %a) nounwind {
558 ; RV32I-LABEL: icmp_sge_constant_neg_2048:
560 ; RV32I-NEXT: not a0, a0
561 ; RV32I-NEXT: srli a0, a0, 31
563 %1 = icmp sge i32 %a, 0
564 %2 = zext i1 %1 to i32
568 define i32 @icmp_slt(i32 %a, i32 %b) nounwind {
569 ; RV32I-LABEL: icmp_slt:
571 ; RV32I-NEXT: slt a0, a0, a1
573 %1 = icmp slt i32 %a, %b
574 %2 = zext i1 %1 to i32
578 define i32 @icmp_slt_constant_zero(i32 %a) nounwind {
579 ; RV32I-LABEL: icmp_slt_constant_zero:
581 ; RV32I-NEXT: srli a0, a0, 31
583 %1 = icmp slt i32 %a, 0
584 %2 = zext i1 %1 to i32
588 define i32 @icmp_slt_constant_2047(i32 %a) nounwind {
589 ; RV32I-LABEL: icmp_slt_constant_2047:
591 ; RV32I-NEXT: slti a0, a0, 2047
593 %1 = icmp slt i32 %a, 2047
594 %2 = zext i1 %1 to i32
598 define i32 @icmp_slt_constant_2048(i32 %a) nounwind {
599 ; RV32I-LABEL: icmp_slt_constant_2048:
601 ; RV32I-NEXT: li a1, 1
602 ; RV32I-NEXT: slli a1, a1, 11
603 ; RV32I-NEXT: slt a0, a0, a1
605 %1 = icmp slt i32 %a, 2048
606 %2 = zext i1 %1 to i32
610 define i32 @icmp_slt_constant_neg_2048(i32 %a) nounwind {
611 ; RV32I-LABEL: icmp_slt_constant_neg_2048:
613 ; RV32I-NEXT: slti a0, a0, -2048
615 %1 = icmp slt i32 %a, -2048
616 %2 = zext i1 %1 to i32
620 define i32 @icmp_slt_constant_neg_2049(i32 %a) nounwind {
621 ; RV32I-LABEL: icmp_slt_constant_neg_2049:
623 ; RV32I-NEXT: lui a1, 1048575
624 ; RV32I-NEXT: addi a1, a1, 2047
625 ; RV32I-NEXT: slt a0, a0, a1
627 %1 = icmp slt i32 %a, -2049
628 %2 = zext i1 %1 to i32
632 define i32 @icmp_sle(i32 %a, i32 %b) nounwind {
633 ; RV32I-LABEL: icmp_sle:
635 ; RV32I-NEXT: slt a0, a1, a0
636 ; RV32I-NEXT: xori a0, a0, 1
638 %1 = icmp sle i32 %a, %b
639 %2 = zext i1 %1 to i32
643 define i32 @icmp_sle_constant_zero(i32 %a) nounwind {
644 ; RV32I-LABEL: icmp_sle_constant_zero:
646 ; RV32I-NEXT: slti a0, a0, 1
648 %1 = icmp sle i32 %a, 0
649 %2 = zext i1 %1 to i32
653 define i32 @icmp_sle_constant_2046(i32 %a) nounwind {
654 ; RV32I-LABEL: icmp_sle_constant_2046:
656 ; RV32I-NEXT: slti a0, a0, 2047
658 %1 = icmp sle i32 %a, 2046
659 %2 = zext i1 %1 to i32
663 define i32 @icmp_sle_constant_2047(i32 %a) nounwind {
664 ; RV32I-LABEL: icmp_sle_constant_2047:
666 ; RV32I-NEXT: li a1, 1
667 ; RV32I-NEXT: slli a1, a1, 11
668 ; RV32I-NEXT: slt a0, a0, a1
670 %1 = icmp sle i32 %a, 2047
671 %2 = zext i1 %1 to i32
675 define i32 @icmp_sle_constant_neg_2049(i32 %a) nounwind {
676 ; RV32I-LABEL: icmp_sle_constant_neg_2049:
678 ; RV32I-NEXT: slti a0, a0, -2048
680 %1 = icmp sle i32 %a, -2049
681 %2 = zext i1 %1 to i32
685 define i32 @icmp_sle_constant_neg_2050(i32 %a) nounwind {
686 ; RV32I-LABEL: icmp_sle_constant_neg_2050:
688 ; RV32I-NEXT: lui a1, 1048575
689 ; RV32I-NEXT: addi a1, a1, 2047
690 ; RV32I-NEXT: slt a0, a0, a1
692 %1 = icmp sle i32 %a, -2050
693 %2 = zext i1 %1 to i32