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 ; TODO: check the generated instructions for the equivalent of seqz, snez,
6 ; sltz, sgtz map to something simple
8 define i32 @icmp_eq(i32 %a, i32 %b) nounwind {
9 ; RV32I-LABEL: icmp_eq:
11 ; RV32I-NEXT: xor a0, a0, a1
12 ; RV32I-NEXT: seqz a0, a0
14 %1 = icmp eq i32 %a, %b
15 %2 = zext i1 %1 to i32
19 define i32 @icmp_eq_constant(i32 %a) nounwind {
20 ; RV32I-LABEL: icmp_eq_constant:
22 ; RV32I-NEXT: addi a0, a0, -42
23 ; RV32I-NEXT: seqz a0, a0
25 %1 = icmp eq i32 %a, 42
26 %2 = zext i1 %1 to i32
30 define i32 @icmp_eq_constant_2048(i32 %a) nounwind {
31 ; RV32I-LABEL: icmp_eq_constant_2048:
33 ; RV32I-NEXT: addi a0, a0, -2048
34 ; RV32I-NEXT: seqz a0, a0
36 %1 = icmp eq i32 %a, 2048
37 %2 = zext i1 %1 to i32
41 define i32 @icmp_eq_constant_neg_2048(i32 %a) nounwind {
42 ; RV32I-LABEL: icmp_eq_constant_neg_2048:
44 ; RV32I-NEXT: addi a1, zero, -2048
45 ; RV32I-NEXT: xor a0, a0, a1
46 ; RV32I-NEXT: seqz a0, a0
48 %1 = icmp eq i32 %a, -2048
49 %2 = zext i1 %1 to i32
53 define i32 @icmp_eq_constant_neg_2047(i32 %a) nounwind {
54 ; RV32I-LABEL: icmp_eq_constant_neg_2047:
56 ; RV32I-NEXT: addi a0, a0, 2047
57 ; RV32I-NEXT: seqz a0, a0
59 %1 = icmp eq i32 %a, -2047
60 %2 = zext i1 %1 to i32
64 define i32 @icmp_eqz(i32 %a) nounwind {
65 ; RV32I-LABEL: icmp_eqz:
67 ; RV32I-NEXT: seqz a0, a0
69 %1 = icmp eq i32 %a, 0
70 %2 = zext i1 %1 to i32
74 define i32 @icmp_ne(i32 %a, i32 %b) nounwind {
75 ; RV32I-LABEL: icmp_ne:
77 ; RV32I-NEXT: xor a0, a0, a1
78 ; RV32I-NEXT: snez a0, a0
80 %1 = icmp ne i32 %a, %b
81 %2 = zext i1 %1 to i32
85 define i32 @icmp_ne_constant(i32 %a) nounwind {
86 ; RV32I-LABEL: icmp_ne_constant:
88 ; RV32I-NEXT: addi a0, a0, -42
89 ; RV32I-NEXT: snez a0, a0
91 %1 = icmp ne i32 %a, 42
92 %2 = zext i1 %1 to i32
96 define i32 @icmp_ne_constant_2048(i32 %a) nounwind {
97 ; RV32I-LABEL: icmp_ne_constant_2048:
99 ; RV32I-NEXT: addi a0, a0, -2048
100 ; RV32I-NEXT: snez a0, a0
102 %1 = icmp ne i32 %a, 2048
103 %2 = zext i1 %1 to i32
107 define i32 @icmp_ne_constant_neg_2048(i32 %a) nounwind {
108 ; RV32I-LABEL: icmp_ne_constant_neg_2048:
110 ; RV32I-NEXT: addi a1, zero, -2048
111 ; RV32I-NEXT: xor a0, a0, a1
112 ; RV32I-NEXT: snez a0, a0
114 %1 = icmp ne i32 %a, -2048
115 %2 = zext i1 %1 to i32
119 define i32 @icmp_nez(i32 %a) nounwind {
120 ; RV32I-LABEL: icmp_nez:
122 ; RV32I-NEXT: snez a0, a0
124 %1 = icmp ne i32 %a, 0
125 %2 = zext i1 %1 to i32
129 define i32 @icmp_ugt(i32 %a, i32 %b) nounwind {
130 ; RV32I-LABEL: icmp_ugt:
132 ; RV32I-NEXT: sltu a0, a1, a0
134 %1 = icmp ugt i32 %a, %b
135 %2 = zext i1 %1 to i32
139 define i32 @icmp_uge(i32 %a, i32 %b) nounwind {
140 ; RV32I-LABEL: icmp_uge:
142 ; RV32I-NEXT: sltu a0, a0, a1
143 ; RV32I-NEXT: xori a0, a0, 1
145 %1 = icmp uge i32 %a, %b
146 %2 = zext i1 %1 to i32
150 define i32 @icmp_ult(i32 %a, i32 %b) nounwind {
151 ; RV32I-LABEL: icmp_ult:
153 ; RV32I-NEXT: sltu a0, a0, a1
155 %1 = icmp ult i32 %a, %b
156 %2 = zext i1 %1 to i32
160 define i32 @icmp_ule(i32 %a, i32 %b) nounwind {
161 ; RV32I-LABEL: icmp_ule:
163 ; RV32I-NEXT: sltu a0, a1, a0
164 ; RV32I-NEXT: xori a0, a0, 1
166 %1 = icmp ule i32 %a, %b
167 %2 = zext i1 %1 to i32
171 define i32 @icmp_sgt(i32 %a, i32 %b) nounwind {
172 ; RV32I-LABEL: icmp_sgt:
174 ; RV32I-NEXT: slt a0, a1, a0
176 %1 = icmp sgt i32 %a, %b
177 %2 = zext i1 %1 to i32
181 define i32 @icmp_sge(i32 %a, i32 %b) nounwind {
182 ; RV32I-LABEL: icmp_sge:
184 ; RV32I-NEXT: slt a0, a0, a1
185 ; RV32I-NEXT: xori a0, a0, 1
187 %1 = icmp sge i32 %a, %b
188 %2 = zext i1 %1 to i32
192 define i32 @icmp_slt(i32 %a, i32 %b) nounwind {
193 ; RV32I-LABEL: icmp_slt:
195 ; RV32I-NEXT: slt a0, a0, a1
197 %1 = icmp slt i32 %a, %b
198 %2 = zext i1 %1 to i32
202 define i32 @icmp_sle(i32 %a, i32 %b) nounwind {
203 ; RV32I-LABEL: icmp_sle:
205 ; RV32I-NEXT: slt a0, a1, a0
206 ; RV32I-NEXT: xori a0, a0, 1
208 %1 = icmp sle i32 %a, %b
209 %2 = zext i1 %1 to i32
213 ; TODO: check variants with an immediate?