1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc --mtriple=loongarch32 < %s | FileCheck %s --check-prefix=LA32
3 ; RUN: llc --mtriple=loongarch64 < %s | FileCheck %s --check-prefix=LA64
5 define signext i32 @select_const_int_one_away(i1 zeroext %a) nounwind {
6 ; LA32-LABEL: select_const_int_one_away:
8 ; LA32-NEXT: ori $a1, $zero, 4
9 ; LA32-NEXT: sub.w $a0, $a1, $a0
12 ; LA64-LABEL: select_const_int_one_away:
14 ; LA64-NEXT: ori $a1, $zero, 4
15 ; LA64-NEXT: sub.d $a0, $a1, $a0
17 %1 = select i1 %a, i32 3, i32 4
21 define signext i32 @select_const_int_pow2_zero(i1 zeroext %a) nounwind {
22 ; LA32-LABEL: select_const_int_pow2_zero:
24 ; LA32-NEXT: slli.w $a0, $a0, 2
27 ; LA64-LABEL: select_const_int_pow2_zero:
29 ; LA64-NEXT: slli.d $a0, $a0, 2
31 %1 = select i1 %a, i32 4, i32 0
35 define signext i32 @select_eq_zero_negone(i32 signext %a, i32 signext %b) nounwind {
36 ; LA32-LABEL: select_eq_zero_negone:
38 ; LA32-NEXT: xor $a0, $a0, $a1
39 ; LA32-NEXT: sltui $a0, $a0, 1
40 ; LA32-NEXT: sub.w $a0, $zero, $a0
43 ; LA64-LABEL: select_eq_zero_negone:
45 ; LA64-NEXT: xor $a0, $a0, $a1
46 ; LA64-NEXT: sltui $a0, $a0, 1
47 ; LA64-NEXT: sub.d $a0, $zero, $a0
49 %1 = icmp eq i32 %a, %b
50 %2 = select i1 %1, i32 -1, i32 0
54 define signext i32 @select_ne_zero_negone(i32 signext %a, i32 signext %b) nounwind {
55 ; LA32-LABEL: select_ne_zero_negone:
57 ; LA32-NEXT: xor $a0, $a0, $a1
58 ; LA32-NEXT: sltu $a0, $zero, $a0
59 ; LA32-NEXT: sub.w $a0, $zero, $a0
62 ; LA64-LABEL: select_ne_zero_negone:
64 ; LA64-NEXT: xor $a0, $a0, $a1
65 ; LA64-NEXT: sltu $a0, $zero, $a0
66 ; LA64-NEXT: sub.d $a0, $zero, $a0
68 %1 = icmp ne i32 %a, %b
69 %2 = select i1 %1, i32 -1, i32 0
73 define signext i32 @select_sgt_zero_negone(i32 signext %a, i32 signext %b) nounwind {
74 ; LA32-LABEL: select_sgt_zero_negone:
76 ; LA32-NEXT: slt $a0, $a1, $a0
77 ; LA32-NEXT: sub.w $a0, $zero, $a0
80 ; LA64-LABEL: select_sgt_zero_negone:
82 ; LA64-NEXT: slt $a0, $a1, $a0
83 ; LA64-NEXT: sub.d $a0, $zero, $a0
85 %1 = icmp sgt i32 %a, %b
86 %2 = select i1 %1, i32 -1, i32 0
90 define signext i32 @select_slt_zero_negone(i32 signext %a, i32 signext %b) nounwind {
91 ; LA32-LABEL: select_slt_zero_negone:
93 ; LA32-NEXT: slt $a0, $a0, $a1
94 ; LA32-NEXT: sub.w $a0, $zero, $a0
97 ; LA64-LABEL: select_slt_zero_negone:
99 ; LA64-NEXT: slt $a0, $a0, $a1
100 ; LA64-NEXT: sub.d $a0, $zero, $a0
102 %1 = icmp slt i32 %a, %b
103 %2 = select i1 %1, i32 -1, i32 0
107 define signext i32 @select_sge_zero_negone(i32 signext %a, i32 signext %b) nounwind {
108 ; LA32-LABEL: select_sge_zero_negone:
110 ; LA32-NEXT: slt $a0, $a0, $a1
111 ; LA32-NEXT: xori $a0, $a0, 1
112 ; LA32-NEXT: sub.w $a0, $zero, $a0
115 ; LA64-LABEL: select_sge_zero_negone:
117 ; LA64-NEXT: slt $a0, $a0, $a1
118 ; LA64-NEXT: xori $a0, $a0, 1
119 ; LA64-NEXT: sub.d $a0, $zero, $a0
121 %1 = icmp sge i32 %a, %b
122 %2 = select i1 %1, i32 -1, i32 0
126 define signext i32 @select_sle_zero_negone(i32 signext %a, i32 signext %b) nounwind {
127 ; LA32-LABEL: select_sle_zero_negone:
129 ; LA32-NEXT: slt $a0, $a1, $a0
130 ; LA32-NEXT: xori $a0, $a0, 1
131 ; LA32-NEXT: sub.w $a0, $zero, $a0
134 ; LA64-LABEL: select_sle_zero_negone:
136 ; LA64-NEXT: slt $a0, $a1, $a0
137 ; LA64-NEXT: xori $a0, $a0, 1
138 ; LA64-NEXT: sub.d $a0, $zero, $a0
140 %1 = icmp sle i32 %a, %b
141 %2 = select i1 %1, i32 -1, i32 0
145 define signext i32 @select_ugt_zero_negone(i32 signext %a, i32 signext %b) nounwind {
146 ; LA32-LABEL: select_ugt_zero_negone:
148 ; LA32-NEXT: sltu $a0, $a1, $a0
149 ; LA32-NEXT: sub.w $a0, $zero, $a0
152 ; LA64-LABEL: select_ugt_zero_negone:
154 ; LA64-NEXT: sltu $a0, $a1, $a0
155 ; LA64-NEXT: sub.d $a0, $zero, $a0
157 %1 = icmp ugt i32 %a, %b
158 %2 = select i1 %1, i32 -1, i32 0
162 define signext i32 @select_ult_zero_negone(i32 signext %a, i32 signext %b) nounwind {
163 ; LA32-LABEL: select_ult_zero_negone:
165 ; LA32-NEXT: sltu $a0, $a0, $a1
166 ; LA32-NEXT: sub.w $a0, $zero, $a0
169 ; LA64-LABEL: select_ult_zero_negone:
171 ; LA64-NEXT: sltu $a0, $a0, $a1
172 ; LA64-NEXT: sub.d $a0, $zero, $a0
174 %1 = icmp ult i32 %a, %b
175 %2 = select i1 %1, i32 -1, i32 0
179 define signext i32 @select_uge_zero_negone(i32 signext %a, i32 signext %b) nounwind {
180 ; LA32-LABEL: select_uge_zero_negone:
182 ; LA32-NEXT: sltu $a0, $a0, $a1
183 ; LA32-NEXT: xori $a0, $a0, 1
184 ; LA32-NEXT: sub.w $a0, $zero, $a0
187 ; LA64-LABEL: select_uge_zero_negone:
189 ; LA64-NEXT: sltu $a0, $a0, $a1
190 ; LA64-NEXT: xori $a0, $a0, 1
191 ; LA64-NEXT: sub.d $a0, $zero, $a0
193 %1 = icmp uge i32 %a, %b
194 %2 = select i1 %1, i32 -1, i32 0
198 define signext i32 @select_ule_zero_negone(i32 signext %a, i32 signext %b) nounwind {
199 ; LA32-LABEL: select_ule_zero_negone:
201 ; LA32-NEXT: sltu $a0, $a1, $a0
202 ; LA32-NEXT: xori $a0, $a0, 1
203 ; LA32-NEXT: sub.w $a0, $zero, $a0
206 ; LA64-LABEL: select_ule_zero_negone:
208 ; LA64-NEXT: sltu $a0, $a1, $a0
209 ; LA64-NEXT: xori $a0, $a0, 1
210 ; LA64-NEXT: sub.d $a0, $zero, $a0
212 %1 = icmp ule i32 %a, %b
213 %2 = select i1 %1, i32 -1, i32 0
217 define i32 @select_eq_1_2(i32 signext %a, i32 signext %b) {
218 ; LA32-LABEL: select_eq_1_2:
220 ; LA32-NEXT: xor $a0, $a0, $a1
221 ; LA32-NEXT: sltui $a0, $a0, 1
222 ; LA32-NEXT: ori $a1, $zero, 2
223 ; LA32-NEXT: sub.w $a0, $a1, $a0
226 ; LA64-LABEL: select_eq_1_2:
228 ; LA64-NEXT: xor $a0, $a0, $a1
229 ; LA64-NEXT: sltui $a0, $a0, 1
230 ; LA64-NEXT: ori $a1, $zero, 2
231 ; LA64-NEXT: sub.d $a0, $a1, $a0
233 %1 = icmp eq i32 %a, %b
234 %2 = select i1 %1, i32 1, i32 2
238 define i32 @select_ne_1_2(i32 signext %a, i32 signext %b) {
239 ; LA32-LABEL: select_ne_1_2:
241 ; LA32-NEXT: xor $a0, $a0, $a1
242 ; LA32-NEXT: sltu $a0, $zero, $a0
243 ; LA32-NEXT: ori $a1, $zero, 2
244 ; LA32-NEXT: sub.w $a0, $a1, $a0
247 ; LA64-LABEL: select_ne_1_2:
249 ; LA64-NEXT: xor $a0, $a0, $a1
250 ; LA64-NEXT: sltu $a0, $zero, $a0
251 ; LA64-NEXT: ori $a1, $zero, 2
252 ; LA64-NEXT: sub.d $a0, $a1, $a0
254 %1 = icmp ne i32 %a, %b
255 %2 = select i1 %1, i32 1, i32 2
259 define i32 @select_eq_10000_10001(i32 signext %a, i32 signext %b) {
260 ; LA32-LABEL: select_eq_10000_10001:
262 ; LA32-NEXT: xor $a0, $a0, $a1
263 ; LA32-NEXT: sltui $a0, $a0, 1
264 ; LA32-NEXT: lu12i.w $a1, 2
265 ; LA32-NEXT: ori $a1, $a1, 1810
266 ; LA32-NEXT: sub.w $a0, $a1, $a0
269 ; LA64-LABEL: select_eq_10000_10001:
271 ; LA64-NEXT: xor $a0, $a0, $a1
272 ; LA64-NEXT: sltui $a0, $a0, 1
273 ; LA64-NEXT: lu12i.w $a1, 2
274 ; LA64-NEXT: ori $a1, $a1, 1810
275 ; LA64-NEXT: sub.d $a0, $a1, $a0
277 %1 = icmp eq i32 %a, %b
278 %2 = select i1 %1, i32 10001, i32 10002
282 define i32 @select_ne_10001_10002(i32 signext %a, i32 signext %b) {
283 ; LA32-LABEL: select_ne_10001_10002:
285 ; LA32-NEXT: xor $a0, $a0, $a1
286 ; LA32-NEXT: sltu $a0, $zero, $a0
287 ; LA32-NEXT: lu12i.w $a1, 2
288 ; LA32-NEXT: ori $a1, $a1, 1810
289 ; LA32-NEXT: sub.w $a0, $a1, $a0
292 ; LA64-LABEL: select_ne_10001_10002:
294 ; LA64-NEXT: xor $a0, $a0, $a1
295 ; LA64-NEXT: sltu $a0, $zero, $a0
296 ; LA64-NEXT: lu12i.w $a1, 2
297 ; LA64-NEXT: ori $a1, $a1, 1810
298 ; LA64-NEXT: sub.d $a0, $a1, $a0
300 %1 = icmp ne i32 %a, %b
301 %2 = select i1 %1, i32 10001, i32 10002