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-prefixes=CHECK,RV32I
4 ; RUN: llc -mtriple=riscv32 -mattr=+zbb -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefixes=CHECK,RV32ZBB
7 declare i32 @llvm.ctlz.i32(i32, i1)
9 define i32 @ctlz_i32(i32 %a) nounwind {
10 ; RV32I-LABEL: ctlz_i32:
12 ; RV32I-NEXT: beqz a0, .LBB0_2
13 ; RV32I-NEXT: # %bb.1: # %cond.false
14 ; RV32I-NEXT: addi sp, sp, -16
15 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
16 ; RV32I-NEXT: srli a1, a0, 1
17 ; RV32I-NEXT: or a0, a0, a1
18 ; RV32I-NEXT: srli a1, a0, 2
19 ; RV32I-NEXT: or a0, a0, a1
20 ; RV32I-NEXT: srli a1, a0, 4
21 ; RV32I-NEXT: or a0, a0, a1
22 ; RV32I-NEXT: srli a1, a0, 8
23 ; RV32I-NEXT: or a0, a0, a1
24 ; RV32I-NEXT: srli a1, a0, 16
25 ; RV32I-NEXT: or a0, a0, a1
26 ; RV32I-NEXT: not a0, a0
27 ; RV32I-NEXT: srli a1, a0, 1
28 ; RV32I-NEXT: lui a2, 349525
29 ; RV32I-NEXT: addi a2, a2, 1365
30 ; RV32I-NEXT: and a1, a1, a2
31 ; RV32I-NEXT: sub a0, a0, a1
32 ; RV32I-NEXT: lui a1, 209715
33 ; RV32I-NEXT: addi a1, a1, 819
34 ; RV32I-NEXT: and a2, a0, a1
35 ; RV32I-NEXT: srli a0, a0, 2
36 ; RV32I-NEXT: and a0, a0, a1
37 ; RV32I-NEXT: add a0, a2, a0
38 ; RV32I-NEXT: srli a1, a0, 4
39 ; RV32I-NEXT: add a0, a0, a1
40 ; RV32I-NEXT: lui a1, 61681
41 ; RV32I-NEXT: addi a1, a1, -241
42 ; RV32I-NEXT: and a0, a0, a1
43 ; RV32I-NEXT: lui a1, 4112
44 ; RV32I-NEXT: addi a1, a1, 257
45 ; RV32I-NEXT: call __mulsi3
46 ; RV32I-NEXT: srli a0, a0, 24
47 ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
48 ; RV32I-NEXT: addi sp, sp, 16
50 ; RV32I-NEXT: .LBB0_2:
51 ; RV32I-NEXT: li a0, 32
54 ; RV32ZBB-LABEL: ctlz_i32:
56 ; RV32ZBB-NEXT: clz a0, a0
58 %1 = call i32 @llvm.ctlz.i32(i32 %a, i1 false)
62 declare i64 @llvm.ctlz.i64(i64, i1)
64 define i64 @ctlz_i64(i64 %a) nounwind {
65 ; RV32I-LABEL: ctlz_i64:
67 ; RV32I-NEXT: addi sp, sp, -32
68 ; RV32I-NEXT: sw ra, 28(sp) # 4-byte Folded Spill
69 ; RV32I-NEXT: sw s0, 24(sp) # 4-byte Folded Spill
70 ; RV32I-NEXT: sw s1, 20(sp) # 4-byte Folded Spill
71 ; RV32I-NEXT: sw s2, 16(sp) # 4-byte Folded Spill
72 ; RV32I-NEXT: sw s3, 12(sp) # 4-byte Folded Spill
73 ; RV32I-NEXT: sw s4, 8(sp) # 4-byte Folded Spill
74 ; RV32I-NEXT: sw s5, 4(sp) # 4-byte Folded Spill
75 ; RV32I-NEXT: sw s6, 0(sp) # 4-byte Folded Spill
76 ; RV32I-NEXT: mv s0, a1
77 ; RV32I-NEXT: mv s2, a0
78 ; RV32I-NEXT: srli a0, a1, 1
79 ; RV32I-NEXT: or a0, a1, a0
80 ; RV32I-NEXT: srli a1, a0, 2
81 ; RV32I-NEXT: or a0, a0, a1
82 ; RV32I-NEXT: srli a1, a0, 4
83 ; RV32I-NEXT: or a0, a0, a1
84 ; RV32I-NEXT: srli a1, a0, 8
85 ; RV32I-NEXT: or a0, a0, a1
86 ; RV32I-NEXT: srli a1, a0, 16
87 ; RV32I-NEXT: or a0, a0, a1
88 ; RV32I-NEXT: not a0, a0
89 ; RV32I-NEXT: srli a1, a0, 1
90 ; RV32I-NEXT: lui a2, 349525
91 ; RV32I-NEXT: addi s4, a2, 1365
92 ; RV32I-NEXT: and a1, a1, s4
93 ; RV32I-NEXT: sub a0, a0, a1
94 ; RV32I-NEXT: lui a1, 209715
95 ; RV32I-NEXT: addi s5, a1, 819
96 ; RV32I-NEXT: and a1, a0, s5
97 ; RV32I-NEXT: srli a0, a0, 2
98 ; RV32I-NEXT: and a0, a0, s5
99 ; RV32I-NEXT: add a0, a1, a0
100 ; RV32I-NEXT: srli a1, a0, 4
101 ; RV32I-NEXT: add a0, a0, a1
102 ; RV32I-NEXT: lui a1, 61681
103 ; RV32I-NEXT: addi s6, a1, -241
104 ; RV32I-NEXT: and a0, a0, s6
105 ; RV32I-NEXT: lui a1, 4112
106 ; RV32I-NEXT: addi s3, a1, 257
107 ; RV32I-NEXT: mv a1, s3
108 ; RV32I-NEXT: call __mulsi3
109 ; RV32I-NEXT: mv s1, a0
110 ; RV32I-NEXT: srli a0, s2, 1
111 ; RV32I-NEXT: or a0, s2, a0
112 ; RV32I-NEXT: srli a1, a0, 2
113 ; RV32I-NEXT: or a0, a0, a1
114 ; RV32I-NEXT: srli a1, a0, 4
115 ; RV32I-NEXT: or a0, a0, a1
116 ; RV32I-NEXT: srli a1, a0, 8
117 ; RV32I-NEXT: or a0, a0, a1
118 ; RV32I-NEXT: srli a1, a0, 16
119 ; RV32I-NEXT: or a0, a0, a1
120 ; RV32I-NEXT: not a0, a0
121 ; RV32I-NEXT: srli a1, a0, 1
122 ; RV32I-NEXT: and a1, a1, s4
123 ; RV32I-NEXT: sub a0, a0, a1
124 ; RV32I-NEXT: and a1, a0, s5
125 ; RV32I-NEXT: srli a0, a0, 2
126 ; RV32I-NEXT: and a0, a0, s5
127 ; RV32I-NEXT: add a0, a1, a0
128 ; RV32I-NEXT: srli a1, a0, 4
129 ; RV32I-NEXT: add a0, a0, a1
130 ; RV32I-NEXT: and a0, a0, s6
131 ; RV32I-NEXT: mv a1, s3
132 ; RV32I-NEXT: call __mulsi3
133 ; RV32I-NEXT: bnez s0, .LBB1_2
134 ; RV32I-NEXT: # %bb.1:
135 ; RV32I-NEXT: srli a0, a0, 24
136 ; RV32I-NEXT: addi a0, a0, 32
137 ; RV32I-NEXT: j .LBB1_3
138 ; RV32I-NEXT: .LBB1_2:
139 ; RV32I-NEXT: srli a0, s1, 24
140 ; RV32I-NEXT: .LBB1_3:
141 ; RV32I-NEXT: li a1, 0
142 ; RV32I-NEXT: lw ra, 28(sp) # 4-byte Folded Reload
143 ; RV32I-NEXT: lw s0, 24(sp) # 4-byte Folded Reload
144 ; RV32I-NEXT: lw s1, 20(sp) # 4-byte Folded Reload
145 ; RV32I-NEXT: lw s2, 16(sp) # 4-byte Folded Reload
146 ; RV32I-NEXT: lw s3, 12(sp) # 4-byte Folded Reload
147 ; RV32I-NEXT: lw s4, 8(sp) # 4-byte Folded Reload
148 ; RV32I-NEXT: lw s5, 4(sp) # 4-byte Folded Reload
149 ; RV32I-NEXT: lw s6, 0(sp) # 4-byte Folded Reload
150 ; RV32I-NEXT: addi sp, sp, 32
153 ; RV32ZBB-LABEL: ctlz_i64:
155 ; RV32ZBB-NEXT: bnez a1, .LBB1_2
156 ; RV32ZBB-NEXT: # %bb.1:
157 ; RV32ZBB-NEXT: clz a0, a0
158 ; RV32ZBB-NEXT: addi a0, a0, 32
159 ; RV32ZBB-NEXT: li a1, 0
161 ; RV32ZBB-NEXT: .LBB1_2:
162 ; RV32ZBB-NEXT: clz a0, a1
163 ; RV32ZBB-NEXT: li a1, 0
165 %1 = call i64 @llvm.ctlz.i64(i64 %a, i1 false)
169 declare i32 @llvm.cttz.i32(i32, i1)
171 define i32 @cttz_i32(i32 %a) nounwind {
172 ; RV32I-LABEL: cttz_i32:
174 ; RV32I-NEXT: beqz a0, .LBB2_2
175 ; RV32I-NEXT: # %bb.1: # %cond.false
176 ; RV32I-NEXT: addi sp, sp, -16
177 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
178 ; RV32I-NEXT: neg a1, a0
179 ; RV32I-NEXT: and a0, a0, a1
180 ; RV32I-NEXT: lui a1, 30667
181 ; RV32I-NEXT: addi a1, a1, 1329
182 ; RV32I-NEXT: call __mulsi3
183 ; RV32I-NEXT: srli a0, a0, 27
184 ; RV32I-NEXT: lui a1, %hi(.LCPI2_0)
185 ; RV32I-NEXT: addi a1, a1, %lo(.LCPI2_0)
186 ; RV32I-NEXT: add a0, a1, a0
187 ; RV32I-NEXT: lbu a0, 0(a0)
188 ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
189 ; RV32I-NEXT: addi sp, sp, 16
191 ; RV32I-NEXT: .LBB2_2:
192 ; RV32I-NEXT: li a0, 32
195 ; RV32ZBB-LABEL: cttz_i32:
197 ; RV32ZBB-NEXT: ctz a0, a0
199 %1 = call i32 @llvm.cttz.i32(i32 %a, i1 false)
203 declare i64 @llvm.cttz.i64(i64, i1)
205 define i64 @cttz_i64(i64 %a) nounwind {
206 ; RV32I-LABEL: cttz_i64:
208 ; RV32I-NEXT: addi sp, sp, -32
209 ; RV32I-NEXT: sw ra, 28(sp) # 4-byte Folded Spill
210 ; RV32I-NEXT: sw s0, 24(sp) # 4-byte Folded Spill
211 ; RV32I-NEXT: sw s1, 20(sp) # 4-byte Folded Spill
212 ; RV32I-NEXT: sw s2, 16(sp) # 4-byte Folded Spill
213 ; RV32I-NEXT: sw s3, 12(sp) # 4-byte Folded Spill
214 ; RV32I-NEXT: sw s4, 8(sp) # 4-byte Folded Spill
215 ; RV32I-NEXT: mv s2, a1
216 ; RV32I-NEXT: mv s0, a0
217 ; RV32I-NEXT: neg a0, a0
218 ; RV32I-NEXT: and a0, s0, a0
219 ; RV32I-NEXT: lui a1, 30667
220 ; RV32I-NEXT: addi s3, a1, 1329
221 ; RV32I-NEXT: mv a1, s3
222 ; RV32I-NEXT: call __mulsi3
223 ; RV32I-NEXT: mv s1, a0
224 ; RV32I-NEXT: lui a0, %hi(.LCPI3_0)
225 ; RV32I-NEXT: addi s4, a0, %lo(.LCPI3_0)
226 ; RV32I-NEXT: neg a0, s2
227 ; RV32I-NEXT: and a0, s2, a0
228 ; RV32I-NEXT: mv a1, s3
229 ; RV32I-NEXT: call __mulsi3
230 ; RV32I-NEXT: bnez s2, .LBB3_3
231 ; RV32I-NEXT: # %bb.1:
232 ; RV32I-NEXT: li a0, 32
233 ; RV32I-NEXT: beqz s0, .LBB3_4
234 ; RV32I-NEXT: .LBB3_2:
235 ; RV32I-NEXT: srli s1, s1, 27
236 ; RV32I-NEXT: add s1, s4, s1
237 ; RV32I-NEXT: lbu a0, 0(s1)
238 ; RV32I-NEXT: j .LBB3_5
239 ; RV32I-NEXT: .LBB3_3:
240 ; RV32I-NEXT: srli a0, a0, 27
241 ; RV32I-NEXT: add a0, s4, a0
242 ; RV32I-NEXT: lbu a0, 0(a0)
243 ; RV32I-NEXT: bnez s0, .LBB3_2
244 ; RV32I-NEXT: .LBB3_4:
245 ; RV32I-NEXT: addi a0, a0, 32
246 ; RV32I-NEXT: .LBB3_5:
247 ; RV32I-NEXT: li a1, 0
248 ; RV32I-NEXT: lw ra, 28(sp) # 4-byte Folded Reload
249 ; RV32I-NEXT: lw s0, 24(sp) # 4-byte Folded Reload
250 ; RV32I-NEXT: lw s1, 20(sp) # 4-byte Folded Reload
251 ; RV32I-NEXT: lw s2, 16(sp) # 4-byte Folded Reload
252 ; RV32I-NEXT: lw s3, 12(sp) # 4-byte Folded Reload
253 ; RV32I-NEXT: lw s4, 8(sp) # 4-byte Folded Reload
254 ; RV32I-NEXT: addi sp, sp, 32
257 ; RV32ZBB-LABEL: cttz_i64:
259 ; RV32ZBB-NEXT: bnez a0, .LBB3_2
260 ; RV32ZBB-NEXT: # %bb.1:
261 ; RV32ZBB-NEXT: ctz a0, a1
262 ; RV32ZBB-NEXT: addi a0, a0, 32
263 ; RV32ZBB-NEXT: li a1, 0
265 ; RV32ZBB-NEXT: .LBB3_2:
266 ; RV32ZBB-NEXT: ctz a0, a0
267 ; RV32ZBB-NEXT: li a1, 0
269 %1 = call i64 @llvm.cttz.i64(i64 %a, i1 false)
273 declare i32 @llvm.ctpop.i32(i32)
275 define i32 @ctpop_i32(i32 %a) nounwind {
276 ; RV32I-LABEL: ctpop_i32:
278 ; RV32I-NEXT: addi sp, sp, -16
279 ; RV32I-NEXT: sw ra, 12(sp) # 4-byte Folded Spill
280 ; RV32I-NEXT: srli a1, a0, 1
281 ; RV32I-NEXT: lui a2, 349525
282 ; RV32I-NEXT: addi a2, a2, 1365
283 ; RV32I-NEXT: and a1, a1, a2
284 ; RV32I-NEXT: sub a0, a0, a1
285 ; RV32I-NEXT: lui a1, 209715
286 ; RV32I-NEXT: addi a1, a1, 819
287 ; RV32I-NEXT: and a2, a0, a1
288 ; RV32I-NEXT: srli a0, a0, 2
289 ; RV32I-NEXT: and a0, a0, a1
290 ; RV32I-NEXT: add a0, a2, a0
291 ; RV32I-NEXT: srli a1, a0, 4
292 ; RV32I-NEXT: add a0, a0, a1
293 ; RV32I-NEXT: lui a1, 61681
294 ; RV32I-NEXT: addi a1, a1, -241
295 ; RV32I-NEXT: and a0, a0, a1
296 ; RV32I-NEXT: lui a1, 4112
297 ; RV32I-NEXT: addi a1, a1, 257
298 ; RV32I-NEXT: call __mulsi3
299 ; RV32I-NEXT: srli a0, a0, 24
300 ; RV32I-NEXT: lw ra, 12(sp) # 4-byte Folded Reload
301 ; RV32I-NEXT: addi sp, sp, 16
304 ; RV32ZBB-LABEL: ctpop_i32:
306 ; RV32ZBB-NEXT: cpop a0, a0
308 %1 = call i32 @llvm.ctpop.i32(i32 %a)
312 define i1 @ctpop_i32_ult_two(i32 signext %a) nounwind {
313 ; RV32I-LABEL: ctpop_i32_ult_two:
315 ; RV32I-NEXT: addi a1, a0, -1
316 ; RV32I-NEXT: and a0, a0, a1
317 ; RV32I-NEXT: seqz a0, a0
320 ; RV32ZBB-LABEL: ctpop_i32_ult_two:
322 ; RV32ZBB-NEXT: cpop a0, a0
323 ; RV32ZBB-NEXT: sltiu a0, a0, 2
325 %1 = call i32 @llvm.ctpop.i32(i32 %a)
326 %2 = icmp ult i32 %1, 2
330 define i1 @ctpop_i32_ugt_one(i32 signext %a) nounwind {
331 ; RV32I-LABEL: ctpop_i32_ugt_one:
333 ; RV32I-NEXT: addi a1, a0, -1
334 ; RV32I-NEXT: and a0, a0, a1
335 ; RV32I-NEXT: snez a0, a0
338 ; RV32ZBB-LABEL: ctpop_i32_ugt_one:
340 ; RV32ZBB-NEXT: cpop a0, a0
341 ; RV32ZBB-NEXT: sltiu a0, a0, 2
342 ; RV32ZBB-NEXT: xori a0, a0, 1
344 %1 = call i32 @llvm.ctpop.i32(i32 %a)
345 %2 = icmp ugt i32 %1, 1
349 define i1 @ctpop_i32_eq_one(i32 signext %a) nounwind {
350 ; RV32I-LABEL: ctpop_i32_eq_one:
352 ; RV32I-NEXT: addi a1, a0, -1
353 ; RV32I-NEXT: xor a0, a0, a1
354 ; RV32I-NEXT: sltu a0, a1, a0
357 ; RV32ZBB-LABEL: ctpop_i32_eq_one:
359 ; RV32ZBB-NEXT: cpop a0, a0
360 ; RV32ZBB-NEXT: addi a0, a0, -1
361 ; RV32ZBB-NEXT: seqz a0, a0
363 %1 = call i32 @llvm.ctpop.i32(i32 %a)
364 %2 = icmp eq i32 %1, 1
368 define i1 @ctpop_i32_ne_one(i32 signext %a) nounwind {
369 ; RV32I-LABEL: ctpop_i32_ne_one:
371 ; RV32I-NEXT: addi a1, a0, -1
372 ; RV32I-NEXT: xor a0, a0, a1
373 ; RV32I-NEXT: sltu a0, a1, a0
374 ; RV32I-NEXT: xori a0, a0, 1
377 ; RV32ZBB-LABEL: ctpop_i32_ne_one:
379 ; RV32ZBB-NEXT: cpop a0, a0
380 ; RV32ZBB-NEXT: addi a0, a0, -1
381 ; RV32ZBB-NEXT: snez a0, a0
383 %1 = call i32 @llvm.ctpop.i32(i32 %a)
384 %2 = icmp ne i32 %1, 1
388 declare <2 x i32> @llvm.ctpop.v2i32(<2 x i32>)
390 define <2 x i32> @ctpop_v2i32(<2 x i32> %a) nounwind {
391 ; RV32I-LABEL: ctpop_v2i32:
393 ; RV32I-NEXT: addi sp, sp, -32
394 ; RV32I-NEXT: sw ra, 28(sp) # 4-byte Folded Spill
395 ; RV32I-NEXT: sw s0, 24(sp) # 4-byte Folded Spill
396 ; RV32I-NEXT: sw s1, 20(sp) # 4-byte Folded Spill
397 ; RV32I-NEXT: sw s2, 16(sp) # 4-byte Folded Spill
398 ; RV32I-NEXT: sw s3, 12(sp) # 4-byte Folded Spill
399 ; RV32I-NEXT: sw s4, 8(sp) # 4-byte Folded Spill
400 ; RV32I-NEXT: sw s5, 4(sp) # 4-byte Folded Spill
401 ; RV32I-NEXT: mv s0, a1
402 ; RV32I-NEXT: srli a1, a0, 1
403 ; RV32I-NEXT: lui a2, 349525
404 ; RV32I-NEXT: addi s3, a2, 1365
405 ; RV32I-NEXT: and a1, a1, s3
406 ; RV32I-NEXT: sub a0, a0, a1
407 ; RV32I-NEXT: lui a1, 209715
408 ; RV32I-NEXT: addi s4, a1, 819
409 ; RV32I-NEXT: and a1, a0, s4
410 ; RV32I-NEXT: srli a0, a0, 2
411 ; RV32I-NEXT: and a0, a0, s4
412 ; RV32I-NEXT: add a0, a1, a0
413 ; RV32I-NEXT: srli a1, a0, 4
414 ; RV32I-NEXT: add a0, a0, a1
415 ; RV32I-NEXT: lui a1, 61681
416 ; RV32I-NEXT: addi s5, a1, -241
417 ; RV32I-NEXT: and a0, a0, s5
418 ; RV32I-NEXT: lui a1, 4112
419 ; RV32I-NEXT: addi s1, a1, 257
420 ; RV32I-NEXT: mv a1, s1
421 ; RV32I-NEXT: call __mulsi3
422 ; RV32I-NEXT: srli s2, a0, 24
423 ; RV32I-NEXT: srli a0, s0, 1
424 ; RV32I-NEXT: and a0, a0, s3
425 ; RV32I-NEXT: sub s0, s0, a0
426 ; RV32I-NEXT: and a0, s0, s4
427 ; RV32I-NEXT: srli s0, s0, 2
428 ; RV32I-NEXT: and a1, s0, s4
429 ; RV32I-NEXT: add a0, a0, a1
430 ; RV32I-NEXT: srli a1, a0, 4
431 ; RV32I-NEXT: add a0, a0, a1
432 ; RV32I-NEXT: and a0, a0, s5
433 ; RV32I-NEXT: mv a1, s1
434 ; RV32I-NEXT: call __mulsi3
435 ; RV32I-NEXT: srli a1, a0, 24
436 ; RV32I-NEXT: mv a0, s2
437 ; RV32I-NEXT: lw ra, 28(sp) # 4-byte Folded Reload
438 ; RV32I-NEXT: lw s0, 24(sp) # 4-byte Folded Reload
439 ; RV32I-NEXT: lw s1, 20(sp) # 4-byte Folded Reload
440 ; RV32I-NEXT: lw s2, 16(sp) # 4-byte Folded Reload
441 ; RV32I-NEXT: lw s3, 12(sp) # 4-byte Folded Reload
442 ; RV32I-NEXT: lw s4, 8(sp) # 4-byte Folded Reload
443 ; RV32I-NEXT: lw s5, 4(sp) # 4-byte Folded Reload
444 ; RV32I-NEXT: addi sp, sp, 32
447 ; RV32ZBB-LABEL: ctpop_v2i32:
449 ; RV32ZBB-NEXT: cpop a0, a0
450 ; RV32ZBB-NEXT: cpop a1, a1
452 %1 = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %a)
456 define <2 x i1> @ctpop_v2i32_ult_two(<2 x i32> %a) nounwind {
457 ; RV32I-LABEL: ctpop_v2i32_ult_two:
459 ; RV32I-NEXT: addi a2, a0, -1
460 ; RV32I-NEXT: and a0, a0, a2
461 ; RV32I-NEXT: seqz a0, a0
462 ; RV32I-NEXT: addi a2, a1, -1
463 ; RV32I-NEXT: and a1, a1, a2
464 ; RV32I-NEXT: seqz a1, a1
467 ; RV32ZBB-LABEL: ctpop_v2i32_ult_two:
469 ; RV32ZBB-NEXT: cpop a1, a1
470 ; RV32ZBB-NEXT: cpop a0, a0
471 ; RV32ZBB-NEXT: sltiu a0, a0, 2
472 ; RV32ZBB-NEXT: sltiu a1, a1, 2
474 %1 = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %a)
475 %2 = icmp ult <2 x i32> %1, <i32 2, i32 2>
479 define <2 x i1> @ctpop_v2i32_ugt_one(<2 x i32> %a) nounwind {
480 ; RV32I-LABEL: ctpop_v2i32_ugt_one:
482 ; RV32I-NEXT: addi a2, a0, -1
483 ; RV32I-NEXT: and a0, a0, a2
484 ; RV32I-NEXT: snez a0, a0
485 ; RV32I-NEXT: addi a2, a1, -1
486 ; RV32I-NEXT: and a1, a1, a2
487 ; RV32I-NEXT: snez a1, a1
490 ; RV32ZBB-LABEL: ctpop_v2i32_ugt_one:
492 ; RV32ZBB-NEXT: cpop a1, a1
493 ; RV32ZBB-NEXT: cpop a0, a0
494 ; RV32ZBB-NEXT: sltiu a0, a0, 2
495 ; RV32ZBB-NEXT: xori a0, a0, 1
496 ; RV32ZBB-NEXT: sltiu a1, a1, 2
497 ; RV32ZBB-NEXT: xori a1, a1, 1
499 %1 = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %a)
500 %2 = icmp ugt <2 x i32> %1, <i32 1, i32 1>
504 define <2 x i1> @ctpop_v2i32_eq_one(<2 x i32> %a) nounwind {
505 ; RV32I-LABEL: ctpop_v2i32_eq_one:
507 ; RV32I-NEXT: addi a2, a0, -1
508 ; RV32I-NEXT: xor a0, a0, a2
509 ; RV32I-NEXT: sltu a0, a2, a0
510 ; RV32I-NEXT: addi a2, a1, -1
511 ; RV32I-NEXT: xor a1, a1, a2
512 ; RV32I-NEXT: sltu a1, a2, a1
515 ; RV32ZBB-LABEL: ctpop_v2i32_eq_one:
517 ; RV32ZBB-NEXT: cpop a1, a1
518 ; RV32ZBB-NEXT: cpop a0, a0
519 ; RV32ZBB-NEXT: addi a0, a0, -1
520 ; RV32ZBB-NEXT: seqz a0, a0
521 ; RV32ZBB-NEXT: addi a1, a1, -1
522 ; RV32ZBB-NEXT: seqz a1, a1
524 %1 = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %a)
525 %2 = icmp eq <2 x i32> %1, <i32 1, i32 1>
529 define <2 x i1> @ctpop_v2i32_ne_one(<2 x i32> %a) nounwind {
530 ; RV32I-LABEL: ctpop_v2i32_ne_one:
532 ; RV32I-NEXT: addi a2, a0, -1
533 ; RV32I-NEXT: xor a0, a0, a2
534 ; RV32I-NEXT: sltu a0, a2, a0
535 ; RV32I-NEXT: xori a0, a0, 1
536 ; RV32I-NEXT: addi a2, a1, -1
537 ; RV32I-NEXT: xor a1, a1, a2
538 ; RV32I-NEXT: sltu a1, a2, a1
539 ; RV32I-NEXT: xori a1, a1, 1
542 ; RV32ZBB-LABEL: ctpop_v2i32_ne_one:
544 ; RV32ZBB-NEXT: cpop a1, a1
545 ; RV32ZBB-NEXT: cpop a0, a0
546 ; RV32ZBB-NEXT: addi a0, a0, -1
547 ; RV32ZBB-NEXT: snez a0, a0
548 ; RV32ZBB-NEXT: addi a1, a1, -1
549 ; RV32ZBB-NEXT: snez a1, a1
551 %1 = call <2 x i32> @llvm.ctpop.v2i32(<2 x i32> %a)
552 %2 = icmp ne <2 x i32> %1, <i32 1, i32 1>
556 declare i64 @llvm.ctpop.i64(i64)
558 define i64 @ctpop_i64(i64 %a) nounwind {
559 ; RV32I-LABEL: ctpop_i64:
561 ; RV32I-NEXT: addi sp, sp, -32
562 ; RV32I-NEXT: sw ra, 28(sp) # 4-byte Folded Spill
563 ; RV32I-NEXT: sw s0, 24(sp) # 4-byte Folded Spill
564 ; RV32I-NEXT: sw s1, 20(sp) # 4-byte Folded Spill
565 ; RV32I-NEXT: sw s2, 16(sp) # 4-byte Folded Spill
566 ; RV32I-NEXT: sw s3, 12(sp) # 4-byte Folded Spill
567 ; RV32I-NEXT: sw s4, 8(sp) # 4-byte Folded Spill
568 ; RV32I-NEXT: sw s5, 4(sp) # 4-byte Folded Spill
569 ; RV32I-NEXT: mv s0, a0
570 ; RV32I-NEXT: srli a0, a1, 1
571 ; RV32I-NEXT: lui a2, 349525
572 ; RV32I-NEXT: addi s2, a2, 1365
573 ; RV32I-NEXT: and a0, a0, s2
574 ; RV32I-NEXT: sub a1, a1, a0
575 ; RV32I-NEXT: lui a0, 209715
576 ; RV32I-NEXT: addi s3, a0, 819
577 ; RV32I-NEXT: and a0, a1, s3
578 ; RV32I-NEXT: srli a1, a1, 2
579 ; RV32I-NEXT: and a1, a1, s3
580 ; RV32I-NEXT: add a0, a0, a1
581 ; RV32I-NEXT: srli a1, a0, 4
582 ; RV32I-NEXT: add a0, a0, a1
583 ; RV32I-NEXT: lui a1, 61681
584 ; RV32I-NEXT: addi s4, a1, -241
585 ; RV32I-NEXT: and a0, a0, s4
586 ; RV32I-NEXT: lui a1, 4112
587 ; RV32I-NEXT: addi s1, a1, 257
588 ; RV32I-NEXT: mv a1, s1
589 ; RV32I-NEXT: call __mulsi3
590 ; RV32I-NEXT: srli s5, a0, 24
591 ; RV32I-NEXT: srli a0, s0, 1
592 ; RV32I-NEXT: and a0, a0, s2
593 ; RV32I-NEXT: sub s0, s0, a0
594 ; RV32I-NEXT: and a0, s0, s3
595 ; RV32I-NEXT: srli s0, s0, 2
596 ; RV32I-NEXT: and a1, s0, s3
597 ; RV32I-NEXT: add a0, a0, a1
598 ; RV32I-NEXT: srli a1, a0, 4
599 ; RV32I-NEXT: add a0, a0, a1
600 ; RV32I-NEXT: and a0, a0, s4
601 ; RV32I-NEXT: mv a1, s1
602 ; RV32I-NEXT: call __mulsi3
603 ; RV32I-NEXT: srli a0, a0, 24
604 ; RV32I-NEXT: add a0, a0, s5
605 ; RV32I-NEXT: li a1, 0
606 ; RV32I-NEXT: lw ra, 28(sp) # 4-byte Folded Reload
607 ; RV32I-NEXT: lw s0, 24(sp) # 4-byte Folded Reload
608 ; RV32I-NEXT: lw s1, 20(sp) # 4-byte Folded Reload
609 ; RV32I-NEXT: lw s2, 16(sp) # 4-byte Folded Reload
610 ; RV32I-NEXT: lw s3, 12(sp) # 4-byte Folded Reload
611 ; RV32I-NEXT: lw s4, 8(sp) # 4-byte Folded Reload
612 ; RV32I-NEXT: lw s5, 4(sp) # 4-byte Folded Reload
613 ; RV32I-NEXT: addi sp, sp, 32
616 ; RV32ZBB-LABEL: ctpop_i64:
618 ; RV32ZBB-NEXT: cpop a1, a1
619 ; RV32ZBB-NEXT: cpop a0, a0
620 ; RV32ZBB-NEXT: add a0, a0, a1
621 ; RV32ZBB-NEXT: li a1, 0
623 %1 = call i64 @llvm.ctpop.i64(i64 %a)
627 define i1 @ctpop_i64_ugt_two(i64 %a) nounwind {
628 ; RV32I-LABEL: ctpop_i64_ugt_two:
630 ; RV32I-NEXT: addi a2, a0, -1
631 ; RV32I-NEXT: and a2, a0, a2
632 ; RV32I-NEXT: seqz a0, a0
633 ; RV32I-NEXT: sub a0, a1, a0
634 ; RV32I-NEXT: and a0, a1, a0
635 ; RV32I-NEXT: or a0, a2, a0
636 ; RV32I-NEXT: seqz a0, a0
639 ; RV32ZBB-LABEL: ctpop_i64_ugt_two:
641 ; RV32ZBB-NEXT: cpop a1, a1
642 ; RV32ZBB-NEXT: cpop a0, a0
643 ; RV32ZBB-NEXT: add a0, a0, a1
644 ; RV32ZBB-NEXT: sltiu a0, a0, 2
646 %1 = call i64 @llvm.ctpop.i64(i64 %a)
647 %2 = icmp ult i64 %1, 2
651 define i1 @ctpop_i64_ugt_one(i64 %a) nounwind {
652 ; RV32I-LABEL: ctpop_i64_ugt_one:
654 ; RV32I-NEXT: addi a2, a0, -1
655 ; RV32I-NEXT: and a2, a0, a2
656 ; RV32I-NEXT: seqz a0, a0
657 ; RV32I-NEXT: sub a0, a1, a0
658 ; RV32I-NEXT: and a0, a1, a0
659 ; RV32I-NEXT: or a0, a2, a0
660 ; RV32I-NEXT: snez a0, a0
663 ; RV32ZBB-LABEL: ctpop_i64_ugt_one:
665 ; RV32ZBB-NEXT: cpop a1, a1
666 ; RV32ZBB-NEXT: cpop a0, a0
667 ; RV32ZBB-NEXT: add a0, a0, a1
668 ; RV32ZBB-NEXT: sltiu a0, a0, 2
669 ; RV32ZBB-NEXT: xori a0, a0, 1
671 %1 = call i64 @llvm.ctpop.i64(i64 %a)
672 %2 = icmp ugt i64 %1, 1
676 define i1 @ctpop_i64_eq_one(i64 %a) nounwind {
677 ; RV32I-LABEL: ctpop_i64_eq_one:
679 ; RV32I-NEXT: beqz a1, .LBB17_2
680 ; RV32I-NEXT: # %bb.1:
681 ; RV32I-NEXT: seqz a0, a0
682 ; RV32I-NEXT: sub a0, a1, a0
683 ; RV32I-NEXT: xor a1, a1, a0
684 ; RV32I-NEXT: sltu a0, a0, a1
686 ; RV32I-NEXT: .LBB17_2:
687 ; RV32I-NEXT: addi a1, a0, -1
688 ; RV32I-NEXT: xor a0, a0, a1
689 ; RV32I-NEXT: sltu a0, a1, a0
692 ; RV32ZBB-LABEL: ctpop_i64_eq_one:
694 ; RV32ZBB-NEXT: cpop a1, a1
695 ; RV32ZBB-NEXT: cpop a0, a0
696 ; RV32ZBB-NEXT: add a0, a0, a1
697 ; RV32ZBB-NEXT: addi a0, a0, -1
698 ; RV32ZBB-NEXT: seqz a0, a0
700 %1 = call i64 @llvm.ctpop.i64(i64 %a)
701 %2 = icmp eq i64 %1, 1
705 define i1 @ctpop_i64_ne_one(i64 %a) nounwind {
706 ; RV32I-LABEL: ctpop_i64_ne_one:
708 ; RV32I-NEXT: beqz a1, .LBB18_2
709 ; RV32I-NEXT: # %bb.1:
710 ; RV32I-NEXT: seqz a0, a0
711 ; RV32I-NEXT: sub a0, a1, a0
712 ; RV32I-NEXT: xor a1, a1, a0
713 ; RV32I-NEXT: sltu a0, a0, a1
714 ; RV32I-NEXT: xori a0, a0, 1
716 ; RV32I-NEXT: .LBB18_2:
717 ; RV32I-NEXT: addi a1, a0, -1
718 ; RV32I-NEXT: xor a0, a0, a1
719 ; RV32I-NEXT: sltu a0, a1, a0
720 ; RV32I-NEXT: xori a0, a0, 1
723 ; RV32ZBB-LABEL: ctpop_i64_ne_one:
725 ; RV32ZBB-NEXT: cpop a1, a1
726 ; RV32ZBB-NEXT: cpop a0, a0
727 ; RV32ZBB-NEXT: add a0, a0, a1
728 ; RV32ZBB-NEXT: addi a0, a0, -1
729 ; RV32ZBB-NEXT: snez a0, a0
731 %1 = call i64 @llvm.ctpop.i64(i64 %a)
732 %2 = icmp ne i64 %1, 1
736 declare <2 x i64> @llvm.ctpop.v2i64(<2 x i64>)
738 define <2 x i64> @ctpop_v2i64(<2 x i64> %a) nounwind {
739 ; RV32I-LABEL: ctpop_v2i64:
741 ; RV32I-NEXT: addi sp, sp, -48
742 ; RV32I-NEXT: sw ra, 44(sp) # 4-byte Folded Spill
743 ; RV32I-NEXT: sw s0, 40(sp) # 4-byte Folded Spill
744 ; RV32I-NEXT: sw s1, 36(sp) # 4-byte Folded Spill
745 ; RV32I-NEXT: sw s2, 32(sp) # 4-byte Folded Spill
746 ; RV32I-NEXT: sw s3, 28(sp) # 4-byte Folded Spill
747 ; RV32I-NEXT: sw s4, 24(sp) # 4-byte Folded Spill
748 ; RV32I-NEXT: sw s5, 20(sp) # 4-byte Folded Spill
749 ; RV32I-NEXT: sw s6, 16(sp) # 4-byte Folded Spill
750 ; RV32I-NEXT: sw s7, 12(sp) # 4-byte Folded Spill
751 ; RV32I-NEXT: sw s8, 8(sp) # 4-byte Folded Spill
752 ; RV32I-NEXT: mv s0, a0
753 ; RV32I-NEXT: lw a0, 4(a1)
754 ; RV32I-NEXT: lw s2, 8(a1)
755 ; RV32I-NEXT: lw s5, 12(a1)
756 ; RV32I-NEXT: lw s6, 0(a1)
757 ; RV32I-NEXT: srli a1, a0, 1
758 ; RV32I-NEXT: lui a2, 349525
759 ; RV32I-NEXT: addi s3, a2, 1365
760 ; RV32I-NEXT: and a1, a1, s3
761 ; RV32I-NEXT: sub a0, a0, a1
762 ; RV32I-NEXT: lui a1, 209715
763 ; RV32I-NEXT: addi s4, a1, 819
764 ; RV32I-NEXT: and a1, a0, s4
765 ; RV32I-NEXT: srli a0, a0, 2
766 ; RV32I-NEXT: and a0, a0, s4
767 ; RV32I-NEXT: add a0, a1, a0
768 ; RV32I-NEXT: srli a1, a0, 4
769 ; RV32I-NEXT: add a0, a0, a1
770 ; RV32I-NEXT: lui a1, 61681
771 ; RV32I-NEXT: addi s7, a1, -241
772 ; RV32I-NEXT: and a0, a0, s7
773 ; RV32I-NEXT: lui a1, 4112
774 ; RV32I-NEXT: addi s1, a1, 257
775 ; RV32I-NEXT: mv a1, s1
776 ; RV32I-NEXT: call __mulsi3
777 ; RV32I-NEXT: srli s8, a0, 24
778 ; RV32I-NEXT: srli a0, s6, 1
779 ; RV32I-NEXT: and a0, a0, s3
780 ; RV32I-NEXT: sub a0, s6, a0
781 ; RV32I-NEXT: and a1, a0, s4
782 ; RV32I-NEXT: srli a0, a0, 2
783 ; RV32I-NEXT: and a0, a0, s4
784 ; RV32I-NEXT: add a0, a1, a0
785 ; RV32I-NEXT: srli a1, a0, 4
786 ; RV32I-NEXT: add a0, a0, a1
787 ; RV32I-NEXT: and a0, a0, s7
788 ; RV32I-NEXT: mv a1, s1
789 ; RV32I-NEXT: call __mulsi3
790 ; RV32I-NEXT: srli a0, a0, 24
791 ; RV32I-NEXT: add s8, a0, s8
792 ; RV32I-NEXT: srli a0, s5, 1
793 ; RV32I-NEXT: and a0, a0, s3
794 ; RV32I-NEXT: sub a0, s5, a0
795 ; RV32I-NEXT: and a1, a0, s4
796 ; RV32I-NEXT: srli a0, a0, 2
797 ; RV32I-NEXT: and a0, a0, s4
798 ; RV32I-NEXT: add a0, a1, a0
799 ; RV32I-NEXT: srli a1, a0, 4
800 ; RV32I-NEXT: add a0, a0, a1
801 ; RV32I-NEXT: and a0, a0, s7
802 ; RV32I-NEXT: mv a1, s1
803 ; RV32I-NEXT: call __mulsi3
804 ; RV32I-NEXT: srli s5, a0, 24
805 ; RV32I-NEXT: srli a0, s2, 1
806 ; RV32I-NEXT: and a0, a0, s3
807 ; RV32I-NEXT: sub a0, s2, a0
808 ; RV32I-NEXT: and a1, a0, s4
809 ; RV32I-NEXT: srli a0, a0, 2
810 ; RV32I-NEXT: and a0, a0, s4
811 ; RV32I-NEXT: add a0, a1, a0
812 ; RV32I-NEXT: srli a1, a0, 4
813 ; RV32I-NEXT: add a0, a0, a1
814 ; RV32I-NEXT: and a0, a0, s7
815 ; RV32I-NEXT: mv a1, s1
816 ; RV32I-NEXT: call __mulsi3
817 ; RV32I-NEXT: srli a0, a0, 24
818 ; RV32I-NEXT: add a0, a0, s5
819 ; RV32I-NEXT: sw zero, 12(s0)
820 ; RV32I-NEXT: sw zero, 4(s0)
821 ; RV32I-NEXT: sw a0, 8(s0)
822 ; RV32I-NEXT: sw s8, 0(s0)
823 ; RV32I-NEXT: lw ra, 44(sp) # 4-byte Folded Reload
824 ; RV32I-NEXT: lw s0, 40(sp) # 4-byte Folded Reload
825 ; RV32I-NEXT: lw s1, 36(sp) # 4-byte Folded Reload
826 ; RV32I-NEXT: lw s2, 32(sp) # 4-byte Folded Reload
827 ; RV32I-NEXT: lw s3, 28(sp) # 4-byte Folded Reload
828 ; RV32I-NEXT: lw s4, 24(sp) # 4-byte Folded Reload
829 ; RV32I-NEXT: lw s5, 20(sp) # 4-byte Folded Reload
830 ; RV32I-NEXT: lw s6, 16(sp) # 4-byte Folded Reload
831 ; RV32I-NEXT: lw s7, 12(sp) # 4-byte Folded Reload
832 ; RV32I-NEXT: lw s8, 8(sp) # 4-byte Folded Reload
833 ; RV32I-NEXT: addi sp, sp, 48
836 ; RV32ZBB-LABEL: ctpop_v2i64:
838 ; RV32ZBB-NEXT: lw a2, 4(a1)
839 ; RV32ZBB-NEXT: lw a3, 0(a1)
840 ; RV32ZBB-NEXT: lw a4, 8(a1)
841 ; RV32ZBB-NEXT: lw a1, 12(a1)
842 ; RV32ZBB-NEXT: cpop a2, a2
843 ; RV32ZBB-NEXT: cpop a3, a3
844 ; RV32ZBB-NEXT: add a2, a3, a2
845 ; RV32ZBB-NEXT: cpop a1, a1
846 ; RV32ZBB-NEXT: cpop a3, a4
847 ; RV32ZBB-NEXT: add a1, a3, a1
848 ; RV32ZBB-NEXT: sw zero, 12(a0)
849 ; RV32ZBB-NEXT: sw zero, 4(a0)
850 ; RV32ZBB-NEXT: sw a1, 8(a0)
851 ; RV32ZBB-NEXT: sw a2, 0(a0)
853 %1 = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %a)
857 define <2 x i1> @ctpop_v2i64_ult_two(<2 x i64> %a) nounwind {
858 ; RV32I-LABEL: ctpop_v2i64_ult_two:
860 ; RV32I-NEXT: lw a1, 0(a0)
861 ; RV32I-NEXT: lw a2, 12(a0)
862 ; RV32I-NEXT: lw a3, 8(a0)
863 ; RV32I-NEXT: lw a0, 4(a0)
864 ; RV32I-NEXT: addi a4, a1, -1
865 ; RV32I-NEXT: and a4, a1, a4
866 ; RV32I-NEXT: seqz a1, a1
867 ; RV32I-NEXT: sub a1, a0, a1
868 ; RV32I-NEXT: and a0, a0, a1
869 ; RV32I-NEXT: or a0, a4, a0
870 ; RV32I-NEXT: seqz a0, a0
871 ; RV32I-NEXT: addi a1, a3, -1
872 ; RV32I-NEXT: and a1, a3, a1
873 ; RV32I-NEXT: seqz a3, a3
874 ; RV32I-NEXT: sub a3, a2, a3
875 ; RV32I-NEXT: and a2, a2, a3
876 ; RV32I-NEXT: or a1, a1, a2
877 ; RV32I-NEXT: seqz a1, a1
880 ; RV32ZBB-LABEL: ctpop_v2i64_ult_two:
882 ; RV32ZBB-NEXT: lw a1, 12(a0)
883 ; RV32ZBB-NEXT: lw a2, 8(a0)
884 ; RV32ZBB-NEXT: lw a3, 0(a0)
885 ; RV32ZBB-NEXT: lw a0, 4(a0)
886 ; RV32ZBB-NEXT: cpop a1, a1
887 ; RV32ZBB-NEXT: cpop a2, a2
888 ; RV32ZBB-NEXT: add a1, a2, a1
889 ; RV32ZBB-NEXT: cpop a0, a0
890 ; RV32ZBB-NEXT: cpop a2, a3
891 ; RV32ZBB-NEXT: add a0, a2, a0
892 ; RV32ZBB-NEXT: sltiu a0, a0, 2
893 ; RV32ZBB-NEXT: sltiu a1, a1, 2
895 %1 = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %a)
896 %2 = icmp ult <2 x i64> %1, <i64 2, i64 2>
900 define <2 x i1> @ctpop_v2i64_ugt_one(<2 x i64> %a) nounwind {
901 ; RV32I-LABEL: ctpop_v2i64_ugt_one:
903 ; RV32I-NEXT: lw a1, 0(a0)
904 ; RV32I-NEXT: lw a2, 12(a0)
905 ; RV32I-NEXT: lw a3, 8(a0)
906 ; RV32I-NEXT: lw a0, 4(a0)
907 ; RV32I-NEXT: addi a4, a1, -1
908 ; RV32I-NEXT: and a4, a1, a4
909 ; RV32I-NEXT: seqz a1, a1
910 ; RV32I-NEXT: sub a1, a0, a1
911 ; RV32I-NEXT: and a0, a0, a1
912 ; RV32I-NEXT: or a0, a4, a0
913 ; RV32I-NEXT: snez a0, a0
914 ; RV32I-NEXT: addi a1, a3, -1
915 ; RV32I-NEXT: and a1, a3, a1
916 ; RV32I-NEXT: seqz a3, a3
917 ; RV32I-NEXT: sub a3, a2, a3
918 ; RV32I-NEXT: and a2, a2, a3
919 ; RV32I-NEXT: or a1, a1, a2
920 ; RV32I-NEXT: snez a1, a1
923 ; RV32ZBB-LABEL: ctpop_v2i64_ugt_one:
925 ; RV32ZBB-NEXT: lw a1, 12(a0)
926 ; RV32ZBB-NEXT: lw a2, 8(a0)
927 ; RV32ZBB-NEXT: lw a3, 0(a0)
928 ; RV32ZBB-NEXT: lw a0, 4(a0)
929 ; RV32ZBB-NEXT: cpop a1, a1
930 ; RV32ZBB-NEXT: cpop a2, a2
931 ; RV32ZBB-NEXT: add a1, a2, a1
932 ; RV32ZBB-NEXT: cpop a0, a0
933 ; RV32ZBB-NEXT: cpop a2, a3
934 ; RV32ZBB-NEXT: add a0, a2, a0
935 ; RV32ZBB-NEXT: sltiu a0, a0, 2
936 ; RV32ZBB-NEXT: xori a0, a0, 1
937 ; RV32ZBB-NEXT: sltiu a1, a1, 2
938 ; RV32ZBB-NEXT: xori a1, a1, 1
940 %1 = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %a)
941 %2 = icmp ugt <2 x i64> %1, <i64 1, i64 1>
945 define <2 x i1> @ctpop_v2i64_eq_one(<2 x i64> %a) nounwind {
946 ; RV32I-LABEL: ctpop_v2i64_eq_one:
948 ; RV32I-NEXT: mv a1, a0
949 ; RV32I-NEXT: lw a2, 12(a0)
950 ; RV32I-NEXT: lw a0, 4(a0)
951 ; RV32I-NEXT: lw a3, 0(a1)
952 ; RV32I-NEXT: beqz a0, .LBB22_3
953 ; RV32I-NEXT: # %bb.1:
954 ; RV32I-NEXT: seqz a3, a3
955 ; RV32I-NEXT: sub a3, a0, a3
956 ; RV32I-NEXT: xor a0, a0, a3
957 ; RV32I-NEXT: sltu a0, a3, a0
958 ; RV32I-NEXT: lw a1, 8(a1)
959 ; RV32I-NEXT: bnez a2, .LBB22_4
960 ; RV32I-NEXT: .LBB22_2:
961 ; RV32I-NEXT: addi a2, a1, -1
962 ; RV32I-NEXT: xor a1, a1, a2
963 ; RV32I-NEXT: sltu a1, a2, a1
965 ; RV32I-NEXT: .LBB22_3:
966 ; RV32I-NEXT: addi a0, a3, -1
967 ; RV32I-NEXT: xor a3, a3, a0
968 ; RV32I-NEXT: sltu a0, a0, a3
969 ; RV32I-NEXT: lw a1, 8(a1)
970 ; RV32I-NEXT: beqz a2, .LBB22_2
971 ; RV32I-NEXT: .LBB22_4:
972 ; RV32I-NEXT: seqz a1, a1
973 ; RV32I-NEXT: sub a1, a2, a1
974 ; RV32I-NEXT: xor a2, a2, a1
975 ; RV32I-NEXT: sltu a1, a1, a2
978 ; RV32ZBB-LABEL: ctpop_v2i64_eq_one:
980 ; RV32ZBB-NEXT: lw a1, 12(a0)
981 ; RV32ZBB-NEXT: lw a2, 8(a0)
982 ; RV32ZBB-NEXT: lw a3, 0(a0)
983 ; RV32ZBB-NEXT: lw a0, 4(a0)
984 ; RV32ZBB-NEXT: cpop a1, a1
985 ; RV32ZBB-NEXT: cpop a2, a2
986 ; RV32ZBB-NEXT: add a1, a2, a1
987 ; RV32ZBB-NEXT: cpop a0, a0
988 ; RV32ZBB-NEXT: cpop a2, a3
989 ; RV32ZBB-NEXT: add a0, a2, a0
990 ; RV32ZBB-NEXT: addi a0, a0, -1
991 ; RV32ZBB-NEXT: seqz a0, a0
992 ; RV32ZBB-NEXT: addi a1, a1, -1
993 ; RV32ZBB-NEXT: seqz a1, a1
995 %1 = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %a)
996 %2 = icmp eq <2 x i64> %1, <i64 1, i64 1>
1000 define <2 x i1> @ctpop_v2i64_ne_one(<2 x i64> %a) nounwind {
1001 ; RV32I-LABEL: ctpop_v2i64_ne_one:
1003 ; RV32I-NEXT: lw a1, 12(a0)
1004 ; RV32I-NEXT: lw a2, 4(a0)
1005 ; RV32I-NEXT: lw a3, 0(a0)
1006 ; RV32I-NEXT: beqz a2, .LBB23_2
1007 ; RV32I-NEXT: # %bb.1:
1008 ; RV32I-NEXT: seqz a3, a3
1009 ; RV32I-NEXT: sub a3, a2, a3
1010 ; RV32I-NEXT: xor a2, a2, a3
1011 ; RV32I-NEXT: sltu a2, a3, a2
1012 ; RV32I-NEXT: j .LBB23_3
1013 ; RV32I-NEXT: .LBB23_2:
1014 ; RV32I-NEXT: addi a2, a3, -1
1015 ; RV32I-NEXT: xor a3, a3, a2
1016 ; RV32I-NEXT: sltu a2, a2, a3
1017 ; RV32I-NEXT: .LBB23_3:
1018 ; RV32I-NEXT: lw a3, 8(a0)
1019 ; RV32I-NEXT: xori a0, a2, 1
1020 ; RV32I-NEXT: beqz a1, .LBB23_5
1021 ; RV32I-NEXT: # %bb.4:
1022 ; RV32I-NEXT: seqz a2, a3
1023 ; RV32I-NEXT: sub a2, a1, a2
1024 ; RV32I-NEXT: xor a1, a1, a2
1025 ; RV32I-NEXT: sltu a1, a2, a1
1026 ; RV32I-NEXT: xori a1, a1, 1
1028 ; RV32I-NEXT: .LBB23_5:
1029 ; RV32I-NEXT: addi a1, a3, -1
1030 ; RV32I-NEXT: xor a3, a3, a1
1031 ; RV32I-NEXT: sltu a1, a1, a3
1032 ; RV32I-NEXT: xori a1, a1, 1
1035 ; RV32ZBB-LABEL: ctpop_v2i64_ne_one:
1037 ; RV32ZBB-NEXT: lw a1, 12(a0)
1038 ; RV32ZBB-NEXT: lw a2, 8(a0)
1039 ; RV32ZBB-NEXT: lw a3, 0(a0)
1040 ; RV32ZBB-NEXT: lw a0, 4(a0)
1041 ; RV32ZBB-NEXT: cpop a1, a1
1042 ; RV32ZBB-NEXT: cpop a2, a2
1043 ; RV32ZBB-NEXT: add a1, a2, a1
1044 ; RV32ZBB-NEXT: cpop a0, a0
1045 ; RV32ZBB-NEXT: cpop a2, a3
1046 ; RV32ZBB-NEXT: add a0, a2, a0
1047 ; RV32ZBB-NEXT: addi a0, a0, -1
1048 ; RV32ZBB-NEXT: snez a0, a0
1049 ; RV32ZBB-NEXT: addi a1, a1, -1
1050 ; RV32ZBB-NEXT: snez a1, a1
1052 %1 = call <2 x i64> @llvm.ctpop.v2i64(<2 x i64> %a)
1053 %2 = icmp ne <2 x i64> %1, <i64 1, i64 1>
1057 define i32 @sextb_i32(i32 %a) nounwind {
1058 ; RV32I-LABEL: sextb_i32:
1060 ; RV32I-NEXT: slli a0, a0, 24
1061 ; RV32I-NEXT: srai a0, a0, 24
1064 ; RV32ZBB-LABEL: sextb_i32:
1066 ; RV32ZBB-NEXT: sext.b a0, a0
1068 %shl = shl i32 %a, 24
1069 %shr = ashr exact i32 %shl, 24
1073 define i64 @sextb_i64(i64 %a) nounwind {
1074 ; RV32I-LABEL: sextb_i64:
1076 ; RV32I-NEXT: slli a1, a0, 24
1077 ; RV32I-NEXT: srai a0, a1, 24
1078 ; RV32I-NEXT: srai a1, a1, 31
1081 ; RV32ZBB-LABEL: sextb_i64:
1083 ; RV32ZBB-NEXT: sext.b a0, a0
1084 ; RV32ZBB-NEXT: srai a1, a0, 31
1086 %shl = shl i64 %a, 56
1087 %shr = ashr exact i64 %shl, 56
1091 define i32 @sexth_i32(i32 %a) nounwind {
1092 ; RV32I-LABEL: sexth_i32:
1094 ; RV32I-NEXT: slli a0, a0, 16
1095 ; RV32I-NEXT: srai a0, a0, 16
1098 ; RV32ZBB-LABEL: sexth_i32:
1100 ; RV32ZBB-NEXT: sext.h a0, a0
1102 %shl = shl i32 %a, 16
1103 %shr = ashr exact i32 %shl, 16
1107 define i64 @sexth_i64(i64 %a) nounwind {
1108 ; RV32I-LABEL: sexth_i64:
1110 ; RV32I-NEXT: slli a1, a0, 16
1111 ; RV32I-NEXT: srai a0, a1, 16
1112 ; RV32I-NEXT: srai a1, a1, 31
1115 ; RV32ZBB-LABEL: sexth_i64:
1117 ; RV32ZBB-NEXT: sext.h a0, a0
1118 ; RV32ZBB-NEXT: srai a1, a0, 31
1120 %shl = shl i64 %a, 48
1121 %shr = ashr exact i64 %shl, 48
1125 define i32 @min_i32(i32 %a, i32 %b) nounwind {
1126 ; RV32I-LABEL: min_i32:
1128 ; RV32I-NEXT: blt a0, a1, .LBB28_2
1129 ; RV32I-NEXT: # %bb.1:
1130 ; RV32I-NEXT: mv a0, a1
1131 ; RV32I-NEXT: .LBB28_2:
1134 ; RV32ZBB-LABEL: min_i32:
1136 ; RV32ZBB-NEXT: min a0, a0, a1
1138 %cmp = icmp slt i32 %a, %b
1139 %cond = select i1 %cmp, i32 %a, i32 %b
1143 ; As we are not matching directly i64 code patterns on RV32 some i64 patterns
1144 ; don't have yet any matching bit manipulation instructions on RV32.
1145 ; This test is presented here in case future expansions of the Bitmanip
1146 ; extensions introduce instructions suitable for this pattern.
1148 define i64 @min_i64(i64 %a, i64 %b) nounwind {
1149 ; CHECK-LABEL: min_i64:
1151 ; CHECK-NEXT: beq a1, a3, .LBB29_2
1152 ; CHECK-NEXT: # %bb.1:
1153 ; CHECK-NEXT: slt a4, a1, a3
1154 ; CHECK-NEXT: beqz a4, .LBB29_3
1155 ; CHECK-NEXT: j .LBB29_4
1156 ; CHECK-NEXT: .LBB29_2:
1157 ; CHECK-NEXT: sltu a4, a0, a2
1158 ; CHECK-NEXT: bnez a4, .LBB29_4
1159 ; CHECK-NEXT: .LBB29_3:
1160 ; CHECK-NEXT: mv a0, a2
1161 ; CHECK-NEXT: mv a1, a3
1162 ; CHECK-NEXT: .LBB29_4:
1164 %cmp = icmp slt i64 %a, %b
1165 %cond = select i1 %cmp, i64 %a, i64 %b
1169 define i32 @max_i32(i32 %a, i32 %b) nounwind {
1170 ; RV32I-LABEL: max_i32:
1172 ; RV32I-NEXT: blt a1, a0, .LBB30_2
1173 ; RV32I-NEXT: # %bb.1:
1174 ; RV32I-NEXT: mv a0, a1
1175 ; RV32I-NEXT: .LBB30_2:
1178 ; RV32ZBB-LABEL: max_i32:
1180 ; RV32ZBB-NEXT: max a0, a0, a1
1182 %cmp = icmp sgt i32 %a, %b
1183 %cond = select i1 %cmp, i32 %a, i32 %b
1187 ; As we are not matching directly i64 code patterns on RV32 some i64 patterns
1188 ; don't have yet any matching bit manipulation instructions on RV32.
1189 ; This test is presented here in case future expansions of the Bitmanip
1190 ; extensions introduce instructions suitable for this pattern.
1192 define i64 @max_i64(i64 %a, i64 %b) nounwind {
1193 ; CHECK-LABEL: max_i64:
1195 ; CHECK-NEXT: beq a1, a3, .LBB31_2
1196 ; CHECK-NEXT: # %bb.1:
1197 ; CHECK-NEXT: slt a4, a3, a1
1198 ; CHECK-NEXT: beqz a4, .LBB31_3
1199 ; CHECK-NEXT: j .LBB31_4
1200 ; CHECK-NEXT: .LBB31_2:
1201 ; CHECK-NEXT: sltu a4, a2, a0
1202 ; CHECK-NEXT: bnez a4, .LBB31_4
1203 ; CHECK-NEXT: .LBB31_3:
1204 ; CHECK-NEXT: mv a0, a2
1205 ; CHECK-NEXT: mv a1, a3
1206 ; CHECK-NEXT: .LBB31_4:
1208 %cmp = icmp sgt i64 %a, %b
1209 %cond = select i1 %cmp, i64 %a, i64 %b
1213 define i32 @minu_i32(i32 %a, i32 %b) nounwind {
1214 ; RV32I-LABEL: minu_i32:
1216 ; RV32I-NEXT: bltu a0, a1, .LBB32_2
1217 ; RV32I-NEXT: # %bb.1:
1218 ; RV32I-NEXT: mv a0, a1
1219 ; RV32I-NEXT: .LBB32_2:
1222 ; RV32ZBB-LABEL: minu_i32:
1224 ; RV32ZBB-NEXT: minu a0, a0, a1
1226 %cmp = icmp ult i32 %a, %b
1227 %cond = select i1 %cmp, i32 %a, i32 %b
1231 ; As we are not matching directly i64 code patterns on RV32 some i64 patterns
1232 ; don't have yet any matching bit manipulation instructions on RV32.
1233 ; This test is presented here in case future expansions of the Bitmanip
1234 ; extensions introduce instructions suitable for this pattern.
1236 define i64 @minu_i64(i64 %a, i64 %b) nounwind {
1237 ; CHECK-LABEL: minu_i64:
1239 ; CHECK-NEXT: beq a1, a3, .LBB33_2
1240 ; CHECK-NEXT: # %bb.1:
1241 ; CHECK-NEXT: sltu a4, a1, a3
1242 ; CHECK-NEXT: beqz a4, .LBB33_3
1243 ; CHECK-NEXT: j .LBB33_4
1244 ; CHECK-NEXT: .LBB33_2:
1245 ; CHECK-NEXT: sltu a4, a0, a2
1246 ; CHECK-NEXT: bnez a4, .LBB33_4
1247 ; CHECK-NEXT: .LBB33_3:
1248 ; CHECK-NEXT: mv a0, a2
1249 ; CHECK-NEXT: mv a1, a3
1250 ; CHECK-NEXT: .LBB33_4:
1252 %cmp = icmp ult i64 %a, %b
1253 %cond = select i1 %cmp, i64 %a, i64 %b
1257 define i32 @maxu_i32(i32 %a, i32 %b) nounwind {
1258 ; RV32I-LABEL: maxu_i32:
1260 ; RV32I-NEXT: bltu a1, a0, .LBB34_2
1261 ; RV32I-NEXT: # %bb.1:
1262 ; RV32I-NEXT: mv a0, a1
1263 ; RV32I-NEXT: .LBB34_2:
1266 ; RV32ZBB-LABEL: maxu_i32:
1268 ; RV32ZBB-NEXT: maxu a0, a0, a1
1270 %cmp = icmp ugt i32 %a, %b
1271 %cond = select i1 %cmp, i32 %a, i32 %b
1275 ; As we are not matching directly i64 code patterns on RV32 some i64 patterns
1276 ; don't have yet any matching bit manipulation instructions on RV32.
1277 ; This test is presented here in case future expansions of the Bitmanip
1278 ; extensions introduce instructions suitable for this pattern.
1280 define i64 @maxu_i64(i64 %a, i64 %b) nounwind {
1281 ; CHECK-LABEL: maxu_i64:
1283 ; CHECK-NEXT: beq a1, a3, .LBB35_2
1284 ; CHECK-NEXT: # %bb.1:
1285 ; CHECK-NEXT: sltu a4, a3, a1
1286 ; CHECK-NEXT: beqz a4, .LBB35_3
1287 ; CHECK-NEXT: j .LBB35_4
1288 ; CHECK-NEXT: .LBB35_2:
1289 ; CHECK-NEXT: sltu a4, a2, a0
1290 ; CHECK-NEXT: bnez a4, .LBB35_4
1291 ; CHECK-NEXT: .LBB35_3:
1292 ; CHECK-NEXT: mv a0, a2
1293 ; CHECK-NEXT: mv a1, a3
1294 ; CHECK-NEXT: .LBB35_4:
1296 %cmp = icmp ugt i64 %a, %b
1297 %cond = select i1 %cmp, i64 %a, i64 %b
1301 declare i32 @llvm.abs.i32(i32, i1 immarg)
1303 define i32 @abs_i32(i32 %x) {
1304 ; RV32I-LABEL: abs_i32:
1306 ; RV32I-NEXT: srai a1, a0, 31
1307 ; RV32I-NEXT: xor a0, a0, a1
1308 ; RV32I-NEXT: sub a0, a0, a1
1311 ; RV32ZBB-LABEL: abs_i32:
1313 ; RV32ZBB-NEXT: neg a1, a0
1314 ; RV32ZBB-NEXT: max a0, a0, a1
1316 %abs = tail call i32 @llvm.abs.i32(i32 %x, i1 true)
1320 declare i64 @llvm.abs.i64(i64, i1 immarg)
1322 define i64 @abs_i64(i64 %x) {
1323 ; CHECK-LABEL: abs_i64:
1325 ; CHECK-NEXT: bgez a1, .LBB37_2
1326 ; CHECK-NEXT: # %bb.1:
1327 ; CHECK-NEXT: snez a2, a0
1328 ; CHECK-NEXT: neg a0, a0
1329 ; CHECK-NEXT: neg a1, a1
1330 ; CHECK-NEXT: sub a1, a1, a2
1331 ; CHECK-NEXT: .LBB37_2:
1333 %abs = tail call i64 @llvm.abs.i64(i64 %x, i1 true)
1337 define i32 @zexth_i32(i32 %a) nounwind {
1338 ; RV32I-LABEL: zexth_i32:
1340 ; RV32I-NEXT: slli a0, a0, 16
1341 ; RV32I-NEXT: srli a0, a0, 16
1344 ; RV32ZBB-LABEL: zexth_i32:
1346 ; RV32ZBB-NEXT: zext.h a0, a0
1348 %and = and i32 %a, 65535
1352 define i64 @zexth_i64(i64 %a) nounwind {
1353 ; RV32I-LABEL: zexth_i64:
1355 ; RV32I-NEXT: slli a0, a0, 16
1356 ; RV32I-NEXT: srli a0, a0, 16
1357 ; RV32I-NEXT: li a1, 0
1360 ; RV32ZBB-LABEL: zexth_i64:
1362 ; RV32ZBB-NEXT: zext.h a0, a0
1363 ; RV32ZBB-NEXT: li a1, 0
1365 %and = and i64 %a, 65535
1369 declare i32 @llvm.bswap.i32(i32)
1371 define i32 @bswap_i32(i32 %a) nounwind {
1372 ; RV32I-LABEL: bswap_i32:
1374 ; RV32I-NEXT: srli a1, a0, 8
1375 ; RV32I-NEXT: lui a2, 16
1376 ; RV32I-NEXT: addi a2, a2, -256
1377 ; RV32I-NEXT: and a1, a1, a2
1378 ; RV32I-NEXT: srli a3, a0, 24
1379 ; RV32I-NEXT: or a1, a1, a3
1380 ; RV32I-NEXT: and a2, a0, a2
1381 ; RV32I-NEXT: slli a2, a2, 8
1382 ; RV32I-NEXT: slli a0, a0, 24
1383 ; RV32I-NEXT: or a0, a0, a2
1384 ; RV32I-NEXT: or a0, a0, a1
1387 ; RV32ZBB-LABEL: bswap_i32:
1389 ; RV32ZBB-NEXT: rev8 a0, a0
1391 %1 = tail call i32 @llvm.bswap.i32(i32 %a)
1395 declare i64 @llvm.bswap.i64(i64)
1397 define i64 @bswap_i64(i64 %a) {
1398 ; RV32I-LABEL: bswap_i64:
1400 ; RV32I-NEXT: srli a2, a1, 8
1401 ; RV32I-NEXT: lui a3, 16
1402 ; RV32I-NEXT: addi a3, a3, -256
1403 ; RV32I-NEXT: and a2, a2, a3
1404 ; RV32I-NEXT: srli a4, a1, 24
1405 ; RV32I-NEXT: or a2, a2, a4
1406 ; RV32I-NEXT: and a4, a1, a3
1407 ; RV32I-NEXT: slli a4, a4, 8
1408 ; RV32I-NEXT: slli a1, a1, 24
1409 ; RV32I-NEXT: or a1, a1, a4
1410 ; RV32I-NEXT: or a2, a1, a2
1411 ; RV32I-NEXT: srli a1, a0, 8
1412 ; RV32I-NEXT: and a1, a1, a3
1413 ; RV32I-NEXT: srli a4, a0, 24
1414 ; RV32I-NEXT: or a1, a1, a4
1415 ; RV32I-NEXT: and a3, a0, a3
1416 ; RV32I-NEXT: slli a3, a3, 8
1417 ; RV32I-NEXT: slli a0, a0, 24
1418 ; RV32I-NEXT: or a0, a0, a3
1419 ; RV32I-NEXT: or a1, a0, a1
1420 ; RV32I-NEXT: mv a0, a2
1423 ; RV32ZBB-LABEL: bswap_i64:
1425 ; RV32ZBB-NEXT: rev8 a2, a1
1426 ; RV32ZBB-NEXT: rev8 a1, a0
1427 ; RV32ZBB-NEXT: mv a0, a2
1429 %1 = call i64 @llvm.bswap.i64(i64 %a)