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
4 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-b -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV32B
6 ; RUN: llc -mtriple=riscv32 -mattr=+experimental-zbp -verify-machineinstrs < %s \
7 ; RUN: | FileCheck %s -check-prefix=RV32ZBP
9 define i32 @gorc1_i32(i32 %a) nounwind {
10 ; RV32I-LABEL: gorc1_i32:
12 ; RV32I-NEXT: slli a1, a0, 1
13 ; RV32I-NEXT: lui a2, 699051
14 ; RV32I-NEXT: addi a2, a2, -1366
15 ; RV32I-NEXT: and a1, a1, a2
16 ; RV32I-NEXT: srli a2, a0, 1
17 ; RV32I-NEXT: lui a3, 349525
18 ; RV32I-NEXT: addi a3, a3, 1365
19 ; RV32I-NEXT: and a2, a2, a3
20 ; RV32I-NEXT: or a0, a2, a0
21 ; RV32I-NEXT: or a0, a0, a1
24 ; RV32B-LABEL: gorc1_i32:
26 ; RV32B-NEXT: orc.p a0, a0
29 ; RV32ZBP-LABEL: gorc1_i32:
31 ; RV32ZBP-NEXT: orc.p a0, a0
34 %shl = and i32 %and, -1431655766
35 %and1 = lshr i32 %a, 1
36 %shr = and i32 %and1, 1431655765
38 %or2 = or i32 %or, %shl
42 define i64 @gorc1_i64(i64 %a) nounwind {
43 ; RV32I-LABEL: gorc1_i64:
45 ; RV32I-NEXT: slli a2, a0, 1
46 ; RV32I-NEXT: slli a3, a1, 1
47 ; RV32I-NEXT: lui a4, 699051
48 ; RV32I-NEXT: addi a4, a4, -1366
49 ; RV32I-NEXT: and a6, a3, a4
50 ; RV32I-NEXT: and a2, a2, a4
51 ; RV32I-NEXT: srli a4, a1, 1
52 ; RV32I-NEXT: srli a5, a0, 1
53 ; RV32I-NEXT: lui a3, 349525
54 ; RV32I-NEXT: addi a3, a3, 1365
55 ; RV32I-NEXT: and a5, a5, a3
56 ; RV32I-NEXT: and a3, a4, a3
57 ; RV32I-NEXT: or a1, a3, a1
58 ; RV32I-NEXT: or a0, a5, a0
59 ; RV32I-NEXT: or a0, a0, a2
60 ; RV32I-NEXT: or a1, a1, a6
63 ; RV32B-LABEL: gorc1_i64:
65 ; RV32B-NEXT: orc.p a0, a0
66 ; RV32B-NEXT: orc.p a1, a1
69 ; RV32ZBP-LABEL: gorc1_i64:
71 ; RV32ZBP-NEXT: orc.p a0, a0
72 ; RV32ZBP-NEXT: orc.p a1, a1
75 %shl = and i64 %and, -6148914691236517206
76 %and1 = lshr i64 %a, 1
77 %shr = and i64 %and1, 6148914691236517205
79 %or2 = or i64 %or, %shl
83 define i32 @gorc2_i32(i32 %a) nounwind {
84 ; RV32I-LABEL: gorc2_i32:
86 ; RV32I-NEXT: slli a1, a0, 2
87 ; RV32I-NEXT: lui a2, 838861
88 ; RV32I-NEXT: addi a2, a2, -820
89 ; RV32I-NEXT: and a1, a1, a2
90 ; RV32I-NEXT: srli a2, a0, 2
91 ; RV32I-NEXT: lui a3, 209715
92 ; RV32I-NEXT: addi a3, a3, 819
93 ; RV32I-NEXT: and a2, a2, a3
94 ; RV32I-NEXT: or a0, a2, a0
95 ; RV32I-NEXT: or a0, a0, a1
98 ; RV32B-LABEL: gorc2_i32:
100 ; RV32B-NEXT: orc2.n a0, a0
103 ; RV32ZBP-LABEL: gorc2_i32:
105 ; RV32ZBP-NEXT: orc2.n a0, a0
108 %shl = and i32 %and, -858993460
109 %and1 = lshr i32 %a, 2
110 %shr = and i32 %and1, 858993459
111 %or = or i32 %shr, %a
112 %or2 = or i32 %or, %shl
116 define i64 @gorc2_i64(i64 %a) nounwind {
117 ; RV32I-LABEL: gorc2_i64:
119 ; RV32I-NEXT: slli a2, a0, 2
120 ; RV32I-NEXT: slli a3, a1, 2
121 ; RV32I-NEXT: lui a4, 838861
122 ; RV32I-NEXT: addi a4, a4, -820
123 ; RV32I-NEXT: and a6, a3, a4
124 ; RV32I-NEXT: and a2, a2, a4
125 ; RV32I-NEXT: srli a4, a1, 2
126 ; RV32I-NEXT: srli a5, a0, 2
127 ; RV32I-NEXT: lui a3, 209715
128 ; RV32I-NEXT: addi a3, a3, 819
129 ; RV32I-NEXT: and a5, a5, a3
130 ; RV32I-NEXT: and a3, a4, a3
131 ; RV32I-NEXT: or a1, a3, a1
132 ; RV32I-NEXT: or a0, a5, a0
133 ; RV32I-NEXT: or a0, a0, a2
134 ; RV32I-NEXT: or a1, a1, a6
137 ; RV32B-LABEL: gorc2_i64:
139 ; RV32B-NEXT: orc2.n a0, a0
140 ; RV32B-NEXT: orc2.n a1, a1
143 ; RV32ZBP-LABEL: gorc2_i64:
145 ; RV32ZBP-NEXT: orc2.n a0, a0
146 ; RV32ZBP-NEXT: orc2.n a1, a1
149 %shl = and i64 %and, -3689348814741910324
150 %and1 = lshr i64 %a, 2
151 %shr = and i64 %and1, 3689348814741910323
152 %or = or i64 %shr, %a
153 %or2 = or i64 %or, %shl
157 define i32 @gorc3_i32(i32 %a) nounwind {
158 ; RV32I-LABEL: gorc3_i32:
160 ; RV32I-NEXT: slli a1, a0, 1
161 ; RV32I-NEXT: lui a2, 699051
162 ; RV32I-NEXT: addi a2, a2, -1366
163 ; RV32I-NEXT: and a1, a1, a2
164 ; RV32I-NEXT: srli a2, a0, 1
165 ; RV32I-NEXT: lui a3, 349525
166 ; RV32I-NEXT: addi a3, a3, 1365
167 ; RV32I-NEXT: and a2, a2, a3
168 ; RV32I-NEXT: or a0, a2, a0
169 ; RV32I-NEXT: or a0, a0, a1
170 ; RV32I-NEXT: slli a1, a0, 2
171 ; RV32I-NEXT: lui a2, 838861
172 ; RV32I-NEXT: addi a2, a2, -820
173 ; RV32I-NEXT: and a1, a1, a2
174 ; RV32I-NEXT: srli a2, a0, 2
175 ; RV32I-NEXT: lui a3, 209715
176 ; RV32I-NEXT: addi a3, a3, 819
177 ; RV32I-NEXT: and a2, a2, a3
178 ; RV32I-NEXT: or a0, a2, a0
179 ; RV32I-NEXT: or a0, a0, a1
182 ; RV32B-LABEL: gorc3_i32:
184 ; RV32B-NEXT: orc.n a0, a0
187 ; RV32ZBP-LABEL: gorc3_i32:
189 ; RV32ZBP-NEXT: orc.n a0, a0
191 %and1 = shl i32 %a, 1
192 %shl1 = and i32 %and1, -1431655766
193 %and1b = lshr i32 %a, 1
194 %shr1 = and i32 %and1b, 1431655765
195 %or1 = or i32 %shr1, %a
196 %or1b = or i32 %or1, %shl1
197 %and2 = shl i32 %or1b, 2
198 %shl2 = and i32 %and2, -858993460
199 %and2b = lshr i32 %or1b, 2
200 %shr2 = and i32 %and2b, 858993459
201 %or2 = or i32 %shr2, %or1b
202 %or2b = or i32 %or2, %shl2
206 define i64 @gorc3_i64(i64 %a) nounwind {
207 ; RV32I-LABEL: gorc3_i64:
209 ; RV32I-NEXT: slli a2, a1, 1
210 ; RV32I-NEXT: slli a3, a0, 1
211 ; RV32I-NEXT: lui a4, 699051
212 ; RV32I-NEXT: addi a4, a4, -1366
213 ; RV32I-NEXT: and a6, a3, a4
214 ; RV32I-NEXT: and a2, a2, a4
215 ; RV32I-NEXT: srli a4, a0, 1
216 ; RV32I-NEXT: srli a5, a1, 1
217 ; RV32I-NEXT: lui a3, 349525
218 ; RV32I-NEXT: addi a3, a3, 1365
219 ; RV32I-NEXT: and a5, a5, a3
220 ; RV32I-NEXT: and a3, a4, a3
221 ; RV32I-NEXT: or a0, a3, a0
222 ; RV32I-NEXT: or a1, a5, a1
223 ; RV32I-NEXT: or a1, a1, a2
224 ; RV32I-NEXT: or a0, a0, a6
225 ; RV32I-NEXT: slli a2, a0, 2
226 ; RV32I-NEXT: slli a3, a1, 2
227 ; RV32I-NEXT: lui a4, 838861
228 ; RV32I-NEXT: addi a4, a4, -820
229 ; RV32I-NEXT: and a6, a3, a4
230 ; RV32I-NEXT: and a2, a2, a4
231 ; RV32I-NEXT: srli a4, a1, 2
232 ; RV32I-NEXT: srli a5, a0, 2
233 ; RV32I-NEXT: lui a3, 209715
234 ; RV32I-NEXT: addi a3, a3, 819
235 ; RV32I-NEXT: and a5, a5, a3
236 ; RV32I-NEXT: and a3, a4, a3
237 ; RV32I-NEXT: or a1, a3, a1
238 ; RV32I-NEXT: or a0, a5, a0
239 ; RV32I-NEXT: or a0, a0, a2
240 ; RV32I-NEXT: or a1, a1, a6
243 ; RV32B-LABEL: gorc3_i64:
245 ; RV32B-NEXT: orc.n a0, a0
246 ; RV32B-NEXT: orc.n a1, a1
249 ; RV32ZBP-LABEL: gorc3_i64:
251 ; RV32ZBP-NEXT: orc.n a0, a0
252 ; RV32ZBP-NEXT: orc.n a1, a1
254 %and1 = shl i64 %a, 1
255 %shl1 = and i64 %and1, -6148914691236517206
256 %and1b = lshr i64 %a, 1
257 %shr1 = and i64 %and1b, 6148914691236517205
258 %or1 = or i64 %shr1, %a
259 %or1b = or i64 %or1, %shl1
260 %and2 = shl i64 %or1b, 2
261 %shl2 = and i64 %and2, -3689348814741910324
262 %and2b = lshr i64 %or1b, 2
263 %shr2 = and i64 %and2b, 3689348814741910323
264 %or2 = or i64 %shr2, %or1b
265 %or2b = or i64 %or2, %shl2
269 define i32 @gorc4_i32(i32 %a) nounwind {
270 ; RV32I-LABEL: gorc4_i32:
272 ; RV32I-NEXT: slli a1, a0, 4
273 ; RV32I-NEXT: lui a2, 986895
274 ; RV32I-NEXT: addi a2, a2, 240
275 ; RV32I-NEXT: and a1, a1, a2
276 ; RV32I-NEXT: srli a2, a0, 4
277 ; RV32I-NEXT: lui a3, 61681
278 ; RV32I-NEXT: addi a3, a3, -241
279 ; RV32I-NEXT: and a2, a2, a3
280 ; RV32I-NEXT: or a0, a2, a0
281 ; RV32I-NEXT: or a0, a0, a1
284 ; RV32B-LABEL: gorc4_i32:
286 ; RV32B-NEXT: orc4.b a0, a0
289 ; RV32ZBP-LABEL: gorc4_i32:
291 ; RV32ZBP-NEXT: orc4.b a0, a0
294 %shl = and i32 %and, -252645136
295 %and1 = lshr i32 %a, 4
296 %shr = and i32 %and1, 252645135
297 %or = or i32 %shr, %a
298 %or2 = or i32 %or, %shl
302 define i64 @gorc4_i64(i64 %a) nounwind {
303 ; RV32I-LABEL: gorc4_i64:
305 ; RV32I-NEXT: slli a2, a0, 4
306 ; RV32I-NEXT: slli a3, a1, 4
307 ; RV32I-NEXT: lui a4, 986895
308 ; RV32I-NEXT: addi a4, a4, 240
309 ; RV32I-NEXT: and a6, a3, a4
310 ; RV32I-NEXT: and a2, a2, a4
311 ; RV32I-NEXT: srli a4, a1, 4
312 ; RV32I-NEXT: srli a5, a0, 4
313 ; RV32I-NEXT: lui a3, 61681
314 ; RV32I-NEXT: addi a3, a3, -241
315 ; RV32I-NEXT: and a5, a5, a3
316 ; RV32I-NEXT: and a3, a4, a3
317 ; RV32I-NEXT: or a1, a3, a1
318 ; RV32I-NEXT: or a0, a5, a0
319 ; RV32I-NEXT: or a0, a0, a2
320 ; RV32I-NEXT: or a1, a1, a6
323 ; RV32B-LABEL: gorc4_i64:
325 ; RV32B-NEXT: orc4.b a0, a0
326 ; RV32B-NEXT: orc4.b a1, a1
329 ; RV32ZBP-LABEL: gorc4_i64:
331 ; RV32ZBP-NEXT: orc4.b a0, a0
332 ; RV32ZBP-NEXT: orc4.b a1, a1
335 %shl = and i64 %and, -1085102592571150096
336 %and1 = lshr i64 %a, 4
337 %shr = and i64 %and1, 1085102592571150095
338 %or = or i64 %shr, %a
339 %or2 = or i64 %or, %shl
343 define i32 @gorc5_i32(i32 %a) nounwind {
344 ; RV32I-LABEL: gorc5_i32:
346 ; RV32I-NEXT: slli a1, a0, 1
347 ; RV32I-NEXT: lui a2, 699051
348 ; RV32I-NEXT: addi a2, a2, -1366
349 ; RV32I-NEXT: and a1, a1, a2
350 ; RV32I-NEXT: srli a2, a0, 1
351 ; RV32I-NEXT: lui a3, 349525
352 ; RV32I-NEXT: addi a3, a3, 1365
353 ; RV32I-NEXT: and a2, a2, a3
354 ; RV32I-NEXT: or a0, a2, a0
355 ; RV32I-NEXT: or a0, a0, a1
356 ; RV32I-NEXT: slli a1, a0, 4
357 ; RV32I-NEXT: lui a2, 986895
358 ; RV32I-NEXT: addi a2, a2, 240
359 ; RV32I-NEXT: and a1, a1, a2
360 ; RV32I-NEXT: srli a2, a0, 4
361 ; RV32I-NEXT: lui a3, 61681
362 ; RV32I-NEXT: addi a3, a3, -241
363 ; RV32I-NEXT: and a2, a2, a3
364 ; RV32I-NEXT: or a0, a2, a0
365 ; RV32I-NEXT: or a0, a0, a1
368 ; RV32B-LABEL: gorc5_i32:
370 ; RV32B-NEXT: gorci a0, a0, 5
373 ; RV32ZBP-LABEL: gorc5_i32:
375 ; RV32ZBP-NEXT: gorci a0, a0, 5
377 %and1 = shl i32 %a, 1
378 %shl1 = and i32 %and1, -1431655766
379 %and1b = lshr i32 %a, 1
380 %shr1 = and i32 %and1b, 1431655765
381 %or1 = or i32 %shr1, %a
382 %or1b = or i32 %or1, %shl1
383 %and2 = shl i32 %or1b, 4
384 %shl2 = and i32 %and2, -252645136
385 %and2b = lshr i32 %or1b, 4
386 %shr2 = and i32 %and2b, 252645135
387 %or2 = or i32 %shr2, %or1b
388 %or2b = or i32 %or2, %shl2
392 define i64 @gorc5_i64(i64 %a) nounwind {
393 ; RV32I-LABEL: gorc5_i64:
395 ; RV32I-NEXT: slli a2, a1, 1
396 ; RV32I-NEXT: slli a3, a0, 1
397 ; RV32I-NEXT: lui a4, 699051
398 ; RV32I-NEXT: addi a4, a4, -1366
399 ; RV32I-NEXT: and a6, a3, a4
400 ; RV32I-NEXT: and a2, a2, a4
401 ; RV32I-NEXT: srli a4, a0, 1
402 ; RV32I-NEXT: srli a5, a1, 1
403 ; RV32I-NEXT: lui a3, 349525
404 ; RV32I-NEXT: addi a3, a3, 1365
405 ; RV32I-NEXT: and a5, a5, a3
406 ; RV32I-NEXT: and a3, a4, a3
407 ; RV32I-NEXT: or a0, a3, a0
408 ; RV32I-NEXT: or a1, a5, a1
409 ; RV32I-NEXT: or a1, a1, a2
410 ; RV32I-NEXT: or a0, a0, a6
411 ; RV32I-NEXT: slli a2, a0, 4
412 ; RV32I-NEXT: slli a3, a1, 4
413 ; RV32I-NEXT: lui a4, 986895
414 ; RV32I-NEXT: addi a4, a4, 240
415 ; RV32I-NEXT: and a6, a3, a4
416 ; RV32I-NEXT: and a2, a2, a4
417 ; RV32I-NEXT: srli a4, a1, 4
418 ; RV32I-NEXT: srli a5, a0, 4
419 ; RV32I-NEXT: lui a3, 61681
420 ; RV32I-NEXT: addi a3, a3, -241
421 ; RV32I-NEXT: and a5, a5, a3
422 ; RV32I-NEXT: and a3, a4, a3
423 ; RV32I-NEXT: or a1, a3, a1
424 ; RV32I-NEXT: or a0, a5, a0
425 ; RV32I-NEXT: or a0, a0, a2
426 ; RV32I-NEXT: or a1, a1, a6
429 ; RV32B-LABEL: gorc5_i64:
431 ; RV32B-NEXT: gorci a0, a0, 5
432 ; RV32B-NEXT: gorci a1, a1, 5
435 ; RV32ZBP-LABEL: gorc5_i64:
437 ; RV32ZBP-NEXT: gorci a0, a0, 5
438 ; RV32ZBP-NEXT: gorci a1, a1, 5
440 %and1 = shl i64 %a, 1
441 %shl1 = and i64 %and1, -6148914691236517206
442 %and1b = lshr i64 %a, 1
443 %shr1 = and i64 %and1b, 6148914691236517205
444 %or1 = or i64 %shr1, %a
445 %or1b = or i64 %or1, %shl1
446 %and2 = shl i64 %or1b, 4
447 %shl2 = and i64 %and2, -1085102592571150096
448 %and2b = lshr i64 %or1b, 4
449 %shr2 = and i64 %and2b, 1085102592571150095
450 %or2 = or i64 %shr2, %or1b
451 %or2b = or i64 %or2, %shl2
455 define i32 @gorc6_i32(i32 %a) nounwind {
456 ; RV32I-LABEL: gorc6_i32:
458 ; RV32I-NEXT: slli a1, a0, 2
459 ; RV32I-NEXT: lui a2, 838861
460 ; RV32I-NEXT: addi a2, a2, -820
461 ; RV32I-NEXT: and a1, a1, a2
462 ; RV32I-NEXT: srli a2, a0, 2
463 ; RV32I-NEXT: lui a3, 209715
464 ; RV32I-NEXT: addi a3, a3, 819
465 ; RV32I-NEXT: and a2, a2, a3
466 ; RV32I-NEXT: or a0, a2, a0
467 ; RV32I-NEXT: or a0, a0, a1
468 ; RV32I-NEXT: slli a1, a0, 4
469 ; RV32I-NEXT: lui a2, 986895
470 ; RV32I-NEXT: addi a2, a2, 240
471 ; RV32I-NEXT: and a1, a1, a2
472 ; RV32I-NEXT: srli a2, a0, 4
473 ; RV32I-NEXT: lui a3, 61681
474 ; RV32I-NEXT: addi a3, a3, -241
475 ; RV32I-NEXT: and a2, a2, a3
476 ; RV32I-NEXT: or a0, a2, a0
477 ; RV32I-NEXT: or a0, a0, a1
480 ; RV32B-LABEL: gorc6_i32:
482 ; RV32B-NEXT: orc2.b a0, a0
485 ; RV32ZBP-LABEL: gorc6_i32:
487 ; RV32ZBP-NEXT: orc2.b a0, a0
489 %and1 = shl i32 %a, 2
490 %shl1 = and i32 %and1, -858993460
491 %and1b = lshr i32 %a, 2
492 %shr1 = and i32 %and1b, 858993459
493 %or1 = or i32 %shr1, %a
494 %or1b = or i32 %or1, %shl1
495 %and2 = shl i32 %or1b, 4
496 %shl2 = and i32 %and2, -252645136
497 %and2b = lshr i32 %or1b, 4
498 %shr2 = and i32 %and2b, 252645135
499 %or2 = or i32 %shr2, %or1b
500 %or2b = or i32 %or2, %shl2
504 define i64 @gorc6_i64(i64 %a) nounwind {
505 ; RV32I-LABEL: gorc6_i64:
507 ; RV32I-NEXT: slli a2, a1, 2
508 ; RV32I-NEXT: slli a3, a0, 2
509 ; RV32I-NEXT: lui a4, 838861
510 ; RV32I-NEXT: addi a4, a4, -820
511 ; RV32I-NEXT: and a6, a3, a4
512 ; RV32I-NEXT: and a2, a2, a4
513 ; RV32I-NEXT: srli a4, a0, 2
514 ; RV32I-NEXT: srli a5, a1, 2
515 ; RV32I-NEXT: lui a3, 209715
516 ; RV32I-NEXT: addi a3, a3, 819
517 ; RV32I-NEXT: and a5, a5, a3
518 ; RV32I-NEXT: and a3, a4, a3
519 ; RV32I-NEXT: or a0, a3, a0
520 ; RV32I-NEXT: or a1, a5, a1
521 ; RV32I-NEXT: or a1, a1, a2
522 ; RV32I-NEXT: or a0, a0, a6
523 ; RV32I-NEXT: slli a2, a0, 4
524 ; RV32I-NEXT: slli a3, a1, 4
525 ; RV32I-NEXT: lui a4, 986895
526 ; RV32I-NEXT: addi a4, a4, 240
527 ; RV32I-NEXT: and a6, a3, a4
528 ; RV32I-NEXT: and a2, a2, a4
529 ; RV32I-NEXT: srli a4, a1, 4
530 ; RV32I-NEXT: srli a5, a0, 4
531 ; RV32I-NEXT: lui a3, 61681
532 ; RV32I-NEXT: addi a3, a3, -241
533 ; RV32I-NEXT: and a5, a5, a3
534 ; RV32I-NEXT: and a3, a4, a3
535 ; RV32I-NEXT: or a1, a3, a1
536 ; RV32I-NEXT: or a0, a5, a0
537 ; RV32I-NEXT: or a0, a0, a2
538 ; RV32I-NEXT: or a1, a1, a6
541 ; RV32B-LABEL: gorc6_i64:
543 ; RV32B-NEXT: orc2.b a0, a0
544 ; RV32B-NEXT: orc2.b a1, a1
547 ; RV32ZBP-LABEL: gorc6_i64:
549 ; RV32ZBP-NEXT: orc2.b a0, a0
550 ; RV32ZBP-NEXT: orc2.b a1, a1
552 %and1 = shl i64 %a, 2
553 %shl1 = and i64 %and1, -3689348814741910324
554 %and1b = lshr i64 %a, 2
555 %shr1 = and i64 %and1b, 3689348814741910323
556 %or1 = or i64 %shr1, %a
557 %or1b = or i64 %or1, %shl1
558 %and2 = shl i64 %or1b, 4
559 %shl2 = and i64 %and2, -1085102592571150096
560 %and2b = lshr i64 %or1b, 4
561 %shr2 = and i64 %and2b, 1085102592571150095
562 %or2 = or i64 %shr2, %or1b
563 %or2b = or i64 %or2, %shl2
567 define i32 @gorc7_i32(i32 %a) nounwind {
568 ; RV32I-LABEL: gorc7_i32:
570 ; RV32I-NEXT: slli a1, a0, 1
571 ; RV32I-NEXT: lui a2, 699051
572 ; RV32I-NEXT: addi a2, a2, -1366
573 ; RV32I-NEXT: and a1, a1, a2
574 ; RV32I-NEXT: srli a2, a0, 1
575 ; RV32I-NEXT: lui a3, 349525
576 ; RV32I-NEXT: addi a3, a3, 1365
577 ; RV32I-NEXT: and a2, a2, a3
578 ; RV32I-NEXT: or a0, a2, a0
579 ; RV32I-NEXT: or a0, a0, a1
580 ; RV32I-NEXT: slli a1, a0, 2
581 ; RV32I-NEXT: lui a2, 838861
582 ; RV32I-NEXT: addi a2, a2, -820
583 ; RV32I-NEXT: and a1, a1, a2
584 ; RV32I-NEXT: srli a2, a0, 2
585 ; RV32I-NEXT: lui a3, 209715
586 ; RV32I-NEXT: addi a3, a3, 819
587 ; RV32I-NEXT: and a2, a2, a3
588 ; RV32I-NEXT: or a0, a2, a0
589 ; RV32I-NEXT: or a0, a0, a1
590 ; RV32I-NEXT: slli a1, a0, 4
591 ; RV32I-NEXT: lui a2, 986895
592 ; RV32I-NEXT: addi a2, a2, 240
593 ; RV32I-NEXT: and a1, a1, a2
594 ; RV32I-NEXT: srli a2, a0, 4
595 ; RV32I-NEXT: lui a3, 61681
596 ; RV32I-NEXT: addi a3, a3, -241
597 ; RV32I-NEXT: and a2, a2, a3
598 ; RV32I-NEXT: or a0, a2, a0
599 ; RV32I-NEXT: or a0, a0, a1
602 ; RV32B-LABEL: gorc7_i32:
604 ; RV32B-NEXT: orc.b a0, a0
607 ; RV32ZBP-LABEL: gorc7_i32:
609 ; RV32ZBP-NEXT: orc.b a0, a0
611 %and1 = shl i32 %a, 1
612 %shl1 = and i32 %and1, -1431655766
613 %and1b = lshr i32 %a, 1
614 %shr1 = and i32 %and1b, 1431655765
615 %or1 = or i32 %shr1, %a
616 %or1b = or i32 %or1, %shl1
617 %and2 = shl i32 %or1b, 2
618 %shl2 = and i32 %and2, -858993460
619 %and2b = lshr i32 %or1b, 2
620 %shr2 = and i32 %and2b, 858993459
621 %or2 = or i32 %shr2, %or1b
622 %or2b = or i32 %or2, %shl2
623 %and3 = shl i32 %or2b, 4
624 %shl3 = and i32 %and3, -252645136
625 %and3b = lshr i32 %or2b, 4
626 %shr3 = and i32 %and3b, 252645135
627 %or3 = or i32 %shr3, %or2b
628 %or3b = or i32 %or3, %shl3
632 define i64 @gorc7_i64(i64 %a) nounwind {
633 ; RV32I-LABEL: gorc7_i64:
635 ; RV32I-NEXT: slli a2, a0, 1
636 ; RV32I-NEXT: slli a3, a1, 1
637 ; RV32I-NEXT: lui a4, 699051
638 ; RV32I-NEXT: addi a4, a4, -1366
639 ; RV32I-NEXT: and a6, a3, a4
640 ; RV32I-NEXT: and a2, a2, a4
641 ; RV32I-NEXT: srli a4, a1, 1
642 ; RV32I-NEXT: srli a5, a0, 1
643 ; RV32I-NEXT: lui a3, 349525
644 ; RV32I-NEXT: addi a3, a3, 1365
645 ; RV32I-NEXT: and a5, a5, a3
646 ; RV32I-NEXT: and a3, a4, a3
647 ; RV32I-NEXT: or a1, a3, a1
648 ; RV32I-NEXT: or a0, a5, a0
649 ; RV32I-NEXT: or a0, a0, a2
650 ; RV32I-NEXT: or a1, a1, a6
651 ; RV32I-NEXT: slli a2, a1, 2
652 ; RV32I-NEXT: slli a3, a0, 2
653 ; RV32I-NEXT: lui a4, 838861
654 ; RV32I-NEXT: addi a4, a4, -820
655 ; RV32I-NEXT: and a6, a3, a4
656 ; RV32I-NEXT: and a2, a2, a4
657 ; RV32I-NEXT: srli a4, a0, 2
658 ; RV32I-NEXT: srli a5, a1, 2
659 ; RV32I-NEXT: lui a3, 209715
660 ; RV32I-NEXT: addi a3, a3, 819
661 ; RV32I-NEXT: and a5, a5, a3
662 ; RV32I-NEXT: and a3, a4, a3
663 ; RV32I-NEXT: or a0, a3, a0
664 ; RV32I-NEXT: or a1, a5, a1
665 ; RV32I-NEXT: or a1, a1, a2
666 ; RV32I-NEXT: or a0, a0, a6
667 ; RV32I-NEXT: slli a2, a0, 4
668 ; RV32I-NEXT: slli a3, a1, 4
669 ; RV32I-NEXT: lui a4, 986895
670 ; RV32I-NEXT: addi a4, a4, 240
671 ; RV32I-NEXT: and a6, a3, a4
672 ; RV32I-NEXT: and a2, a2, a4
673 ; RV32I-NEXT: srli a4, a1, 4
674 ; RV32I-NEXT: srli a5, a0, 4
675 ; RV32I-NEXT: lui a3, 61681
676 ; RV32I-NEXT: addi a3, a3, -241
677 ; RV32I-NEXT: and a5, a5, a3
678 ; RV32I-NEXT: and a3, a4, a3
679 ; RV32I-NEXT: or a1, a3, a1
680 ; RV32I-NEXT: or a0, a5, a0
681 ; RV32I-NEXT: or a0, a0, a2
682 ; RV32I-NEXT: or a1, a1, a6
685 ; RV32B-LABEL: gorc7_i64:
687 ; RV32B-NEXT: orc.b a0, a0
688 ; RV32B-NEXT: orc.b a1, a1
691 ; RV32ZBP-LABEL: gorc7_i64:
693 ; RV32ZBP-NEXT: orc.b a0, a0
694 ; RV32ZBP-NEXT: orc.b a1, a1
696 %and1 = shl i64 %a, 1
697 %shl1 = and i64 %and1, -6148914691236517206
698 %and1b = lshr i64 %a, 1
699 %shr1 = and i64 %and1b, 6148914691236517205
700 %or1 = or i64 %shr1, %a
701 %or1b = or i64 %or1, %shl1
702 %and2 = shl i64 %or1b, 2
703 %shl2 = and i64 %and2, -3689348814741910324
704 %and2b = lshr i64 %or1b, 2
705 %shr2 = and i64 %and2b, 3689348814741910323
706 %or2 = or i64 %shr2, %or1b
707 %or2b = or i64 %or2, %shl2
708 %and3 = shl i64 %or2b, 4
709 %shl3 = and i64 %and3, -1085102592571150096
710 %and3b = lshr i64 %or2b, 4
711 %shr3 = and i64 %and3b, 1085102592571150095
712 %or3 = or i64 %shr3, %or2b
713 %or3b = or i64 %or3, %shl3
717 define i32 @gorc8_i32(i32 %a) nounwind {
718 ; RV32I-LABEL: gorc8_i32:
720 ; RV32I-NEXT: slli a1, a0, 8
721 ; RV32I-NEXT: lui a2, 1044496
722 ; RV32I-NEXT: addi a2, a2, -256
723 ; RV32I-NEXT: and a1, a1, a2
724 ; RV32I-NEXT: srli a2, a0, 8
725 ; RV32I-NEXT: lui a3, 4080
726 ; RV32I-NEXT: addi a3, a3, 255
727 ; RV32I-NEXT: and a2, a2, a3
728 ; RV32I-NEXT: or a0, a2, a0
729 ; RV32I-NEXT: or a0, a0, a1
732 ; RV32B-LABEL: gorc8_i32:
734 ; RV32B-NEXT: orc8.h a0, a0
737 ; RV32ZBP-LABEL: gorc8_i32:
739 ; RV32ZBP-NEXT: orc8.h a0, a0
742 %shl = and i32 %and, -16711936
743 %and1 = lshr i32 %a, 8
744 %shr = and i32 %and1, 16711935
745 %or = or i32 %shr, %a
746 %or2 = or i32 %or, %shl
750 define i64 @gorc8_i64(i64 %a) nounwind {
751 ; RV32I-LABEL: gorc8_i64:
753 ; RV32I-NEXT: slli a2, a0, 8
754 ; RV32I-NEXT: slli a3, a1, 8
755 ; RV32I-NEXT: lui a4, 1044496
756 ; RV32I-NEXT: addi a4, a4, -256
757 ; RV32I-NEXT: and a6, a3, a4
758 ; RV32I-NEXT: and a2, a2, a4
759 ; RV32I-NEXT: srli a4, a1, 8
760 ; RV32I-NEXT: srli a5, a0, 8
761 ; RV32I-NEXT: lui a3, 4080
762 ; RV32I-NEXT: addi a3, a3, 255
763 ; RV32I-NEXT: and a5, a5, a3
764 ; RV32I-NEXT: and a3, a4, a3
765 ; RV32I-NEXT: or a1, a3, a1
766 ; RV32I-NEXT: or a0, a5, a0
767 ; RV32I-NEXT: or a0, a0, a2
768 ; RV32I-NEXT: or a1, a1, a6
771 ; RV32B-LABEL: gorc8_i64:
773 ; RV32B-NEXT: orc8.h a0, a0
774 ; RV32B-NEXT: orc8.h a1, a1
777 ; RV32ZBP-LABEL: gorc8_i64:
779 ; RV32ZBP-NEXT: orc8.h a0, a0
780 ; RV32ZBP-NEXT: orc8.h a1, a1
783 %shl = and i64 %and, -71777214294589696
784 %and1 = lshr i64 %a, 8
785 %shr = and i64 %and1, 71777214294589695
786 %or = or i64 %shr, %a
787 %or2 = or i64 %or, %shl
791 define i32 @gorc16_i32(i32 %a) nounwind {
792 ; RV32I-LABEL: gorc16_i32:
794 ; RV32I-NEXT: slli a1, a0, 16
795 ; RV32I-NEXT: srli a2, a0, 16
796 ; RV32I-NEXT: or a0, a2, a0
797 ; RV32I-NEXT: or a0, a0, a1
800 ; RV32B-LABEL: gorc16_i32:
802 ; RV32B-NEXT: orc16 a0, a0
805 ; RV32ZBP-LABEL: gorc16_i32:
807 ; RV32ZBP-NEXT: orc16 a0, a0
809 %shl = shl i32 %a, 16
810 %shr = lshr i32 %a, 16
811 %or = or i32 %shr, %a
812 %or2 = or i32 %or, %shl
816 define i32 @gorc16_rotl_i32(i32 %a) nounwind {
817 ; RV32I-LABEL: gorc16_rotl_i32:
819 ; RV32I-NEXT: srli a1, a0, 16
820 ; RV32I-NEXT: slli a2, a0, 16
821 ; RV32I-NEXT: or a1, a2, a1
822 ; RV32I-NEXT: or a0, a1, a0
825 ; RV32B-LABEL: gorc16_rotl_i32:
827 ; RV32B-NEXT: orc16 a0, a0
830 ; RV32ZBP-LABEL: gorc16_rotl_i32:
832 ; RV32ZBP-NEXT: orc16 a0, a0
834 %rot = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 16)
835 %or = or i32 %rot, %a
839 define i32 @gorc16_rotr_i32(i32 %a) nounwind {
840 ; RV32I-LABEL: gorc16_rotr_i32:
842 ; RV32I-NEXT: slli a1, a0, 16
843 ; RV32I-NEXT: srli a2, a0, 16
844 ; RV32I-NEXT: or a1, a2, a1
845 ; RV32I-NEXT: or a0, a1, a0
848 ; RV32B-LABEL: gorc16_rotr_i32:
850 ; RV32B-NEXT: orc16 a0, a0
853 ; RV32ZBP-LABEL: gorc16_rotr_i32:
855 ; RV32ZBP-NEXT: orc16 a0, a0
857 %rot = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 16)
858 %or = or i32 %rot, %a
862 define i64 @gorc16_i64(i64 %a) nounwind {
863 ; RV32I-LABEL: gorc16_i64:
865 ; RV32I-NEXT: slli a2, a1, 16
866 ; RV32I-NEXT: slli a3, a0, 16
867 ; RV32I-NEXT: srli a4, a0, 16
868 ; RV32I-NEXT: srli a5, a1, 16
869 ; RV32I-NEXT: or a1, a5, a1
870 ; RV32I-NEXT: or a0, a4, a0
871 ; RV32I-NEXT: or a0, a0, a3
872 ; RV32I-NEXT: or a1, a1, a2
875 ; RV32B-LABEL: gorc16_i64:
877 ; RV32B-NEXT: orc16 a0, a0
878 ; RV32B-NEXT: orc16 a1, a1
881 ; RV32ZBP-LABEL: gorc16_i64:
883 ; RV32ZBP-NEXT: orc16 a0, a0
884 ; RV32ZBP-NEXT: orc16 a1, a1
886 %and = shl i64 %a, 16
887 %shl = and i64 %and, -281470681808896
888 %and1 = lshr i64 %a, 16
889 %shr = and i64 %and1, 281470681808895
890 %or = or i64 %shr, %a
891 %or2 = or i64 %or, %shl
895 ; gorc2, gorc2 -> gorc2
896 define i32 @gorc2b_i32(i32 %a) nounwind {
897 ; RV32I-LABEL: gorc2b_i32:
899 ; RV32I-NEXT: slli a1, a0, 2
900 ; RV32I-NEXT: lui a2, 838861
901 ; RV32I-NEXT: addi a2, a2, -820
902 ; RV32I-NEXT: and a1, a1, a2
903 ; RV32I-NEXT: srli a3, a0, 2
904 ; RV32I-NEXT: lui a4, 209715
905 ; RV32I-NEXT: addi a4, a4, 819
906 ; RV32I-NEXT: and a3, a3, a4
907 ; RV32I-NEXT: or a0, a3, a0
908 ; RV32I-NEXT: or a0, a0, a1
909 ; RV32I-NEXT: slli a1, a0, 2
910 ; RV32I-NEXT: and a1, a1, a2
911 ; RV32I-NEXT: srli a2, a0, 2
912 ; RV32I-NEXT: and a2, a2, a4
913 ; RV32I-NEXT: or a0, a2, a0
914 ; RV32I-NEXT: or a0, a0, a1
917 ; RV32B-LABEL: gorc2b_i32:
919 ; RV32B-NEXT: orc2.n a0, a0
922 ; RV32ZBP-LABEL: gorc2b_i32:
924 ; RV32ZBP-NEXT: orc2.n a0, a0
926 %and1 = shl i32 %a, 2
927 %shl1 = and i32 %and1, -858993460
928 %and1b = lshr i32 %a, 2
929 %shr1 = and i32 %and1b, 858993459
930 %or1 = or i32 %shr1, %a
931 %or1b = or i32 %or1, %shl1
932 %and2 = shl i32 %or1b, 2
933 %shl2 = and i32 %and2, -858993460
934 %and2b = lshr i32 %or1b, 2
935 %shr2 = and i32 %and2b, 858993459
936 %or2 = or i32 %shr2, %or1b
937 %or2b = or i32 %or2, %shl2
941 ; gorc2, gorc2 -> gorc2
942 define i64 @gorc2b_i64(i64 %a) nounwind {
943 ; RV32I-LABEL: gorc2b_i64:
945 ; RV32I-NEXT: slli a2, a1, 2
946 ; RV32I-NEXT: slli a3, a0, 2
947 ; RV32I-NEXT: lui a4, 838861
948 ; RV32I-NEXT: addi a4, a4, -820
949 ; RV32I-NEXT: and a6, a3, a4
950 ; RV32I-NEXT: and a7, a2, a4
951 ; RV32I-NEXT: srli a5, a0, 2
952 ; RV32I-NEXT: srli a3, a1, 2
953 ; RV32I-NEXT: lui a2, 209715
954 ; RV32I-NEXT: addi a2, a2, 819
955 ; RV32I-NEXT: and a3, a3, a2
956 ; RV32I-NEXT: and a5, a5, a2
957 ; RV32I-NEXT: or a0, a5, a0
958 ; RV32I-NEXT: or a1, a3, a1
959 ; RV32I-NEXT: or a1, a1, a7
960 ; RV32I-NEXT: or a0, a0, a6
961 ; RV32I-NEXT: slli a3, a0, 2
962 ; RV32I-NEXT: slli a5, a1, 2
963 ; RV32I-NEXT: and a6, a5, a4
964 ; RV32I-NEXT: and a3, a3, a4
965 ; RV32I-NEXT: srli a4, a1, 2
966 ; RV32I-NEXT: srli a5, a0, 2
967 ; RV32I-NEXT: and a5, a5, a2
968 ; RV32I-NEXT: and a2, a4, a2
969 ; RV32I-NEXT: or a1, a2, a1
970 ; RV32I-NEXT: or a0, a5, a0
971 ; RV32I-NEXT: or a0, a0, a3
972 ; RV32I-NEXT: or a1, a1, a6
975 ; RV32B-LABEL: gorc2b_i64:
977 ; RV32B-NEXT: orc2.n a0, a0
978 ; RV32B-NEXT: orc2.n a1, a1
981 ; RV32ZBP-LABEL: gorc2b_i64:
983 ; RV32ZBP-NEXT: orc2.n a0, a0
984 ; RV32ZBP-NEXT: orc2.n a1, a1
986 %and1 = shl i64 %a, 2
987 %shl1 = and i64 %and1, -3689348814741910324
988 %and1b = lshr i64 %a, 2
989 %shr1 = and i64 %and1b, 3689348814741910323
990 %or1 = or i64 %shr1, %a
991 %or1b = or i64 %or1, %shl1
992 %and2 = shl i64 %or1b, 2
993 %shl2 = and i64 %and2, -3689348814741910324
994 %and2b = lshr i64 %or1b, 2
995 %shr2 = and i64 %and2b, 3689348814741910323
996 %or2 = or i64 %shr2, %or1b
997 %or2b = or i64 %or2, %shl2
1001 ; gorc1, gorc2, gorc1 -> gorc2
1002 define i32 @gorc3b_i32(i32 %a) nounwind {
1003 ; RV32I-LABEL: gorc3b_i32:
1005 ; RV32I-NEXT: slli a1, a0, 1
1006 ; RV32I-NEXT: lui a2, 699051
1007 ; RV32I-NEXT: addi a2, a2, -1366
1008 ; RV32I-NEXT: and a1, a1, a2
1009 ; RV32I-NEXT: srli a3, a0, 1
1010 ; RV32I-NEXT: lui a4, 349525
1011 ; RV32I-NEXT: addi a4, a4, 1365
1012 ; RV32I-NEXT: and a3, a3, a4
1013 ; RV32I-NEXT: or a0, a3, a0
1014 ; RV32I-NEXT: or a0, a0, a1
1015 ; RV32I-NEXT: slli a1, a0, 2
1016 ; RV32I-NEXT: lui a3, 838861
1017 ; RV32I-NEXT: addi a3, a3, -820
1018 ; RV32I-NEXT: and a1, a1, a3
1019 ; RV32I-NEXT: srli a3, a0, 2
1020 ; RV32I-NEXT: lui a5, 209715
1021 ; RV32I-NEXT: addi a5, a5, 819
1022 ; RV32I-NEXT: and a3, a3, a5
1023 ; RV32I-NEXT: or a0, a3, a0
1024 ; RV32I-NEXT: or a0, a0, a1
1025 ; RV32I-NEXT: slli a1, a0, 1
1026 ; RV32I-NEXT: and a1, a1, a2
1027 ; RV32I-NEXT: srli a2, a0, 1
1028 ; RV32I-NEXT: and a2, a2, a4
1029 ; RV32I-NEXT: or a0, a2, a0
1030 ; RV32I-NEXT: or a0, a0, a1
1033 ; RV32B-LABEL: gorc3b_i32:
1035 ; RV32B-NEXT: orc.n a0, a0
1038 ; RV32ZBP-LABEL: gorc3b_i32:
1040 ; RV32ZBP-NEXT: orc.n a0, a0
1042 %and1 = shl i32 %a, 1
1043 %shl1 = and i32 %and1, -1431655766
1044 %and1b = lshr i32 %a, 1
1045 %shr1 = and i32 %and1b, 1431655765
1046 %or1 = or i32 %shr1, %a
1047 %or1b = or i32 %or1, %shl1
1048 %and2 = shl i32 %or1b, 2
1049 %shl2 = and i32 %and2, -858993460
1050 %and2b = lshr i32 %or1b, 2
1051 %shr2 = and i32 %and2b, 858993459
1052 %or2 = or i32 %shr2, %or1b
1053 %or2b = or i32 %or2, %shl2
1054 %and3 = shl i32 %or2b, 1
1055 %shl3 = and i32 %and3, -1431655766
1056 %and3b = lshr i32 %or2b, 1
1057 %shr3 = and i32 %and3b, 1431655765
1058 %or3 = or i32 %shr3, %or2b
1059 %or3b = or i32 %or3, %shl3
1063 ; gorc1, gorc2, gorc1 -> gorc2
1064 define i64 @gorc3b_i64(i64 %a) nounwind {
1065 ; RV32I-LABEL: gorc3b_i64:
1067 ; RV32I-NEXT: slli a2, a0, 1
1068 ; RV32I-NEXT: slli a3, a1, 1
1069 ; RV32I-NEXT: lui a4, 699051
1070 ; RV32I-NEXT: addi a4, a4, -1366
1071 ; RV32I-NEXT: and a6, a3, a4
1072 ; RV32I-NEXT: and a7, a2, a4
1073 ; RV32I-NEXT: srli a5, a1, 1
1074 ; RV32I-NEXT: srli a3, a0, 1
1075 ; RV32I-NEXT: lui a2, 349525
1076 ; RV32I-NEXT: addi a2, a2, 1365
1077 ; RV32I-NEXT: and a3, a3, a2
1078 ; RV32I-NEXT: and a5, a5, a2
1079 ; RV32I-NEXT: or a1, a5, a1
1080 ; RV32I-NEXT: or a0, a3, a0
1081 ; RV32I-NEXT: or a0, a0, a7
1082 ; RV32I-NEXT: or a1, a1, a6
1083 ; RV32I-NEXT: slli a6, a1, 2
1084 ; RV32I-NEXT: slli a5, a0, 2
1085 ; RV32I-NEXT: lui a3, 838861
1086 ; RV32I-NEXT: addi a3, a3, -820
1087 ; RV32I-NEXT: and a7, a5, a3
1088 ; RV32I-NEXT: and a6, a6, a3
1089 ; RV32I-NEXT: srli t0, a0, 2
1090 ; RV32I-NEXT: srli a3, a1, 2
1091 ; RV32I-NEXT: lui a5, 209715
1092 ; RV32I-NEXT: addi a5, a5, 819
1093 ; RV32I-NEXT: and a3, a3, a5
1094 ; RV32I-NEXT: and a5, t0, a5
1095 ; RV32I-NEXT: or a0, a5, a0
1096 ; RV32I-NEXT: or a1, a3, a1
1097 ; RV32I-NEXT: or a1, a1, a6
1098 ; RV32I-NEXT: or a0, a0, a7
1099 ; RV32I-NEXT: slli a3, a0, 1
1100 ; RV32I-NEXT: slli a5, a1, 1
1101 ; RV32I-NEXT: and a6, a5, a4
1102 ; RV32I-NEXT: and a3, a3, a4
1103 ; RV32I-NEXT: srli a4, a1, 1
1104 ; RV32I-NEXT: srli a5, a0, 1
1105 ; RV32I-NEXT: and a5, a5, a2
1106 ; RV32I-NEXT: and a2, a4, a2
1107 ; RV32I-NEXT: or a1, a2, a1
1108 ; RV32I-NEXT: or a0, a5, a0
1109 ; RV32I-NEXT: or a0, a0, a3
1110 ; RV32I-NEXT: or a1, a1, a6
1113 ; RV32B-LABEL: gorc3b_i64:
1115 ; RV32B-NEXT: orc.n a0, a0
1116 ; RV32B-NEXT: orc.n a1, a1
1119 ; RV32ZBP-LABEL: gorc3b_i64:
1121 ; RV32ZBP-NEXT: orc.n a0, a0
1122 ; RV32ZBP-NEXT: orc.n a1, a1
1124 %and1 = shl i64 %a, 1
1125 %shl1 = and i64 %and1, -6148914691236517206
1126 %and1b = lshr i64 %a, 1
1127 %shr1 = and i64 %and1b, 6148914691236517205
1128 %or1 = or i64 %shr1, %a
1129 %or1b = or i64 %or1, %shl1
1130 %and2 = shl i64 %or1b, 2
1131 %shl2 = and i64 %and2, -3689348814741910324
1132 %and2b = lshr i64 %or1b, 2
1133 %shr2 = and i64 %and2b, 3689348814741910323
1134 %or2 = or i64 %shr2, %or1b
1135 %or2b = or i64 %or2, %shl2
1136 %and3 = shl i64 %or2b, 1
1137 %shl3 = and i64 %and3, -6148914691236517206
1138 %and3b = lshr i64 %or2b, 1
1139 %shr3 = and i64 %and3b, 6148914691236517205
1140 %or3 = or i64 %shr3, %or2b
1141 %or3b = or i64 %or3, %shl3
1145 define i32 @grev1_i32(i32 %a) nounwind {
1146 ; RV32I-LABEL: grev1_i32:
1148 ; RV32I-NEXT: slli a1, a0, 1
1149 ; RV32I-NEXT: lui a2, 699051
1150 ; RV32I-NEXT: addi a2, a2, -1366
1151 ; RV32I-NEXT: and a1, a1, a2
1152 ; RV32I-NEXT: srli a0, a0, 1
1153 ; RV32I-NEXT: lui a2, 349525
1154 ; RV32I-NEXT: addi a2, a2, 1365
1155 ; RV32I-NEXT: and a0, a0, a2
1156 ; RV32I-NEXT: or a0, a1, a0
1159 ; RV32B-LABEL: grev1_i32:
1161 ; RV32B-NEXT: rev.p a0, a0
1164 ; RV32ZBP-LABEL: grev1_i32:
1166 ; RV32ZBP-NEXT: rev.p a0, a0
1168 %and = shl i32 %a, 1
1169 %shl = and i32 %and, -1431655766
1170 %and1 = lshr i32 %a, 1
1171 %shr = and i32 %and1, 1431655765
1172 %or = or i32 %shl, %shr
1176 define i64 @grev1_i64(i64 %a) nounwind {
1177 ; RV32I-LABEL: grev1_i64:
1179 ; RV32I-NEXT: slli a2, a0, 1
1180 ; RV32I-NEXT: slli a3, a1, 1
1181 ; RV32I-NEXT: lui a4, 699051
1182 ; RV32I-NEXT: addi a4, a4, -1366
1183 ; RV32I-NEXT: and a3, a3, a4
1184 ; RV32I-NEXT: and a2, a2, a4
1185 ; RV32I-NEXT: srli a0, a0, 1
1186 ; RV32I-NEXT: srli a1, a1, 1
1187 ; RV32I-NEXT: lui a4, 349525
1188 ; RV32I-NEXT: addi a4, a4, 1365
1189 ; RV32I-NEXT: and a1, a1, a4
1190 ; RV32I-NEXT: and a0, a0, a4
1191 ; RV32I-NEXT: or a0, a2, a0
1192 ; RV32I-NEXT: or a1, a3, a1
1195 ; RV32B-LABEL: grev1_i64:
1197 ; RV32B-NEXT: rev.p a0, a0
1198 ; RV32B-NEXT: rev.p a1, a1
1201 ; RV32ZBP-LABEL: grev1_i64:
1203 ; RV32ZBP-NEXT: rev.p a0, a0
1204 ; RV32ZBP-NEXT: rev.p a1, a1
1206 %and = shl i64 %a, 1
1207 %shl = and i64 %and, -6148914691236517206
1208 %and1 = lshr i64 %a, 1
1209 %shr = and i64 %and1, 6148914691236517205
1210 %or = or i64 %shl, %shr
1214 define i32 @grev2_i32(i32 %a) nounwind {
1215 ; RV32I-LABEL: grev2_i32:
1217 ; RV32I-NEXT: slli a1, a0, 2
1218 ; RV32I-NEXT: lui a2, 838861
1219 ; RV32I-NEXT: addi a2, a2, -820
1220 ; RV32I-NEXT: and a1, a1, a2
1221 ; RV32I-NEXT: srli a0, a0, 2
1222 ; RV32I-NEXT: lui a2, 209715
1223 ; RV32I-NEXT: addi a2, a2, 819
1224 ; RV32I-NEXT: and a0, a0, a2
1225 ; RV32I-NEXT: or a0, a1, a0
1228 ; RV32B-LABEL: grev2_i32:
1230 ; RV32B-NEXT: rev2.n a0, a0
1233 ; RV32ZBP-LABEL: grev2_i32:
1235 ; RV32ZBP-NEXT: rev2.n a0, a0
1237 %and = shl i32 %a, 2
1238 %shl = and i32 %and, -858993460
1239 %and1 = lshr i32 %a, 2
1240 %shr = and i32 %and1, 858993459
1241 %or = or i32 %shl, %shr
1245 define i64 @grev2_i64(i64 %a) nounwind {
1246 ; RV32I-LABEL: grev2_i64:
1248 ; RV32I-NEXT: slli a2, a0, 2
1249 ; RV32I-NEXT: slli a3, a1, 2
1250 ; RV32I-NEXT: lui a4, 838861
1251 ; RV32I-NEXT: addi a4, a4, -820
1252 ; RV32I-NEXT: and a3, a3, a4
1253 ; RV32I-NEXT: and a2, a2, a4
1254 ; RV32I-NEXT: srli a0, a0, 2
1255 ; RV32I-NEXT: srli a1, a1, 2
1256 ; RV32I-NEXT: lui a4, 209715
1257 ; RV32I-NEXT: addi a4, a4, 819
1258 ; RV32I-NEXT: and a1, a1, a4
1259 ; RV32I-NEXT: and a0, a0, a4
1260 ; RV32I-NEXT: or a0, a2, a0
1261 ; RV32I-NEXT: or a1, a3, a1
1264 ; RV32B-LABEL: grev2_i64:
1266 ; RV32B-NEXT: rev2.n a0, a0
1267 ; RV32B-NEXT: rev2.n a1, a1
1270 ; RV32ZBP-LABEL: grev2_i64:
1272 ; RV32ZBP-NEXT: rev2.n a0, a0
1273 ; RV32ZBP-NEXT: rev2.n a1, a1
1275 %and = shl i64 %a, 2
1276 %shl = and i64 %and, -3689348814741910324
1277 %and1 = lshr i64 %a, 2
1278 %shr = and i64 %and1, 3689348814741910323
1279 %or = or i64 %shl, %shr
1283 define i32 @grev3_i32(i32 %a) nounwind {
1284 ; RV32I-LABEL: grev3_i32:
1286 ; RV32I-NEXT: slli a1, a0, 1
1287 ; RV32I-NEXT: lui a2, 699051
1288 ; RV32I-NEXT: addi a2, a2, -1366
1289 ; RV32I-NEXT: and a1, a1, a2
1290 ; RV32I-NEXT: srli a0, a0, 1
1291 ; RV32I-NEXT: lui a2, 349525
1292 ; RV32I-NEXT: addi a2, a2, 1365
1293 ; RV32I-NEXT: and a0, a0, a2
1294 ; RV32I-NEXT: or a0, a1, a0
1295 ; RV32I-NEXT: slli a1, a0, 2
1296 ; RV32I-NEXT: lui a2, 838861
1297 ; RV32I-NEXT: addi a2, a2, -820
1298 ; RV32I-NEXT: and a1, a1, a2
1299 ; RV32I-NEXT: srli a0, a0, 2
1300 ; RV32I-NEXT: lui a2, 209715
1301 ; RV32I-NEXT: addi a2, a2, 819
1302 ; RV32I-NEXT: and a0, a0, a2
1303 ; RV32I-NEXT: or a0, a1, a0
1306 ; RV32B-LABEL: grev3_i32:
1308 ; RV32B-NEXT: rev.n a0, a0
1311 ; RV32ZBP-LABEL: grev3_i32:
1313 ; RV32ZBP-NEXT: rev.n a0, a0
1315 %and1 = shl i32 %a, 1
1316 %shl1 = and i32 %and1, -1431655766
1317 %and1b = lshr i32 %a, 1
1318 %shr1 = and i32 %and1b, 1431655765
1319 %or1 = or i32 %shl1, %shr1
1320 %and2 = shl i32 %or1, 2
1321 %shl2 = and i32 %and2, -858993460
1322 %and2b = lshr i32 %or1, 2
1323 %shr2 = and i32 %and2b, 858993459
1324 %or2 = or i32 %shl2, %shr2
1328 define i64 @grev3_i64(i64 %a) nounwind {
1329 ; RV32I-LABEL: grev3_i64:
1331 ; RV32I-NEXT: slli a2, a1, 1
1332 ; RV32I-NEXT: slli a3, a0, 1
1333 ; RV32I-NEXT: lui a4, 699051
1334 ; RV32I-NEXT: addi a4, a4, -1366
1335 ; RV32I-NEXT: and a3, a3, a4
1336 ; RV32I-NEXT: and a2, a2, a4
1337 ; RV32I-NEXT: srli a1, a1, 1
1338 ; RV32I-NEXT: srli a0, a0, 1
1339 ; RV32I-NEXT: lui a4, 349525
1340 ; RV32I-NEXT: addi a4, a4, 1365
1341 ; RV32I-NEXT: and a0, a0, a4
1342 ; RV32I-NEXT: and a1, a1, a4
1343 ; RV32I-NEXT: or a1, a2, a1
1344 ; RV32I-NEXT: or a0, a3, a0
1345 ; RV32I-NEXT: slli a2, a0, 2
1346 ; RV32I-NEXT: slli a3, a1, 2
1347 ; RV32I-NEXT: lui a4, 838861
1348 ; RV32I-NEXT: addi a4, a4, -820
1349 ; RV32I-NEXT: and a3, a3, a4
1350 ; RV32I-NEXT: and a2, a2, a4
1351 ; RV32I-NEXT: srli a0, a0, 2
1352 ; RV32I-NEXT: srli a1, a1, 2
1353 ; RV32I-NEXT: lui a4, 209715
1354 ; RV32I-NEXT: addi a4, a4, 819
1355 ; RV32I-NEXT: and a1, a1, a4
1356 ; RV32I-NEXT: and a0, a0, a4
1357 ; RV32I-NEXT: or a0, a2, a0
1358 ; RV32I-NEXT: or a1, a3, a1
1361 ; RV32B-LABEL: grev3_i64:
1363 ; RV32B-NEXT: rev.n a0, a0
1364 ; RV32B-NEXT: rev.n a1, a1
1367 ; RV32ZBP-LABEL: grev3_i64:
1369 ; RV32ZBP-NEXT: rev.n a0, a0
1370 ; RV32ZBP-NEXT: rev.n a1, a1
1372 %and1 = shl i64 %a, 1
1373 %shl1 = and i64 %and1, -6148914691236517206
1374 %and1b = lshr i64 %a, 1
1375 %shr1 = and i64 %and1b, 6148914691236517205
1376 %or1 = or i64 %shl1, %shr1
1377 %and2 = shl i64 %or1, 2
1378 %shl2 = and i64 %and2, -3689348814741910324
1379 %and2b = lshr i64 %or1, 2
1380 %shr2 = and i64 %and2b, 3689348814741910323
1381 %or2 = or i64 %shl2, %shr2
1385 define i32 @grev4_i32(i32 %a) nounwind {
1386 ; RV32I-LABEL: grev4_i32:
1388 ; RV32I-NEXT: slli a1, a0, 4
1389 ; RV32I-NEXT: lui a2, 986895
1390 ; RV32I-NEXT: addi a2, a2, 240
1391 ; RV32I-NEXT: and a1, a1, a2
1392 ; RV32I-NEXT: srli a0, a0, 4
1393 ; RV32I-NEXT: lui a2, 61681
1394 ; RV32I-NEXT: addi a2, a2, -241
1395 ; RV32I-NEXT: and a0, a0, a2
1396 ; RV32I-NEXT: or a0, a1, a0
1399 ; RV32B-LABEL: grev4_i32:
1401 ; RV32B-NEXT: rev4.b a0, a0
1404 ; RV32ZBP-LABEL: grev4_i32:
1406 ; RV32ZBP-NEXT: rev4.b a0, a0
1408 %and = shl i32 %a, 4
1409 %shl = and i32 %and, -252645136
1410 %and1 = lshr i32 %a, 4
1411 %shr = and i32 %and1, 252645135
1412 %or = or i32 %shl, %shr
1416 define i64 @grev4_i64(i64 %a) nounwind {
1417 ; RV32I-LABEL: grev4_i64:
1419 ; RV32I-NEXT: slli a2, a0, 4
1420 ; RV32I-NEXT: slli a3, a1, 4
1421 ; RV32I-NEXT: lui a4, 986895
1422 ; RV32I-NEXT: addi a4, a4, 240
1423 ; RV32I-NEXT: and a3, a3, a4
1424 ; RV32I-NEXT: and a2, a2, a4
1425 ; RV32I-NEXT: srli a0, a0, 4
1426 ; RV32I-NEXT: srli a1, a1, 4
1427 ; RV32I-NEXT: lui a4, 61681
1428 ; RV32I-NEXT: addi a4, a4, -241
1429 ; RV32I-NEXT: and a1, a1, a4
1430 ; RV32I-NEXT: and a0, a0, a4
1431 ; RV32I-NEXT: or a0, a2, a0
1432 ; RV32I-NEXT: or a1, a3, a1
1435 ; RV32B-LABEL: grev4_i64:
1437 ; RV32B-NEXT: rev4.b a0, a0
1438 ; RV32B-NEXT: rev4.b a1, a1
1441 ; RV32ZBP-LABEL: grev4_i64:
1443 ; RV32ZBP-NEXT: rev4.b a0, a0
1444 ; RV32ZBP-NEXT: rev4.b a1, a1
1446 %and = shl i64 %a, 4
1447 %shl = and i64 %and, -1085102592571150096
1448 %and1 = lshr i64 %a, 4
1449 %shr = and i64 %and1, 1085102592571150095
1450 %or = or i64 %shl, %shr
1454 define i32 @grev5_i32(i32 %a) nounwind {
1455 ; RV32I-LABEL: grev5_i32:
1457 ; RV32I-NEXT: slli a1, a0, 1
1458 ; RV32I-NEXT: lui a2, 699051
1459 ; RV32I-NEXT: addi a2, a2, -1366
1460 ; RV32I-NEXT: and a1, a1, a2
1461 ; RV32I-NEXT: srli a0, a0, 1
1462 ; RV32I-NEXT: lui a2, 349525
1463 ; RV32I-NEXT: addi a2, a2, 1365
1464 ; RV32I-NEXT: and a0, a0, a2
1465 ; RV32I-NEXT: or a0, a1, a0
1466 ; RV32I-NEXT: slli a1, a0, 4
1467 ; RV32I-NEXT: lui a2, 986895
1468 ; RV32I-NEXT: addi a2, a2, 240
1469 ; RV32I-NEXT: and a1, a1, a2
1470 ; RV32I-NEXT: srli a0, a0, 4
1471 ; RV32I-NEXT: lui a2, 61681
1472 ; RV32I-NEXT: addi a2, a2, -241
1473 ; RV32I-NEXT: and a0, a0, a2
1474 ; RV32I-NEXT: or a0, a1, a0
1477 ; RV32B-LABEL: grev5_i32:
1479 ; RV32B-NEXT: grevi a0, a0, 5
1482 ; RV32ZBP-LABEL: grev5_i32:
1484 ; RV32ZBP-NEXT: grevi a0, a0, 5
1486 %and1 = shl i32 %a, 1
1487 %shl1 = and i32 %and1, -1431655766
1488 %and1b = lshr i32 %a, 1
1489 %shr1 = and i32 %and1b, 1431655765
1490 %or1 = or i32 %shl1, %shr1
1491 %and2 = shl i32 %or1, 4
1492 %shl2 = and i32 %and2, -252645136
1493 %and2b = lshr i32 %or1, 4
1494 %shr2 = and i32 %and2b, 252645135
1495 %or2 = or i32 %shl2, %shr2
1499 define i64 @grev5_i64(i64 %a) nounwind {
1500 ; RV32I-LABEL: grev5_i64:
1502 ; RV32I-NEXT: slli a2, a1, 1
1503 ; RV32I-NEXT: slli a3, a0, 1
1504 ; RV32I-NEXT: lui a4, 699051
1505 ; RV32I-NEXT: addi a4, a4, -1366
1506 ; RV32I-NEXT: and a3, a3, a4
1507 ; RV32I-NEXT: and a2, a2, a4
1508 ; RV32I-NEXT: srli a1, a1, 1
1509 ; RV32I-NEXT: srli a0, a0, 1
1510 ; RV32I-NEXT: lui a4, 349525
1511 ; RV32I-NEXT: addi a4, a4, 1365
1512 ; RV32I-NEXT: and a0, a0, a4
1513 ; RV32I-NEXT: and a1, a1, a4
1514 ; RV32I-NEXT: or a1, a2, a1
1515 ; RV32I-NEXT: or a0, a3, a0
1516 ; RV32I-NEXT: slli a2, a0, 4
1517 ; RV32I-NEXT: slli a3, a1, 4
1518 ; RV32I-NEXT: lui a4, 986895
1519 ; RV32I-NEXT: addi a4, a4, 240
1520 ; RV32I-NEXT: and a3, a3, a4
1521 ; RV32I-NEXT: and a2, a2, a4
1522 ; RV32I-NEXT: srli a0, a0, 4
1523 ; RV32I-NEXT: srli a1, a1, 4
1524 ; RV32I-NEXT: lui a4, 61681
1525 ; RV32I-NEXT: addi a4, a4, -241
1526 ; RV32I-NEXT: and a1, a1, a4
1527 ; RV32I-NEXT: and a0, a0, a4
1528 ; RV32I-NEXT: or a0, a2, a0
1529 ; RV32I-NEXT: or a1, a3, a1
1532 ; RV32B-LABEL: grev5_i64:
1534 ; RV32B-NEXT: grevi a0, a0, 5
1535 ; RV32B-NEXT: grevi a1, a1, 5
1538 ; RV32ZBP-LABEL: grev5_i64:
1540 ; RV32ZBP-NEXT: grevi a0, a0, 5
1541 ; RV32ZBP-NEXT: grevi a1, a1, 5
1543 %and1 = shl i64 %a, 1
1544 %shl1 = and i64 %and1, -6148914691236517206
1545 %and1b = lshr i64 %a, 1
1546 %shr1 = and i64 %and1b, 6148914691236517205
1547 %or1 = or i64 %shl1, %shr1
1549 %and2 = shl i64 %or1, 4
1550 %shl2 = and i64 %and2, -1085102592571150096
1551 %and2b = lshr i64 %or1, 4
1552 %shr2 = and i64 %and2b, 1085102592571150095
1553 %or2 = or i64 %shl2, %shr2
1557 define i32 @grev6_i32(i32 %a) nounwind {
1558 ; RV32I-LABEL: grev6_i32:
1560 ; RV32I-NEXT: slli a1, a0, 2
1561 ; RV32I-NEXT: lui a2, 838861
1562 ; RV32I-NEXT: addi a2, a2, -820
1563 ; RV32I-NEXT: and a1, a1, a2
1564 ; RV32I-NEXT: srli a0, a0, 2
1565 ; RV32I-NEXT: lui a2, 209715
1566 ; RV32I-NEXT: addi a2, a2, 819
1567 ; RV32I-NEXT: and a0, a0, a2
1568 ; RV32I-NEXT: or a0, a1, a0
1569 ; RV32I-NEXT: slli a1, a0, 4
1570 ; RV32I-NEXT: lui a2, 986895
1571 ; RV32I-NEXT: addi a2, a2, 240
1572 ; RV32I-NEXT: and a1, a1, a2
1573 ; RV32I-NEXT: srli a0, a0, 4
1574 ; RV32I-NEXT: lui a2, 61681
1575 ; RV32I-NEXT: addi a2, a2, -241
1576 ; RV32I-NEXT: and a0, a0, a2
1577 ; RV32I-NEXT: or a0, a1, a0
1580 ; RV32B-LABEL: grev6_i32:
1582 ; RV32B-NEXT: rev2.b a0, a0
1585 ; RV32ZBP-LABEL: grev6_i32:
1587 ; RV32ZBP-NEXT: rev2.b a0, a0
1589 %and1 = shl i32 %a, 2
1590 %shl1 = and i32 %and1, -858993460
1591 %and1b = lshr i32 %a, 2
1592 %shr1 = and i32 %and1b, 858993459
1593 %or1 = or i32 %shl1, %shr1
1594 %and2 = shl i32 %or1, 4
1595 %shl2 = and i32 %and2, -252645136
1596 %and2b = lshr i32 %or1, 4
1597 %shr2 = and i32 %and2b, 252645135
1598 %or2 = or i32 %shl2, %shr2
1602 define i64 @grev6_i64(i64 %a) nounwind {
1603 ; RV32I-LABEL: grev6_i64:
1605 ; RV32I-NEXT: slli a2, a1, 2
1606 ; RV32I-NEXT: slli a3, a0, 2
1607 ; RV32I-NEXT: lui a4, 838861
1608 ; RV32I-NEXT: addi a4, a4, -820
1609 ; RV32I-NEXT: and a3, a3, a4
1610 ; RV32I-NEXT: and a2, a2, a4
1611 ; RV32I-NEXT: srli a1, a1, 2
1612 ; RV32I-NEXT: srli a0, a0, 2
1613 ; RV32I-NEXT: lui a4, 209715
1614 ; RV32I-NEXT: addi a4, a4, 819
1615 ; RV32I-NEXT: and a0, a0, a4
1616 ; RV32I-NEXT: and a1, a1, a4
1617 ; RV32I-NEXT: or a1, a2, a1
1618 ; RV32I-NEXT: or a0, a3, a0
1619 ; RV32I-NEXT: slli a2, a0, 4
1620 ; RV32I-NEXT: slli a3, a1, 4
1621 ; RV32I-NEXT: lui a4, 986895
1622 ; RV32I-NEXT: addi a4, a4, 240
1623 ; RV32I-NEXT: and a3, a3, a4
1624 ; RV32I-NEXT: and a2, a2, a4
1625 ; RV32I-NEXT: srli a0, a0, 4
1626 ; RV32I-NEXT: srli a1, a1, 4
1627 ; RV32I-NEXT: lui a4, 61681
1628 ; RV32I-NEXT: addi a4, a4, -241
1629 ; RV32I-NEXT: and a1, a1, a4
1630 ; RV32I-NEXT: and a0, a0, a4
1631 ; RV32I-NEXT: or a0, a2, a0
1632 ; RV32I-NEXT: or a1, a3, a1
1635 ; RV32B-LABEL: grev6_i64:
1637 ; RV32B-NEXT: rev2.b a0, a0
1638 ; RV32B-NEXT: rev2.b a1, a1
1641 ; RV32ZBP-LABEL: grev6_i64:
1643 ; RV32ZBP-NEXT: rev2.b a0, a0
1644 ; RV32ZBP-NEXT: rev2.b a1, a1
1646 %and1 = shl i64 %a, 2
1647 %shl1 = and i64 %and1, -3689348814741910324
1648 %and1b = lshr i64 %a, 2
1649 %shr1 = and i64 %and1b, 3689348814741910323
1650 %or1 = or i64 %shl1, %shr1
1651 %and2 = shl i64 %or1, 4
1652 %shl2 = and i64 %and2, -1085102592571150096
1653 %and2b = lshr i64 %or1, 4
1654 %shr2 = and i64 %and2b, 1085102592571150095
1655 %or2 = or i64 %shl2, %shr2
1659 define i32 @grev7_i32(i32 %a) nounwind {
1660 ; RV32I-LABEL: grev7_i32:
1662 ; RV32I-NEXT: slli a1, a0, 1
1663 ; RV32I-NEXT: lui a2, 699051
1664 ; RV32I-NEXT: addi a2, a2, -1366
1665 ; RV32I-NEXT: and a1, a1, a2
1666 ; RV32I-NEXT: srli a0, a0, 1
1667 ; RV32I-NEXT: lui a2, 349525
1668 ; RV32I-NEXT: addi a2, a2, 1365
1669 ; RV32I-NEXT: and a0, a0, a2
1670 ; RV32I-NEXT: or a0, a1, a0
1671 ; RV32I-NEXT: slli a1, a0, 2
1672 ; RV32I-NEXT: lui a2, 838861
1673 ; RV32I-NEXT: addi a2, a2, -820
1674 ; RV32I-NEXT: and a1, a1, a2
1675 ; RV32I-NEXT: srli a0, a0, 2
1676 ; RV32I-NEXT: lui a2, 209715
1677 ; RV32I-NEXT: addi a2, a2, 819
1678 ; RV32I-NEXT: and a0, a0, a2
1679 ; RV32I-NEXT: or a0, a1, a0
1680 ; RV32I-NEXT: slli a1, a0, 4
1681 ; RV32I-NEXT: lui a2, 986895
1682 ; RV32I-NEXT: addi a2, a2, 240
1683 ; RV32I-NEXT: and a1, a1, a2
1684 ; RV32I-NEXT: srli a0, a0, 4
1685 ; RV32I-NEXT: lui a2, 61681
1686 ; RV32I-NEXT: addi a2, a2, -241
1687 ; RV32I-NEXT: and a0, a0, a2
1688 ; RV32I-NEXT: or a0, a1, a0
1691 ; RV32B-LABEL: grev7_i32:
1693 ; RV32B-NEXT: rev.b a0, a0
1696 ; RV32ZBP-LABEL: grev7_i32:
1698 ; RV32ZBP-NEXT: rev.b a0, a0
1700 %and1 = shl i32 %a, 1
1701 %shl1 = and i32 %and1, -1431655766
1702 %and1b = lshr i32 %a, 1
1703 %shr1 = and i32 %and1b, 1431655765
1704 %or1 = or i32 %shl1, %shr1
1705 %and2 = shl i32 %or1, 2
1706 %shl2 = and i32 %and2, -858993460
1707 %and2b = lshr i32 %or1, 2
1708 %shr2 = and i32 %and2b, 858993459
1709 %or2 = or i32 %shl2, %shr2
1710 %and3 = shl i32 %or2, 4
1711 %shl3 = and i32 %and3, -252645136
1712 %and3b = lshr i32 %or2, 4
1713 %shr3 = and i32 %and3b, 252645135
1714 %or3 = or i32 %shl3, %shr3
1718 define i64 @grev7_i64(i64 %a) nounwind {
1719 ; RV32I-LABEL: grev7_i64:
1721 ; RV32I-NEXT: slli a2, a0, 1
1722 ; RV32I-NEXT: slli a3, a1, 1
1723 ; RV32I-NEXT: lui a4, 699051
1724 ; RV32I-NEXT: addi a4, a4, -1366
1725 ; RV32I-NEXT: and a3, a3, a4
1726 ; RV32I-NEXT: and a2, a2, a4
1727 ; RV32I-NEXT: srli a0, a0, 1
1728 ; RV32I-NEXT: srli a1, a1, 1
1729 ; RV32I-NEXT: lui a4, 349525
1730 ; RV32I-NEXT: addi a4, a4, 1365
1731 ; RV32I-NEXT: and a1, a1, a4
1732 ; RV32I-NEXT: and a0, a0, a4
1733 ; RV32I-NEXT: or a0, a2, a0
1734 ; RV32I-NEXT: or a1, a3, a1
1735 ; RV32I-NEXT: slli a2, a1, 2
1736 ; RV32I-NEXT: slli a3, a0, 2
1737 ; RV32I-NEXT: lui a4, 838861
1738 ; RV32I-NEXT: addi a4, a4, -820
1739 ; RV32I-NEXT: and a3, a3, a4
1740 ; RV32I-NEXT: and a2, a2, a4
1741 ; RV32I-NEXT: srli a1, a1, 2
1742 ; RV32I-NEXT: srli a0, a0, 2
1743 ; RV32I-NEXT: lui a4, 209715
1744 ; RV32I-NEXT: addi a4, a4, 819
1745 ; RV32I-NEXT: and a0, a0, a4
1746 ; RV32I-NEXT: and a1, a1, a4
1747 ; RV32I-NEXT: or a1, a2, a1
1748 ; RV32I-NEXT: or a0, a3, a0
1749 ; RV32I-NEXT: slli a2, a0, 4
1750 ; RV32I-NEXT: slli a3, a1, 4
1751 ; RV32I-NEXT: lui a4, 986895
1752 ; RV32I-NEXT: addi a4, a4, 240
1753 ; RV32I-NEXT: and a3, a3, a4
1754 ; RV32I-NEXT: and a2, a2, a4
1755 ; RV32I-NEXT: srli a0, a0, 4
1756 ; RV32I-NEXT: srli a1, a1, 4
1757 ; RV32I-NEXT: lui a4, 61681
1758 ; RV32I-NEXT: addi a4, a4, -241
1759 ; RV32I-NEXT: and a1, a1, a4
1760 ; RV32I-NEXT: and a0, a0, a4
1761 ; RV32I-NEXT: or a0, a2, a0
1762 ; RV32I-NEXT: or a1, a3, a1
1765 ; RV32B-LABEL: grev7_i64:
1767 ; RV32B-NEXT: rev.b a0, a0
1768 ; RV32B-NEXT: rev.b a1, a1
1771 ; RV32ZBP-LABEL: grev7_i64:
1773 ; RV32ZBP-NEXT: rev.b a0, a0
1774 ; RV32ZBP-NEXT: rev.b a1, a1
1776 %and1 = shl i64 %a, 1
1777 %shl1 = and i64 %and1, -6148914691236517206
1778 %and1b = lshr i64 %a, 1
1779 %shr1 = and i64 %and1b, 6148914691236517205
1780 %or1 = or i64 %shl1, %shr1
1781 %and2 = shl i64 %or1, 2
1782 %shl2 = and i64 %and2, -3689348814741910324
1783 %and2b = lshr i64 %or1, 2
1784 %shr2 = and i64 %and2b, 3689348814741910323
1785 %or2 = or i64 %shl2, %shr2
1786 %and3 = shl i64 %or2, 4
1787 %shl3 = and i64 %and3, -1085102592571150096
1788 %and3b = lshr i64 %or2, 4
1789 %shr3 = and i64 %and3b, 1085102592571150095
1790 %or3 = or i64 %shl3, %shr3
1794 define i32 @grev8_i32(i32 %a) nounwind {
1795 ; RV32I-LABEL: grev8_i32:
1797 ; RV32I-NEXT: slli a1, a0, 8
1798 ; RV32I-NEXT: lui a2, 1044496
1799 ; RV32I-NEXT: addi a2, a2, -256
1800 ; RV32I-NEXT: and a1, a1, a2
1801 ; RV32I-NEXT: srli a0, a0, 8
1802 ; RV32I-NEXT: lui a2, 4080
1803 ; RV32I-NEXT: addi a2, a2, 255
1804 ; RV32I-NEXT: and a0, a0, a2
1805 ; RV32I-NEXT: or a0, a1, a0
1808 ; RV32B-LABEL: grev8_i32:
1810 ; RV32B-NEXT: rev8.h a0, a0
1813 ; RV32ZBP-LABEL: grev8_i32:
1815 ; RV32ZBP-NEXT: rev8.h a0, a0
1817 %and = shl i32 %a, 8
1818 %shl = and i32 %and, -16711936
1819 %and1 = lshr i32 %a, 8
1820 %shr = and i32 %and1, 16711935
1821 %or = or i32 %shl, %shr
1825 define i64 @grev8_i64(i64 %a) nounwind {
1826 ; RV32I-LABEL: grev8_i64:
1828 ; RV32I-NEXT: slli a2, a0, 8
1829 ; RV32I-NEXT: slli a3, a1, 8
1830 ; RV32I-NEXT: lui a4, 1044496
1831 ; RV32I-NEXT: addi a4, a4, -256
1832 ; RV32I-NEXT: and a3, a3, a4
1833 ; RV32I-NEXT: and a2, a2, a4
1834 ; RV32I-NEXT: srli a0, a0, 8
1835 ; RV32I-NEXT: srli a1, a1, 8
1836 ; RV32I-NEXT: lui a4, 4080
1837 ; RV32I-NEXT: addi a4, a4, 255
1838 ; RV32I-NEXT: and a1, a1, a4
1839 ; RV32I-NEXT: and a0, a0, a4
1840 ; RV32I-NEXT: or a0, a2, a0
1841 ; RV32I-NEXT: or a1, a3, a1
1844 ; RV32B-LABEL: grev8_i64:
1846 ; RV32B-NEXT: rev8.h a0, a0
1847 ; RV32B-NEXT: rev8.h a1, a1
1850 ; RV32ZBP-LABEL: grev8_i64:
1852 ; RV32ZBP-NEXT: rev8.h a0, a0
1853 ; RV32ZBP-NEXT: rev8.h a1, a1
1855 %and = shl i64 %a, 8
1856 %shl = and i64 %and, -71777214294589696
1857 %and1 = lshr i64 %a, 8
1858 %shr = and i64 %and1, 71777214294589695
1859 %or = or i64 %shl, %shr
1863 define i32 @grev16_i32(i32 %a) nounwind {
1864 ; RV32I-LABEL: grev16_i32:
1866 ; RV32I-NEXT: slli a1, a0, 16
1867 ; RV32I-NEXT: srli a0, a0, 16
1868 ; RV32I-NEXT: or a0, a1, a0
1871 ; RV32B-LABEL: grev16_i32:
1873 ; RV32B-NEXT: rori a0, a0, 16
1876 ; RV32ZBP-LABEL: grev16_i32:
1878 ; RV32ZBP-NEXT: rori a0, a0, 16
1880 %shl = shl i32 %a, 16
1881 %shr = lshr i32 %a, 16
1882 %or = or i32 %shl, %shr
1887 define i32 @grev3b_i32(i32 %a) nounwind {
1888 ; RV32I-LABEL: grev3b_i32:
1890 ; RV32I-NEXT: slli a1, a0, 2
1891 ; RV32I-NEXT: lui a2, 838861
1892 ; RV32I-NEXT: addi a2, a2, -820
1893 ; RV32I-NEXT: and a1, a1, a2
1894 ; RV32I-NEXT: srli a0, a0, 2
1895 ; RV32I-NEXT: lui a2, 209715
1896 ; RV32I-NEXT: addi a2, a2, 819
1897 ; RV32I-NEXT: and a0, a0, a2
1898 ; RV32I-NEXT: or a0, a1, a0
1899 ; RV32I-NEXT: slli a1, a0, 1
1900 ; RV32I-NEXT: lui a2, 699051
1901 ; RV32I-NEXT: addi a2, a2, -1366
1902 ; RV32I-NEXT: and a1, a1, a2
1903 ; RV32I-NEXT: srli a0, a0, 1
1904 ; RV32I-NEXT: lui a2, 349525
1905 ; RV32I-NEXT: addi a2, a2, 1365
1906 ; RV32I-NEXT: and a0, a0, a2
1907 ; RV32I-NEXT: or a0, a1, a0
1910 ; RV32B-LABEL: grev3b_i32:
1912 ; RV32B-NEXT: rev.n a0, a0
1915 ; RV32ZBP-LABEL: grev3b_i32:
1917 ; RV32ZBP-NEXT: rev.n a0, a0
1919 %and2 = shl i32 %a, 2
1920 %shl2 = and i32 %and2, -858993460
1921 %and2b = lshr i32 %a, 2
1922 %shr2 = and i32 %and2b, 858993459
1923 %or2 = or i32 %shl2, %shr2
1924 %and1 = shl i32 %or2, 1
1925 %shl1 = and i32 %and1, -1431655766
1926 %and1b = lshr i32 %or2, 1
1927 %shr1 = and i32 %and1b, 1431655765
1928 %or1 = or i32 %shl1, %shr1
1932 define i64 @grev3b_i64(i64 %a) nounwind {
1933 ; RV32I-LABEL: grev3b_i64:
1935 ; RV32I-NEXT: slli a2, a1, 2
1936 ; RV32I-NEXT: slli a3, a0, 2
1937 ; RV32I-NEXT: lui a4, 838861
1938 ; RV32I-NEXT: addi a4, a4, -820
1939 ; RV32I-NEXT: and a3, a3, a4
1940 ; RV32I-NEXT: and a2, a2, a4
1941 ; RV32I-NEXT: srli a1, a1, 2
1942 ; RV32I-NEXT: srli a0, a0, 2
1943 ; RV32I-NEXT: lui a4, 209715
1944 ; RV32I-NEXT: addi a4, a4, 819
1945 ; RV32I-NEXT: and a0, a0, a4
1946 ; RV32I-NEXT: and a1, a1, a4
1947 ; RV32I-NEXT: or a1, a2, a1
1948 ; RV32I-NEXT: or a0, a3, a0
1949 ; RV32I-NEXT: slli a2, a0, 1
1950 ; RV32I-NEXT: slli a3, a1, 1
1951 ; RV32I-NEXT: lui a4, 699051
1952 ; RV32I-NEXT: addi a4, a4, -1366
1953 ; RV32I-NEXT: and a3, a3, a4
1954 ; RV32I-NEXT: and a2, a2, a4
1955 ; RV32I-NEXT: srli a0, a0, 1
1956 ; RV32I-NEXT: srli a1, a1, 1
1957 ; RV32I-NEXT: lui a4, 349525
1958 ; RV32I-NEXT: addi a4, a4, 1365
1959 ; RV32I-NEXT: and a1, a1, a4
1960 ; RV32I-NEXT: and a0, a0, a4
1961 ; RV32I-NEXT: or a0, a2, a0
1962 ; RV32I-NEXT: or a1, a3, a1
1965 ; RV32B-LABEL: grev3b_i64:
1967 ; RV32B-NEXT: rev.n a0, a0
1968 ; RV32B-NEXT: rev.n a1, a1
1971 ; RV32ZBP-LABEL: grev3b_i64:
1973 ; RV32ZBP-NEXT: rev.n a0, a0
1974 ; RV32ZBP-NEXT: rev.n a1, a1
1976 %and2 = shl i64 %a, 2
1977 %shl2 = and i64 %and2, -3689348814741910324
1978 %and2b = lshr i64 %a, 2
1979 %shr2 = and i64 %and2b, 3689348814741910323
1980 %or2 = or i64 %shl2, %shr2
1981 %and1 = shl i64 %or2, 1
1982 %shl1 = and i64 %and1, -6148914691236517206
1983 %and1b = lshr i64 %or2, 1
1984 %shr1 = and i64 %and1b, 6148914691236517205
1985 %or1 = or i64 %shl1, %shr1
1989 ; grev1, grev2, grev1 -> grev2
1990 define i32 @grev2b_i32(i32 %a) nounwind {
1991 ; RV32I-LABEL: grev2b_i32:
1993 ; RV32I-NEXT: slli a1, a0, 1
1994 ; RV32I-NEXT: lui a2, 699051
1995 ; RV32I-NEXT: addi a2, a2, -1366
1996 ; RV32I-NEXT: and a1, a1, a2
1997 ; RV32I-NEXT: srli a0, a0, 1
1998 ; RV32I-NEXT: lui a3, 349525
1999 ; RV32I-NEXT: addi a3, a3, 1365
2000 ; RV32I-NEXT: and a0, a0, a3
2001 ; RV32I-NEXT: or a0, a1, a0
2002 ; RV32I-NEXT: slli a1, a0, 2
2003 ; RV32I-NEXT: lui a4, 838861
2004 ; RV32I-NEXT: addi a4, a4, -820
2005 ; RV32I-NEXT: and a1, a1, a4
2006 ; RV32I-NEXT: srli a0, a0, 2
2007 ; RV32I-NEXT: lui a4, 209715
2008 ; RV32I-NEXT: addi a4, a4, 819
2009 ; RV32I-NEXT: and a0, a0, a4
2010 ; RV32I-NEXT: or a0, a1, a0
2011 ; RV32I-NEXT: slli a1, a0, 1
2012 ; RV32I-NEXT: and a1, a1, a2
2013 ; RV32I-NEXT: srli a0, a0, 1
2014 ; RV32I-NEXT: and a0, a0, a3
2015 ; RV32I-NEXT: or a0, a1, a0
2018 ; RV32B-LABEL: grev2b_i32:
2020 ; RV32B-NEXT: rev2.n a0, a0
2023 ; RV32ZBP-LABEL: grev2b_i32:
2025 ; RV32ZBP-NEXT: rev2.n a0, a0
2027 %and1 = shl i32 %a, 1
2028 %shl1 = and i32 %and1, -1431655766
2029 %and1b = lshr i32 %a, 1
2030 %shr1 = and i32 %and1b, 1431655765
2031 %or1 = or i32 %shl1, %shr1
2032 %and2 = shl i32 %or1, 2
2033 %shl2 = and i32 %and2, -858993460
2034 %and2b = lshr i32 %or1, 2
2035 %shr2 = and i32 %and2b, 858993459
2036 %or2 = or i32 %shl2, %shr2
2037 %and3 = shl i32 %or2, 1
2038 %shl3 = and i32 %and3, -1431655766
2039 %and3b = lshr i32 %or2, 1
2040 %shr3 = and i32 %and3b, 1431655765
2041 %or3 = or i32 %shl3, %shr3
2045 ; grev1, grev2, grev1 -> grev2
2046 define i64 @grev2b_i64(i64 %a) nounwind {
2047 ; RV32I-LABEL: grev2b_i64:
2049 ; RV32I-NEXT: slli a2, a0, 1
2050 ; RV32I-NEXT: slli a3, a1, 1
2051 ; RV32I-NEXT: lui a4, 699051
2052 ; RV32I-NEXT: addi a4, a4, -1366
2053 ; RV32I-NEXT: and a3, a3, a4
2054 ; RV32I-NEXT: and a2, a2, a4
2055 ; RV32I-NEXT: srli a0, a0, 1
2056 ; RV32I-NEXT: srli a1, a1, 1
2057 ; RV32I-NEXT: lui a5, 349525
2058 ; RV32I-NEXT: addi a5, a5, 1365
2059 ; RV32I-NEXT: and a1, a1, a5
2060 ; RV32I-NEXT: and a0, a0, a5
2061 ; RV32I-NEXT: or a0, a2, a0
2062 ; RV32I-NEXT: or a1, a3, a1
2063 ; RV32I-NEXT: slli a6, a1, 2
2064 ; RV32I-NEXT: slli a3, a0, 2
2065 ; RV32I-NEXT: lui a2, 838861
2066 ; RV32I-NEXT: addi a2, a2, -820
2067 ; RV32I-NEXT: and a7, a3, a2
2068 ; RV32I-NEXT: and a2, a6, a2
2069 ; RV32I-NEXT: srli a1, a1, 2
2070 ; RV32I-NEXT: srli a0, a0, 2
2071 ; RV32I-NEXT: lui a3, 209715
2072 ; RV32I-NEXT: addi a3, a3, 819
2073 ; RV32I-NEXT: and a0, a0, a3
2074 ; RV32I-NEXT: and a1, a1, a3
2075 ; RV32I-NEXT: or a1, a2, a1
2076 ; RV32I-NEXT: or a0, a7, a0
2077 ; RV32I-NEXT: slli a2, a0, 1
2078 ; RV32I-NEXT: slli a3, a1, 1
2079 ; RV32I-NEXT: and a3, a3, a4
2080 ; RV32I-NEXT: and a2, a2, a4
2081 ; RV32I-NEXT: srli a0, a0, 1
2082 ; RV32I-NEXT: srli a1, a1, 1
2083 ; RV32I-NEXT: and a1, a1, a5
2084 ; RV32I-NEXT: and a0, a0, a5
2085 ; RV32I-NEXT: or a0, a2, a0
2086 ; RV32I-NEXT: or a1, a3, a1
2089 ; RV32B-LABEL: grev2b_i64:
2091 ; RV32B-NEXT: rev2.n a0, a0
2092 ; RV32B-NEXT: rev2.n a1, a1
2095 ; RV32ZBP-LABEL: grev2b_i64:
2097 ; RV32ZBP-NEXT: rev2.n a0, a0
2098 ; RV32ZBP-NEXT: rev2.n a1, a1
2100 %and1 = shl i64 %a, 1
2101 %shl1 = and i64 %and1, -6148914691236517206
2102 %and1b = lshr i64 %a, 1
2103 %shr1 = and i64 %and1b, 6148914691236517205
2104 %or1 = or i64 %shl1, %shr1
2105 %and2 = shl i64 %or1, 2
2106 %shl2 = and i64 %and2, -3689348814741910324
2107 %and2b = lshr i64 %or1, 2
2108 %shr2 = and i64 %and2b, 3689348814741910323
2109 %or2 = or i64 %shl2, %shr2
2110 %and3 = shl i64 %or2, 1
2111 %shl3 = and i64 %and3, -6148914691236517206
2112 %and3b = lshr i64 %or2, 1
2113 %shr3 = and i64 %and3b, 6148914691236517205
2114 %or3 = or i64 %shl3, %shr3
2118 ; grev1, grev2, grev1, grev2 -> identity
2119 define i32 @grev0_i32(i32 %a) nounwind {
2120 ; RV32I-LABEL: grev0_i32:
2122 ; RV32I-NEXT: slli a1, a0, 1
2123 ; RV32I-NEXT: lui a2, 699051
2124 ; RV32I-NEXT: addi a2, a2, -1366
2125 ; RV32I-NEXT: and a1, a1, a2
2126 ; RV32I-NEXT: srli a0, a0, 1
2127 ; RV32I-NEXT: lui a3, 349525
2128 ; RV32I-NEXT: addi a3, a3, 1365
2129 ; RV32I-NEXT: and a0, a0, a3
2130 ; RV32I-NEXT: or a0, a1, a0
2131 ; RV32I-NEXT: slli a1, a0, 2
2132 ; RV32I-NEXT: lui a4, 838861
2133 ; RV32I-NEXT: addi a4, a4, -820
2134 ; RV32I-NEXT: and a1, a1, a4
2135 ; RV32I-NEXT: srli a0, a0, 2
2136 ; RV32I-NEXT: lui a5, 209715
2137 ; RV32I-NEXT: addi a5, a5, 819
2138 ; RV32I-NEXT: and a0, a0, a5
2139 ; RV32I-NEXT: or a0, a1, a0
2140 ; RV32I-NEXT: slli a1, a0, 1
2141 ; RV32I-NEXT: and a1, a1, a2
2142 ; RV32I-NEXT: srli a0, a0, 1
2143 ; RV32I-NEXT: and a0, a0, a3
2144 ; RV32I-NEXT: or a0, a1, a0
2145 ; RV32I-NEXT: slli a1, a0, 2
2146 ; RV32I-NEXT: and a1, a1, a4
2147 ; RV32I-NEXT: srli a0, a0, 2
2148 ; RV32I-NEXT: and a0, a0, a5
2149 ; RV32I-NEXT: or a0, a1, a0
2152 ; RV32B-LABEL: grev0_i32:
2156 ; RV32ZBP-LABEL: grev0_i32:
2159 %and1 = shl i32 %a, 1
2160 %shl1 = and i32 %and1, -1431655766
2161 %and1b = lshr i32 %a, 1
2162 %shr1 = and i32 %and1b, 1431655765
2163 %or1 = or i32 %shl1, %shr1
2164 %and2 = shl i32 %or1, 2
2165 %shl2 = and i32 %and2, -858993460
2166 %and2b = lshr i32 %or1, 2
2167 %shr2 = and i32 %and2b, 858993459
2168 %or2 = or i32 %shl2, %shr2
2169 %and3 = shl i32 %or2, 1
2170 %shl3 = and i32 %and3, -1431655766
2171 %and3b = lshr i32 %or2, 1
2172 %shr3 = and i32 %and3b, 1431655765
2173 %or3 = or i32 %shl3, %shr3
2174 %and4 = shl i32 %or3, 2
2175 %shl4 = and i32 %and4, -858993460
2176 %and4b = lshr i32 %or3, 2
2177 %shr4 = and i32 %and4b, 858993459
2178 %or4 = or i32 %shl4, %shr4
2182 ; grev1, grev2, grev1, grev2 -> identity
2183 define i64 @grev0_i64(i64 %a) nounwind {
2184 ; RV32I-LABEL: grev0_i64:
2186 ; RV32I-NEXT: slli a2, a1, 1
2187 ; RV32I-NEXT: slli a3, a0, 1
2188 ; RV32I-NEXT: lui a4, 699051
2189 ; RV32I-NEXT: addi a4, a4, -1366
2190 ; RV32I-NEXT: and a3, a3, a4
2191 ; RV32I-NEXT: and a2, a2, a4
2192 ; RV32I-NEXT: srli a1, a1, 1
2193 ; RV32I-NEXT: srli a0, a0, 1
2194 ; RV32I-NEXT: lui a5, 349525
2195 ; RV32I-NEXT: addi a5, a5, 1365
2196 ; RV32I-NEXT: and a0, a0, a5
2197 ; RV32I-NEXT: and a1, a1, a5
2198 ; RV32I-NEXT: or a1, a2, a1
2199 ; RV32I-NEXT: or a0, a3, a0
2200 ; RV32I-NEXT: slli a6, a0, 2
2201 ; RV32I-NEXT: slli a3, a1, 2
2202 ; RV32I-NEXT: lui a2, 838861
2203 ; RV32I-NEXT: addi a2, a2, -820
2204 ; RV32I-NEXT: and a7, a3, a2
2205 ; RV32I-NEXT: and a6, a6, a2
2206 ; RV32I-NEXT: srli a0, a0, 2
2207 ; RV32I-NEXT: srli a1, a1, 2
2208 ; RV32I-NEXT: lui a3, 209715
2209 ; RV32I-NEXT: addi a3, a3, 819
2210 ; RV32I-NEXT: and a1, a1, a3
2211 ; RV32I-NEXT: and a0, a0, a3
2212 ; RV32I-NEXT: or t0, a6, a0
2213 ; RV32I-NEXT: or a1, a7, a1
2214 ; RV32I-NEXT: slli a6, a1, 1
2215 ; RV32I-NEXT: slli a0, t0, 1
2216 ; RV32I-NEXT: and a7, a0, a4
2217 ; RV32I-NEXT: and a4, a6, a4
2218 ; RV32I-NEXT: srli a1, a1, 1
2219 ; RV32I-NEXT: srli a0, t0, 1
2220 ; RV32I-NEXT: and a0, a0, a5
2221 ; RV32I-NEXT: and a1, a1, a5
2222 ; RV32I-NEXT: or a1, a4, a1
2223 ; RV32I-NEXT: or a0, a7, a0
2224 ; RV32I-NEXT: slli a4, a0, 2
2225 ; RV32I-NEXT: slli a5, a1, 2
2226 ; RV32I-NEXT: and a5, a5, a2
2227 ; RV32I-NEXT: and a2, a4, a2
2228 ; RV32I-NEXT: srli a0, a0, 2
2229 ; RV32I-NEXT: srli a1, a1, 2
2230 ; RV32I-NEXT: and a1, a1, a3
2231 ; RV32I-NEXT: and a0, a0, a3
2232 ; RV32I-NEXT: or a0, a2, a0
2233 ; RV32I-NEXT: or a1, a5, a1
2236 ; RV32B-LABEL: grev0_i64:
2240 ; RV32ZBP-LABEL: grev0_i64:
2243 %and1 = shl i64 %a, 1
2244 %shl1 = and i64 %and1, -6148914691236517206
2245 %and1b = lshr i64 %a, 1
2246 %shr1 = and i64 %and1b, 6148914691236517205
2247 %or1 = or i64 %shl1, %shr1
2248 %and2 = shl i64 %or1, 2
2249 %shl2 = and i64 %and2, -3689348814741910324
2250 %and2b = lshr i64 %or1, 2
2251 %shr2 = and i64 %and2b, 3689348814741910323
2252 %or2 = or i64 %shl2, %shr2
2253 %and3 = shl i64 %or2, 1
2254 %shl3 = and i64 %and3, -6148914691236517206
2255 %and3b = lshr i64 %or2, 1
2256 %shr3 = and i64 %and3b, 6148914691236517205
2257 %or3 = or i64 %shl3, %shr3
2258 %and4 = shl i64 %or3, 2
2259 %shl4 = and i64 %and4, -3689348814741910324
2260 %and4b = lshr i64 %or3, 2
2261 %shr4 = and i64 %and4b, 3689348814741910323
2262 %or4 = or i64 %shl4, %shr4
2266 declare i32 @llvm.fshl.i32(i32, i32, i32)
2267 declare i32 @llvm.fshr.i32(i32, i32, i32)
2269 define signext i32 @grev16_i32_fshl(i32 signext %a) nounwind {
2270 ; RV32I-LABEL: grev16_i32_fshl:
2272 ; RV32I-NEXT: srli a1, a0, 16
2273 ; RV32I-NEXT: slli a0, a0, 16
2274 ; RV32I-NEXT: or a0, a0, a1
2277 ; RV32B-LABEL: grev16_i32_fshl:
2279 ; RV32B-NEXT: rori a0, a0, 16
2282 ; RV32ZBP-LABEL: grev16_i32_fshl:
2284 ; RV32ZBP-NEXT: rori a0, a0, 16
2286 %or = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 16)
2290 define signext i32 @grev16_i32_fshr(i32 signext %a) nounwind {
2291 ; RV32I-LABEL: grev16_i32_fshr:
2293 ; RV32I-NEXT: slli a1, a0, 16
2294 ; RV32I-NEXT: srli a0, a0, 16
2295 ; RV32I-NEXT: or a0, a0, a1
2298 ; RV32B-LABEL: grev16_i32_fshr:
2300 ; RV32B-NEXT: rori a0, a0, 16
2303 ; RV32ZBP-LABEL: grev16_i32_fshr:
2305 ; RV32ZBP-NEXT: rori a0, a0, 16
2307 %or = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 16)
2311 define i64 @grev16_i64(i64 %a) nounwind {
2312 ; RV32I-LABEL: grev16_i64:
2314 ; RV32I-NEXT: slli a2, a1, 16
2315 ; RV32I-NEXT: srli a3, a0, 16
2316 ; RV32I-NEXT: slli a0, a0, 16
2317 ; RV32I-NEXT: or a0, a0, a3
2318 ; RV32I-NEXT: srli a1, a1, 16
2319 ; RV32I-NEXT: or a1, a2, a1
2322 ; RV32B-LABEL: grev16_i64:
2324 ; RV32B-NEXT: rori a0, a0, 16
2325 ; RV32B-NEXT: rori a1, a1, 16
2328 ; RV32ZBP-LABEL: grev16_i64:
2330 ; RV32ZBP-NEXT: rori a0, a0, 16
2331 ; RV32ZBP-NEXT: rori a1, a1, 16
2333 %and = shl i64 %a, 16
2334 %shl = and i64 %and, -281470681808896
2335 %and1 = lshr i64 %a, 16
2336 %shr = and i64 %and1, 281470681808895
2337 %or = or i64 %shl, %shr
2341 declare i16 @llvm.bswap.i16(i16)
2343 define zeroext i16 @bswap_i16(i16 zeroext %a) nounwind {
2344 ; RV32I-LABEL: bswap_i16:
2346 ; RV32I-NEXT: srli a1, a0, 8
2347 ; RV32I-NEXT: slli a0, a0, 8
2348 ; RV32I-NEXT: or a0, a0, a1
2349 ; RV32I-NEXT: lui a1, 16
2350 ; RV32I-NEXT: addi a1, a1, -1
2351 ; RV32I-NEXT: and a0, a0, a1
2354 ; RV32B-LABEL: bswap_i16:
2356 ; RV32B-NEXT: rev8.h a0, a0
2359 ; RV32ZBP-LABEL: bswap_i16:
2361 ; RV32ZBP-NEXT: rev8.h a0, a0
2363 %1 = tail call i16 @llvm.bswap.i16(i16 %a)
2367 declare i32 @llvm.bswap.i32(i32)
2369 define i32 @bswap_i32(i32 %a) nounwind {
2370 ; RV32I-LABEL: bswap_i32:
2372 ; RV32I-NEXT: srli a1, a0, 8
2373 ; RV32I-NEXT: lui a2, 16
2374 ; RV32I-NEXT: addi a2, a2, -256
2375 ; RV32I-NEXT: and a1, a1, a2
2376 ; RV32I-NEXT: srli a2, a0, 24
2377 ; RV32I-NEXT: or a1, a1, a2
2378 ; RV32I-NEXT: slli a2, a0, 8
2379 ; RV32I-NEXT: lui a3, 4080
2380 ; RV32I-NEXT: and a2, a2, a3
2381 ; RV32I-NEXT: slli a0, a0, 24
2382 ; RV32I-NEXT: or a0, a0, a2
2383 ; RV32I-NEXT: or a0, a0, a1
2386 ; RV32B-LABEL: bswap_i32:
2388 ; RV32B-NEXT: rev8 a0, a0
2391 ; RV32ZBP-LABEL: bswap_i32:
2393 ; RV32ZBP-NEXT: rev8 a0, a0
2395 %1 = tail call i32 @llvm.bswap.i32(i32 %a)
2399 declare i64 @llvm.bswap.i64(i64)
2401 define i64 @bswap_i64(i64 %a) {
2402 ; RV32I-LABEL: bswap_i64:
2404 ; RV32I-NEXT: srli a2, a1, 8
2405 ; RV32I-NEXT: lui a3, 16
2406 ; RV32I-NEXT: addi a3, a3, -256
2407 ; RV32I-NEXT: and a2, a2, a3
2408 ; RV32I-NEXT: srli a4, a1, 24
2409 ; RV32I-NEXT: or a2, a2, a4
2410 ; RV32I-NEXT: slli a4, a1, 8
2411 ; RV32I-NEXT: lui a5, 4080
2412 ; RV32I-NEXT: and a4, a4, a5
2413 ; RV32I-NEXT: slli a1, a1, 24
2414 ; RV32I-NEXT: or a1, a1, a4
2415 ; RV32I-NEXT: or a2, a1, a2
2416 ; RV32I-NEXT: srli a1, a0, 8
2417 ; RV32I-NEXT: and a1, a1, a3
2418 ; RV32I-NEXT: srli a3, a0, 24
2419 ; RV32I-NEXT: or a1, a1, a3
2420 ; RV32I-NEXT: slli a3, a0, 8
2421 ; RV32I-NEXT: and a3, a3, a5
2422 ; RV32I-NEXT: slli a0, a0, 24
2423 ; RV32I-NEXT: or a0, a0, a3
2424 ; RV32I-NEXT: or a1, a0, a1
2425 ; RV32I-NEXT: mv a0, a2
2428 ; RV32B-LABEL: bswap_i64:
2430 ; RV32B-NEXT: rev8 a2, a1
2431 ; RV32B-NEXT: rev8 a1, a0
2432 ; RV32B-NEXT: mv a0, a2
2435 ; RV32ZBP-LABEL: bswap_i64:
2437 ; RV32ZBP-NEXT: rev8 a2, a1
2438 ; RV32ZBP-NEXT: rev8 a1, a0
2439 ; RV32ZBP-NEXT: mv a0, a2
2441 %1 = call i64 @llvm.bswap.i64(i64 %a)
2445 declare i8 @llvm.bitreverse.i8(i8)
2447 define zeroext i8 @bitreverse_i8(i8 zeroext %a) nounwind {
2448 ; RV32I-LABEL: bitreverse_i8:
2450 ; RV32I-NEXT: srli a1, a0, 4
2451 ; RV32I-NEXT: andi a0, a0, 15
2452 ; RV32I-NEXT: slli a0, a0, 4
2453 ; RV32I-NEXT: or a0, a1, a0
2454 ; RV32I-NEXT: andi a1, a0, 51
2455 ; RV32I-NEXT: slli a1, a1, 2
2456 ; RV32I-NEXT: andi a0, a0, 204
2457 ; RV32I-NEXT: srli a0, a0, 2
2458 ; RV32I-NEXT: or a0, a0, a1
2459 ; RV32I-NEXT: andi a1, a0, 85
2460 ; RV32I-NEXT: slli a1, a1, 1
2461 ; RV32I-NEXT: andi a0, a0, 170
2462 ; RV32I-NEXT: srli a0, a0, 1
2463 ; RV32I-NEXT: or a0, a0, a1
2466 ; RV32B-LABEL: bitreverse_i8:
2468 ; RV32B-NEXT: rev.b a0, a0
2471 ; RV32ZBP-LABEL: bitreverse_i8:
2473 ; RV32ZBP-NEXT: rev.b a0, a0
2475 %1 = tail call i8 @llvm.bitreverse.i8(i8 %a)
2479 declare i16 @llvm.bitreverse.i16(i16)
2481 define zeroext i16 @bitreverse_i16(i16 zeroext %a) nounwind {
2482 ; RV32I-LABEL: bitreverse_i16:
2484 ; RV32I-NEXT: srli a1, a0, 8
2485 ; RV32I-NEXT: slli a0, a0, 8
2486 ; RV32I-NEXT: or a0, a0, a1
2487 ; RV32I-NEXT: lui a1, 1
2488 ; RV32I-NEXT: addi a1, a1, -241
2489 ; RV32I-NEXT: and a1, a0, a1
2490 ; RV32I-NEXT: slli a1, a1, 4
2491 ; RV32I-NEXT: lui a2, 15
2492 ; RV32I-NEXT: addi a2, a2, 240
2493 ; RV32I-NEXT: and a0, a0, a2
2494 ; RV32I-NEXT: srli a0, a0, 4
2495 ; RV32I-NEXT: or a0, a0, a1
2496 ; RV32I-NEXT: lui a1, 3
2497 ; RV32I-NEXT: addi a1, a1, 819
2498 ; RV32I-NEXT: and a1, a0, a1
2499 ; RV32I-NEXT: slli a1, a1, 2
2500 ; RV32I-NEXT: lui a2, 13
2501 ; RV32I-NEXT: addi a2, a2, -820
2502 ; RV32I-NEXT: and a0, a0, a2
2503 ; RV32I-NEXT: srli a0, a0, 2
2504 ; RV32I-NEXT: or a0, a0, a1
2505 ; RV32I-NEXT: lui a1, 5
2506 ; RV32I-NEXT: addi a1, a1, 1365
2507 ; RV32I-NEXT: and a1, a0, a1
2508 ; RV32I-NEXT: slli a1, a1, 1
2509 ; RV32I-NEXT: lui a2, 11
2510 ; RV32I-NEXT: addi a2, a2, -1366
2511 ; RV32I-NEXT: and a0, a0, a2
2512 ; RV32I-NEXT: srli a0, a0, 1
2513 ; RV32I-NEXT: or a0, a0, a1
2516 ; RV32B-LABEL: bitreverse_i16:
2518 ; RV32B-NEXT: rev.h a0, a0
2521 ; RV32ZBP-LABEL: bitreverse_i16:
2523 ; RV32ZBP-NEXT: rev.h a0, a0
2525 %1 = tail call i16 @llvm.bitreverse.i16(i16 %a)
2529 declare i32 @llvm.bitreverse.i32(i32)
2531 define i32 @bitreverse_i32(i32 %a) nounwind {
2532 ; RV32I-LABEL: bitreverse_i32:
2534 ; RV32I-NEXT: srli a1, a0, 8
2535 ; RV32I-NEXT: lui a2, 16
2536 ; RV32I-NEXT: addi a2, a2, -256
2537 ; RV32I-NEXT: and a1, a1, a2
2538 ; RV32I-NEXT: srli a2, a0, 24
2539 ; RV32I-NEXT: or a1, a1, a2
2540 ; RV32I-NEXT: slli a2, a0, 8
2541 ; RV32I-NEXT: lui a3, 4080
2542 ; RV32I-NEXT: and a2, a2, a3
2543 ; RV32I-NEXT: slli a0, a0, 24
2544 ; RV32I-NEXT: or a0, a0, a2
2545 ; RV32I-NEXT: or a0, a0, a1
2546 ; RV32I-NEXT: lui a1, 61681
2547 ; RV32I-NEXT: addi a1, a1, -241
2548 ; RV32I-NEXT: and a1, a0, a1
2549 ; RV32I-NEXT: slli a1, a1, 4
2550 ; RV32I-NEXT: lui a2, 986895
2551 ; RV32I-NEXT: addi a2, a2, 240
2552 ; RV32I-NEXT: and a0, a0, a2
2553 ; RV32I-NEXT: srli a0, a0, 4
2554 ; RV32I-NEXT: or a0, a0, a1
2555 ; RV32I-NEXT: lui a1, 209715
2556 ; RV32I-NEXT: addi a1, a1, 819
2557 ; RV32I-NEXT: and a1, a0, a1
2558 ; RV32I-NEXT: slli a1, a1, 2
2559 ; RV32I-NEXT: lui a2, 838861
2560 ; RV32I-NEXT: addi a2, a2, -820
2561 ; RV32I-NEXT: and a0, a0, a2
2562 ; RV32I-NEXT: srli a0, a0, 2
2563 ; RV32I-NEXT: or a0, a0, a1
2564 ; RV32I-NEXT: lui a1, 349525
2565 ; RV32I-NEXT: addi a1, a1, 1365
2566 ; RV32I-NEXT: and a1, a0, a1
2567 ; RV32I-NEXT: slli a1, a1, 1
2568 ; RV32I-NEXT: lui a2, 699051
2569 ; RV32I-NEXT: addi a2, a2, -1366
2570 ; RV32I-NEXT: and a0, a0, a2
2571 ; RV32I-NEXT: srli a0, a0, 1
2572 ; RV32I-NEXT: or a0, a0, a1
2575 ; RV32B-LABEL: bitreverse_i32:
2577 ; RV32B-NEXT: rev a0, a0
2580 ; RV32ZBP-LABEL: bitreverse_i32:
2582 ; RV32ZBP-NEXT: rev a0, a0
2584 %1 = tail call i32 @llvm.bitreverse.i32(i32 %a)
2588 declare i64 @llvm.bitreverse.i64(i64)
2590 define i64 @bitreverse_i64(i64 %a) nounwind {
2591 ; RV32I-LABEL: bitreverse_i64:
2593 ; RV32I-NEXT: srli a2, a1, 8
2594 ; RV32I-NEXT: lui a3, 16
2595 ; RV32I-NEXT: addi t0, a3, -256
2596 ; RV32I-NEXT: and a2, a2, t0
2597 ; RV32I-NEXT: srli a4, a1, 24
2598 ; RV32I-NEXT: or a2, a2, a4
2599 ; RV32I-NEXT: slli a4, a1, 8
2600 ; RV32I-NEXT: lui a6, 4080
2601 ; RV32I-NEXT: and a4, a4, a6
2602 ; RV32I-NEXT: slli a1, a1, 24
2603 ; RV32I-NEXT: or a1, a1, a4
2604 ; RV32I-NEXT: or a1, a1, a2
2605 ; RV32I-NEXT: lui a2, 61681
2606 ; RV32I-NEXT: addi t1, a2, -241
2607 ; RV32I-NEXT: and a2, a1, t1
2608 ; RV32I-NEXT: slli a2, a2, 4
2609 ; RV32I-NEXT: lui a5, 986895
2610 ; RV32I-NEXT: addi t2, a5, 240
2611 ; RV32I-NEXT: and a1, a1, t2
2612 ; RV32I-NEXT: srli a1, a1, 4
2613 ; RV32I-NEXT: or a1, a1, a2
2614 ; RV32I-NEXT: lui a2, 209715
2615 ; RV32I-NEXT: addi t3, a2, 819
2616 ; RV32I-NEXT: and a3, a1, t3
2617 ; RV32I-NEXT: slli a3, a3, 2
2618 ; RV32I-NEXT: lui a4, 838861
2619 ; RV32I-NEXT: addi a4, a4, -820
2620 ; RV32I-NEXT: and a1, a1, a4
2621 ; RV32I-NEXT: srli a1, a1, 2
2622 ; RV32I-NEXT: or a1, a1, a3
2623 ; RV32I-NEXT: lui a3, 349525
2624 ; RV32I-NEXT: addi a3, a3, 1365
2625 ; RV32I-NEXT: and a5, a1, a3
2626 ; RV32I-NEXT: slli a5, a5, 1
2627 ; RV32I-NEXT: lui a2, 699051
2628 ; RV32I-NEXT: addi a2, a2, -1366
2629 ; RV32I-NEXT: and a1, a1, a2
2630 ; RV32I-NEXT: srli a1, a1, 1
2631 ; RV32I-NEXT: or a7, a1, a5
2632 ; RV32I-NEXT: srli a1, a0, 8
2633 ; RV32I-NEXT: and a1, a1, t0
2634 ; RV32I-NEXT: srli a5, a0, 24
2635 ; RV32I-NEXT: or a1, a1, a5
2636 ; RV32I-NEXT: slli a5, a0, 8
2637 ; RV32I-NEXT: and a5, a5, a6
2638 ; RV32I-NEXT: slli a0, a0, 24
2639 ; RV32I-NEXT: or a0, a0, a5
2640 ; RV32I-NEXT: or a0, a0, a1
2641 ; RV32I-NEXT: and a1, a0, t1
2642 ; RV32I-NEXT: slli a1, a1, 4
2643 ; RV32I-NEXT: and a0, a0, t2
2644 ; RV32I-NEXT: srli a0, a0, 4
2645 ; RV32I-NEXT: or a0, a0, a1
2646 ; RV32I-NEXT: and a1, a0, t3
2647 ; RV32I-NEXT: slli a1, a1, 2
2648 ; RV32I-NEXT: and a0, a0, a4
2649 ; RV32I-NEXT: srli a0, a0, 2
2650 ; RV32I-NEXT: or a0, a0, a1
2651 ; RV32I-NEXT: and a1, a0, a3
2652 ; RV32I-NEXT: slli a1, a1, 1
2653 ; RV32I-NEXT: and a0, a0, a2
2654 ; RV32I-NEXT: srli a0, a0, 1
2655 ; RV32I-NEXT: or a1, a0, a1
2656 ; RV32I-NEXT: mv a0, a7
2659 ; RV32B-LABEL: bitreverse_i64:
2661 ; RV32B-NEXT: rev a2, a1
2662 ; RV32B-NEXT: rev a1, a0
2663 ; RV32B-NEXT: mv a0, a2
2666 ; RV32ZBP-LABEL: bitreverse_i64:
2668 ; RV32ZBP-NEXT: rev a2, a1
2669 ; RV32ZBP-NEXT: rev a1, a0
2670 ; RV32ZBP-NEXT: mv a0, a2
2672 %1 = call i64 @llvm.bitreverse.i64(i64 %a)
2676 define i32 @bswap_rotr_i32(i32 %a) {
2677 ; RV32I-LABEL: bswap_rotr_i32:
2679 ; RV32I-NEXT: srli a1, a0, 8
2680 ; RV32I-NEXT: lui a2, 16
2681 ; RV32I-NEXT: addi a2, a2, -256
2682 ; RV32I-NEXT: and a1, a1, a2
2683 ; RV32I-NEXT: srli a2, a0, 24
2684 ; RV32I-NEXT: or a1, a1, a2
2685 ; RV32I-NEXT: slli a2, a0, 8
2686 ; RV32I-NEXT: lui a3, 4080
2687 ; RV32I-NEXT: and a2, a2, a3
2688 ; RV32I-NEXT: slli a0, a0, 24
2689 ; RV32I-NEXT: or a0, a0, a2
2690 ; RV32I-NEXT: or a0, a0, a1
2691 ; RV32I-NEXT: slli a1, a0, 16
2692 ; RV32I-NEXT: srli a0, a0, 16
2693 ; RV32I-NEXT: or a0, a0, a1
2696 ; RV32B-LABEL: bswap_rotr_i32:
2698 ; RV32B-NEXT: rev8.h a0, a0
2701 ; RV32ZBP-LABEL: bswap_rotr_i32:
2703 ; RV32ZBP-NEXT: rev8.h a0, a0
2705 %1 = call i32 @llvm.bswap.i32(i32 %a)
2706 %2 = call i32 @llvm.fshr.i32(i32 %1, i32 %1, i32 16)
2710 define i32 @bswap_rotl_i32(i32 %a) {
2711 ; RV32I-LABEL: bswap_rotl_i32:
2713 ; RV32I-NEXT: srli a1, a0, 8
2714 ; RV32I-NEXT: lui a2, 16
2715 ; RV32I-NEXT: addi a2, a2, -256
2716 ; RV32I-NEXT: and a1, a1, a2
2717 ; RV32I-NEXT: srli a2, a0, 24
2718 ; RV32I-NEXT: or a1, a1, a2
2719 ; RV32I-NEXT: slli a2, a0, 8
2720 ; RV32I-NEXT: lui a3, 4080
2721 ; RV32I-NEXT: and a2, a2, a3
2722 ; RV32I-NEXT: slli a0, a0, 24
2723 ; RV32I-NEXT: or a0, a0, a2
2724 ; RV32I-NEXT: or a0, a0, a1
2725 ; RV32I-NEXT: srli a1, a0, 16
2726 ; RV32I-NEXT: slli a0, a0, 16
2727 ; RV32I-NEXT: or a0, a0, a1
2730 ; RV32B-LABEL: bswap_rotl_i32:
2732 ; RV32B-NEXT: rev8.h a0, a0
2735 ; RV32ZBP-LABEL: bswap_rotl_i32:
2737 ; RV32ZBP-NEXT: rev8.h a0, a0
2739 %1 = call i32 @llvm.bswap.i32(i32 %a)
2740 %2 = call i32 @llvm.fshl.i32(i32 %1, i32 %1, i32 16)
2744 define i32 @bitreverse_bswap_i32(i32 %a) {
2745 ; RV32I-LABEL: bitreverse_bswap_i32:
2747 ; RV32I-NEXT: srli a1, a0, 8
2748 ; RV32I-NEXT: lui a2, 16
2749 ; RV32I-NEXT: addi a2, a2, -256
2750 ; RV32I-NEXT: and a1, a1, a2
2751 ; RV32I-NEXT: srli a3, a0, 24
2752 ; RV32I-NEXT: or a1, a1, a3
2753 ; RV32I-NEXT: slli a3, a0, 8
2754 ; RV32I-NEXT: lui a4, 4080
2755 ; RV32I-NEXT: and a3, a3, a4
2756 ; RV32I-NEXT: slli a0, a0, 24
2757 ; RV32I-NEXT: or a0, a0, a3
2758 ; RV32I-NEXT: or a0, a0, a1
2759 ; RV32I-NEXT: lui a1, 61681
2760 ; RV32I-NEXT: addi a1, a1, -241
2761 ; RV32I-NEXT: and a1, a0, a1
2762 ; RV32I-NEXT: slli a1, a1, 4
2763 ; RV32I-NEXT: lui a3, 986895
2764 ; RV32I-NEXT: addi a3, a3, 240
2765 ; RV32I-NEXT: and a0, a0, a3
2766 ; RV32I-NEXT: srli a0, a0, 4
2767 ; RV32I-NEXT: or a0, a0, a1
2768 ; RV32I-NEXT: lui a1, 209715
2769 ; RV32I-NEXT: addi a1, a1, 819
2770 ; RV32I-NEXT: and a1, a0, a1
2771 ; RV32I-NEXT: slli a1, a1, 2
2772 ; RV32I-NEXT: lui a3, 838861
2773 ; RV32I-NEXT: addi a3, a3, -820
2774 ; RV32I-NEXT: and a0, a0, a3
2775 ; RV32I-NEXT: srli a0, a0, 2
2776 ; RV32I-NEXT: or a0, a0, a1
2777 ; RV32I-NEXT: lui a1, 349525
2778 ; RV32I-NEXT: addi a1, a1, 1365
2779 ; RV32I-NEXT: and a1, a0, a1
2780 ; RV32I-NEXT: slli a1, a1, 1
2781 ; RV32I-NEXT: lui a3, 699051
2782 ; RV32I-NEXT: addi a3, a3, -1366
2783 ; RV32I-NEXT: and a0, a0, a3
2784 ; RV32I-NEXT: srli a0, a0, 1
2785 ; RV32I-NEXT: or a0, a0, a1
2786 ; RV32I-NEXT: srli a1, a0, 8
2787 ; RV32I-NEXT: and a1, a1, a2
2788 ; RV32I-NEXT: srli a2, a0, 24
2789 ; RV32I-NEXT: or a1, a1, a2
2790 ; RV32I-NEXT: slli a2, a0, 8
2791 ; RV32I-NEXT: and a2, a2, a4
2792 ; RV32I-NEXT: slli a0, a0, 24
2793 ; RV32I-NEXT: or a0, a0, a2
2794 ; RV32I-NEXT: or a0, a0, a1
2797 ; RV32B-LABEL: bitreverse_bswap_i32:
2799 ; RV32B-NEXT: rev.b a0, a0
2802 ; RV32ZBP-LABEL: bitreverse_bswap_i32:
2804 ; RV32ZBP-NEXT: rev.b a0, a0
2806 %1 = call i32 @llvm.bitreverse.i32(i32 %a)
2807 %2 = call i32 @llvm.bswap.i32(i32 %1)
2811 define i64 @bitreverse_bswap_i64(i64 %a) {
2812 ; RV32I-LABEL: bitreverse_bswap_i64:
2814 ; RV32I-NEXT: srli a3, a1, 8
2815 ; RV32I-NEXT: lui a2, 16
2816 ; RV32I-NEXT: addi t1, a2, -256
2817 ; RV32I-NEXT: and a3, a3, t1
2818 ; RV32I-NEXT: srli a4, a1, 24
2819 ; RV32I-NEXT: or a4, a3, a4
2820 ; RV32I-NEXT: slli a5, a1, 8
2821 ; RV32I-NEXT: lui a6, 4080
2822 ; RV32I-NEXT: and a5, a5, a6
2823 ; RV32I-NEXT: slli a1, a1, 24
2824 ; RV32I-NEXT: or a1, a1, a5
2825 ; RV32I-NEXT: or a1, a1, a4
2826 ; RV32I-NEXT: lui a4, 61681
2827 ; RV32I-NEXT: addi a7, a4, -241
2828 ; RV32I-NEXT: and a5, a1, a7
2829 ; RV32I-NEXT: slli a5, a5, 4
2830 ; RV32I-NEXT: lui a3, 986895
2831 ; RV32I-NEXT: addi t0, a3, 240
2832 ; RV32I-NEXT: and a1, a1, t0
2833 ; RV32I-NEXT: srli a1, a1, 4
2834 ; RV32I-NEXT: or a1, a1, a5
2835 ; RV32I-NEXT: lui a5, 209715
2836 ; RV32I-NEXT: addi t2, a5, 819
2837 ; RV32I-NEXT: and a4, a1, t2
2838 ; RV32I-NEXT: slli a4, a4, 2
2839 ; RV32I-NEXT: lui a3, 838861
2840 ; RV32I-NEXT: addi t3, a3, -820
2841 ; RV32I-NEXT: and a1, a1, t3
2842 ; RV32I-NEXT: srli a1, a1, 2
2843 ; RV32I-NEXT: or a1, a1, a4
2844 ; RV32I-NEXT: lui a4, 349525
2845 ; RV32I-NEXT: addi a4, a4, 1365
2846 ; RV32I-NEXT: and a2, a1, a4
2847 ; RV32I-NEXT: slli a2, a2, 1
2848 ; RV32I-NEXT: lui a5, 699051
2849 ; RV32I-NEXT: addi a5, a5, -1366
2850 ; RV32I-NEXT: and a1, a1, a5
2851 ; RV32I-NEXT: srli a1, a1, 1
2852 ; RV32I-NEXT: or a1, a1, a2
2853 ; RV32I-NEXT: srli a2, a0, 8
2854 ; RV32I-NEXT: and a2, a2, t1
2855 ; RV32I-NEXT: srli a3, a0, 24
2856 ; RV32I-NEXT: or a2, a2, a3
2857 ; RV32I-NEXT: slli a3, a0, 8
2858 ; RV32I-NEXT: and a3, a3, a6
2859 ; RV32I-NEXT: slli a0, a0, 24
2860 ; RV32I-NEXT: or a0, a0, a3
2861 ; RV32I-NEXT: or a0, a0, a2
2862 ; RV32I-NEXT: and a2, a0, a7
2863 ; RV32I-NEXT: slli a2, a2, 4
2864 ; RV32I-NEXT: and a0, a0, t0
2865 ; RV32I-NEXT: srli a0, a0, 4
2866 ; RV32I-NEXT: or a0, a0, a2
2867 ; RV32I-NEXT: and a2, a0, t2
2868 ; RV32I-NEXT: slli a2, a2, 2
2869 ; RV32I-NEXT: and a0, a0, t3
2870 ; RV32I-NEXT: srli a0, a0, 2
2871 ; RV32I-NEXT: or a0, a0, a2
2872 ; RV32I-NEXT: and a2, a0, a4
2873 ; RV32I-NEXT: slli a2, a2, 1
2874 ; RV32I-NEXT: and a0, a0, a5
2875 ; RV32I-NEXT: srli a0, a0, 1
2876 ; RV32I-NEXT: or a0, a0, a2
2877 ; RV32I-NEXT: srli a2, a0, 8
2878 ; RV32I-NEXT: and a2, a2, t1
2879 ; RV32I-NEXT: srli a3, a0, 24
2880 ; RV32I-NEXT: or a2, a2, a3
2881 ; RV32I-NEXT: slli a3, a0, 8
2882 ; RV32I-NEXT: and a3, a3, a6
2883 ; RV32I-NEXT: slli a0, a0, 24
2884 ; RV32I-NEXT: or a0, a0, a3
2885 ; RV32I-NEXT: or a0, a0, a2
2886 ; RV32I-NEXT: srli a2, a1, 8
2887 ; RV32I-NEXT: and a2, a2, t1
2888 ; RV32I-NEXT: srli a3, a1, 24
2889 ; RV32I-NEXT: or a2, a2, a3
2890 ; RV32I-NEXT: slli a3, a1, 8
2891 ; RV32I-NEXT: and a3, a3, a6
2892 ; RV32I-NEXT: slli a1, a1, 24
2893 ; RV32I-NEXT: or a1, a1, a3
2894 ; RV32I-NEXT: or a1, a1, a2
2897 ; RV32B-LABEL: bitreverse_bswap_i64:
2899 ; RV32B-NEXT: rev.b a0, a0
2900 ; RV32B-NEXT: rev.b a1, a1
2903 ; RV32ZBP-LABEL: bitreverse_bswap_i64:
2905 ; RV32ZBP-NEXT: rev.b a0, a0
2906 ; RV32ZBP-NEXT: rev.b a1, a1
2908 %1 = call i64 @llvm.bitreverse.i64(i64 %a)
2909 %2 = call i64 @llvm.bswap.i64(i64 %1)
2913 define i32 @shfl1_i32(i32 %a, i32 %b) nounwind {
2914 ; RV32I-LABEL: shfl1_i32:
2916 ; RV32I-NEXT: lui a1, 629146
2917 ; RV32I-NEXT: addi a1, a1, -1639
2918 ; RV32I-NEXT: and a1, a0, a1
2919 ; RV32I-NEXT: slli a2, a0, 1
2920 ; RV32I-NEXT: lui a3, 279620
2921 ; RV32I-NEXT: addi a3, a3, 1092
2922 ; RV32I-NEXT: and a2, a2, a3
2923 ; RV32I-NEXT: or a1, a2, a1
2924 ; RV32I-NEXT: srli a0, a0, 1
2925 ; RV32I-NEXT: lui a2, 139810
2926 ; RV32I-NEXT: addi a2, a2, 546
2927 ; RV32I-NEXT: and a0, a0, a2
2928 ; RV32I-NEXT: or a0, a1, a0
2931 ; RV32B-LABEL: shfl1_i32:
2933 ; RV32B-NEXT: zip.n a0, a0
2936 ; RV32ZBP-LABEL: shfl1_i32:
2938 ; RV32ZBP-NEXT: zip.n a0, a0
2940 %and = and i32 %a, -1717986919
2941 %shl = shl i32 %a, 1
2942 %and1 = and i32 %shl, 1145324612
2943 %or = or i32 %and1, %and
2944 %shr = lshr i32 %a, 1
2945 %and2 = and i32 %shr, 572662306
2946 %or3 = or i32 %or, %and2
2950 define i64 @shfl1_i64(i64 %a, i64 %b) nounwind {
2951 ; RV32I-LABEL: shfl1_i64:
2953 ; RV32I-NEXT: lui a2, 629146
2954 ; RV32I-NEXT: addi a2, a2, -1639
2955 ; RV32I-NEXT: and a6, a0, a2
2956 ; RV32I-NEXT: and a2, a1, a2
2957 ; RV32I-NEXT: slli a4, a1, 1
2958 ; RV32I-NEXT: slli a5, a0, 1
2959 ; RV32I-NEXT: lui a3, 279620
2960 ; RV32I-NEXT: addi a3, a3, 1092
2961 ; RV32I-NEXT: and a5, a5, a3
2962 ; RV32I-NEXT: and a3, a4, a3
2963 ; RV32I-NEXT: or a2, a2, a3
2964 ; RV32I-NEXT: or a3, a6, a5
2965 ; RV32I-NEXT: srli a0, a0, 1
2966 ; RV32I-NEXT: srli a1, a1, 1
2967 ; RV32I-NEXT: lui a4, 139810
2968 ; RV32I-NEXT: addi a4, a4, 546
2969 ; RV32I-NEXT: and a1, a1, a4
2970 ; RV32I-NEXT: and a0, a0, a4
2971 ; RV32I-NEXT: or a0, a3, a0
2972 ; RV32I-NEXT: or a1, a2, a1
2975 ; RV32B-LABEL: shfl1_i64:
2977 ; RV32B-NEXT: zip.n a0, a0
2978 ; RV32B-NEXT: zip.n a1, a1
2981 ; RV32ZBP-LABEL: shfl1_i64:
2983 ; RV32ZBP-NEXT: zip.n a0, a0
2984 ; RV32ZBP-NEXT: zip.n a1, a1
2986 %and = and i64 %a, -7378697629483820647
2987 %shl = shl i64 %a, 1
2988 %and1 = and i64 %shl, 4919131752989213764
2989 %or = or i64 %and, %and1
2990 %shr = lshr i64 %a, 1
2991 %and2 = and i64 %shr, 2459565876494606882
2992 %or3 = or i64 %or, %and2
2996 define i32 @shfl2_i32(i32 %a, i32 %b) nounwind {
2997 ; RV32I-LABEL: shfl2_i32:
2999 ; RV32I-NEXT: lui a1, 801852
3000 ; RV32I-NEXT: addi a1, a1, 963
3001 ; RV32I-NEXT: and a1, a0, a1
3002 ; RV32I-NEXT: slli a2, a0, 2
3003 ; RV32I-NEXT: lui a3, 197379
3004 ; RV32I-NEXT: addi a3, a3, 48
3005 ; RV32I-NEXT: and a2, a2, a3
3006 ; RV32I-NEXT: or a1, a2, a1
3007 ; RV32I-NEXT: srli a0, a0, 2
3008 ; RV32I-NEXT: lui a2, 49345
3009 ; RV32I-NEXT: addi a2, a2, -1012
3010 ; RV32I-NEXT: and a0, a0, a2
3011 ; RV32I-NEXT: or a0, a0, a1
3014 ; RV32B-LABEL: shfl2_i32:
3016 ; RV32B-NEXT: zip2.b a0, a0
3019 ; RV32ZBP-LABEL: shfl2_i32:
3021 ; RV32ZBP-NEXT: zip2.b a0, a0
3023 %and = and i32 %a, -1010580541
3024 %shl = shl i32 %a, 2
3025 %and1 = and i32 %shl, 808464432
3026 %or = or i32 %and1, %and
3027 %shr = lshr i32 %a, 2
3028 %and2 = and i32 %shr, 202116108
3029 %or3 = or i32 %and2, %or
3033 define i64 @shfl2_i64(i64 %a, i64 %b) nounwind {
3034 ; RV32I-LABEL: shfl2_i64:
3036 ; RV32I-NEXT: lui a2, 801852
3037 ; RV32I-NEXT: addi a2, a2, 963
3038 ; RV32I-NEXT: and a6, a0, a2
3039 ; RV32I-NEXT: and a2, a1, a2
3040 ; RV32I-NEXT: slli a4, a1, 2
3041 ; RV32I-NEXT: slli a5, a0, 2
3042 ; RV32I-NEXT: lui a3, 197379
3043 ; RV32I-NEXT: addi a3, a3, 48
3044 ; RV32I-NEXT: and a5, a5, a3
3045 ; RV32I-NEXT: and a3, a4, a3
3046 ; RV32I-NEXT: or a2, a2, a3
3047 ; RV32I-NEXT: or a3, a6, a5
3048 ; RV32I-NEXT: srli a0, a0, 2
3049 ; RV32I-NEXT: srli a1, a1, 2
3050 ; RV32I-NEXT: lui a4, 49345
3051 ; RV32I-NEXT: addi a4, a4, -1012
3052 ; RV32I-NEXT: and a1, a1, a4
3053 ; RV32I-NEXT: and a0, a0, a4
3054 ; RV32I-NEXT: or a0, a0, a3
3055 ; RV32I-NEXT: or a1, a1, a2
3058 ; RV32B-LABEL: shfl2_i64:
3060 ; RV32B-NEXT: zip2.b a0, a0
3061 ; RV32B-NEXT: zip2.b a1, a1
3064 ; RV32ZBP-LABEL: shfl2_i64:
3066 ; RV32ZBP-NEXT: zip2.b a0, a0
3067 ; RV32ZBP-NEXT: zip2.b a1, a1
3069 %and = and i64 %a, -4340410370284600381
3070 %shl = shl i64 %a, 2
3071 %and1 = and i64 %shl, 3472328296227680304
3072 %or = or i64 %and, %and1
3073 %shr = lshr i64 %a, 2
3074 %and2 = and i64 %shr, 868082074056920076
3075 %or3 = or i64 %and2, %or
3079 define i32 @shfl4_i32(i32 %a, i32 %b) nounwind {
3080 ; RV32I-LABEL: shfl4_i32:
3082 ; RV32I-NEXT: lui a1, 983295
3083 ; RV32I-NEXT: addi a1, a1, 15
3084 ; RV32I-NEXT: and a1, a0, a1
3085 ; RV32I-NEXT: slli a2, a0, 4
3086 ; RV32I-NEXT: lui a3, 61441
3087 ; RV32I-NEXT: addi a3, a3, -256
3088 ; RV32I-NEXT: and a2, a2, a3
3089 ; RV32I-NEXT: srli a0, a0, 4
3090 ; RV32I-NEXT: lui a3, 3840
3091 ; RV32I-NEXT: addi a3, a3, 240
3092 ; RV32I-NEXT: and a0, a0, a3
3093 ; RV32I-NEXT: or a0, a0, a1
3094 ; RV32I-NEXT: or a0, a0, a2
3097 ; RV32B-LABEL: shfl4_i32:
3099 ; RV32B-NEXT: zip4.h a0, a0
3102 ; RV32ZBP-LABEL: shfl4_i32:
3104 ; RV32ZBP-NEXT: zip4.h a0, a0
3106 %and = and i32 %a, -267390961
3107 %shl = shl i32 %a, 4
3108 %and1 = and i32 %shl, 251662080
3109 %shr = lshr i32 %a, 4
3110 %and2 = and i32 %shr, 15728880
3111 %or = or i32 %and2, %and
3112 %or3 = or i32 %or, %and1
3116 define i64 @shfl4_i64(i64 %a, i64 %b) nounwind {
3117 ; RV32I-LABEL: shfl4_i64:
3119 ; RV32I-NEXT: lui a2, 983295
3120 ; RV32I-NEXT: addi a2, a2, 15
3121 ; RV32I-NEXT: and a6, a1, a2
3122 ; RV32I-NEXT: and a2, a0, a2
3123 ; RV32I-NEXT: slli a4, a1, 4
3124 ; RV32I-NEXT: slli a5, a0, 4
3125 ; RV32I-NEXT: lui a3, 61441
3126 ; RV32I-NEXT: addi a3, a3, -256
3127 ; RV32I-NEXT: and a5, a5, a3
3128 ; RV32I-NEXT: and a3, a4, a3
3129 ; RV32I-NEXT: srli a1, a1, 4
3130 ; RV32I-NEXT: srli a0, a0, 4
3131 ; RV32I-NEXT: lui a4, 3840
3132 ; RV32I-NEXT: addi a4, a4, 240
3133 ; RV32I-NEXT: and a0, a0, a4
3134 ; RV32I-NEXT: and a1, a1, a4
3135 ; RV32I-NEXT: or a1, a3, a1
3136 ; RV32I-NEXT: or a0, a5, a0
3137 ; RV32I-NEXT: or a0, a0, a2
3138 ; RV32I-NEXT: or a1, a1, a6
3141 ; RV32B-LABEL: shfl4_i64:
3143 ; RV32B-NEXT: zip4.h a0, a0
3144 ; RV32B-NEXT: zip4.h a1, a1
3147 ; RV32ZBP-LABEL: shfl4_i64:
3149 ; RV32ZBP-NEXT: zip4.h a0, a0
3150 ; RV32ZBP-NEXT: zip4.h a1, a1
3152 %and = and i64 %a, -1148435428713435121
3153 %shl = shl i64 %a, 4
3154 %and1 = and i64 %shl, 1080880403494997760
3155 %shr = lshr i64 %a, 4
3156 %and2 = and i64 %shr, 67555025218437360
3157 %or = or i64 %and1, %and2
3158 %or3 = or i64 %or, %and
3162 define i32 @shfl8_i32(i32 %a, i32 %b) nounwind {
3163 ; RV32I-LABEL: shfl8_i32:
3165 ; RV32I-NEXT: lui a1, 1044480
3166 ; RV32I-NEXT: addi a1, a1, 255
3167 ; RV32I-NEXT: and a1, a0, a1
3168 ; RV32I-NEXT: slli a2, a0, 8
3169 ; RV32I-NEXT: lui a3, 4080
3170 ; RV32I-NEXT: and a2, a2, a3
3171 ; RV32I-NEXT: srli a0, a0, 8
3172 ; RV32I-NEXT: lui a3, 16
3173 ; RV32I-NEXT: addi a3, a3, -256
3174 ; RV32I-NEXT: and a0, a0, a3
3175 ; RV32I-NEXT: or a0, a1, a0
3176 ; RV32I-NEXT: or a0, a0, a2
3179 ; RV32B-LABEL: shfl8_i32:
3181 ; RV32B-NEXT: zip8 a0, a0
3184 ; RV32ZBP-LABEL: shfl8_i32:
3186 ; RV32ZBP-NEXT: zip8 a0, a0
3188 %and = and i32 %a, -16776961
3189 %shl = shl i32 %a, 8
3190 %and1 = and i32 %shl, 16711680
3191 %shr = lshr i32 %a, 8
3192 %and2 = and i32 %shr, 65280
3193 %or = or i32 %and, %and2
3194 %or3 = or i32 %or, %and1
3198 define i64 @shfl8_i64(i64 %a, i64 %b) nounwind {
3199 ; RV32I-LABEL: shfl8_i64:
3201 ; RV32I-NEXT: lui a2, 1044480
3202 ; RV32I-NEXT: addi a2, a2, 255
3203 ; RV32I-NEXT: and a6, a0, a2
3204 ; RV32I-NEXT: and a2, a1, a2
3205 ; RV32I-NEXT: slli a4, a0, 8
3206 ; RV32I-NEXT: slli a5, a1, 8
3207 ; RV32I-NEXT: lui a3, 4080
3208 ; RV32I-NEXT: and a5, a5, a3
3209 ; RV32I-NEXT: and a3, a4, a3
3210 ; RV32I-NEXT: srli a1, a1, 8
3211 ; RV32I-NEXT: srli a0, a0, 8
3212 ; RV32I-NEXT: lui a4, 16
3213 ; RV32I-NEXT: addi a4, a4, -256
3214 ; RV32I-NEXT: and a0, a0, a4
3215 ; RV32I-NEXT: and a1, a1, a4
3216 ; RV32I-NEXT: or a1, a1, a2
3217 ; RV32I-NEXT: or a0, a0, a6
3218 ; RV32I-NEXT: or a0, a3, a0
3219 ; RV32I-NEXT: or a1, a5, a1
3222 ; RV32B-LABEL: shfl8_i64:
3224 ; RV32B-NEXT: zip8 a0, a0
3225 ; RV32B-NEXT: zip8 a1, a1
3228 ; RV32ZBP-LABEL: shfl8_i64:
3230 ; RV32ZBP-NEXT: zip8 a0, a0
3231 ; RV32ZBP-NEXT: zip8 a1, a1
3233 %and = and i64 %a, -72056494543077121
3234 %shl = shl i64 %a, 8
3235 %and1 = and i64 %shl, 71776119077928960
3236 %shr = lshr i64 %a, 8
3237 %and2 = and i64 %shr, 280375465148160
3238 %or = or i64 %and2, %and
3239 %or3 = or i64 %and1, %or
3243 define i32 @pack_i32(i32 %a, i32 %b) nounwind {
3244 ; RV32I-LABEL: pack_i32:
3246 ; RV32I-NEXT: lui a2, 16
3247 ; RV32I-NEXT: addi a2, a2, -1
3248 ; RV32I-NEXT: and a0, a0, a2
3249 ; RV32I-NEXT: slli a1, a1, 16
3250 ; RV32I-NEXT: or a0, a1, a0
3253 ; RV32B-LABEL: pack_i32:
3255 ; RV32B-NEXT: pack a0, a0, a1
3258 ; RV32ZBP-LABEL: pack_i32:
3260 ; RV32ZBP-NEXT: pack a0, a0, a1
3262 %shl = and i32 %a, 65535
3263 %shl1 = shl i32 %b, 16
3264 %or = or i32 %shl1, %shl
3268 ; As we are not matching directly i64 code patterns on RV32 some i64 patterns
3269 ; don't have yet any matching bit manipulation instructions on RV32.
3270 ; This test is presented here in case future expansions of the experimental-b
3271 ; extension introduce instructions suitable for this pattern.
3273 define i64 @pack_i64(i64 %a, i64 %b) nounwind {
3274 ; RV32I-LABEL: pack_i64:
3276 ; RV32I-NEXT: mv a1, a2
3279 ; RV32B-LABEL: pack_i64:
3281 ; RV32B-NEXT: mv a1, a2
3284 ; RV32ZBP-LABEL: pack_i64:
3286 ; RV32ZBP-NEXT: mv a1, a2
3288 %shl = and i64 %a, 4294967295
3289 %shl1 = shl i64 %b, 32
3290 %or = or i64 %shl1, %shl
3294 define i32 @packu_i32(i32 %a, i32 %b) nounwind {
3295 ; RV32I-LABEL: packu_i32:
3297 ; RV32I-NEXT: srli a0, a0, 16
3298 ; RV32I-NEXT: lui a2, 1048560
3299 ; RV32I-NEXT: and a1, a1, a2
3300 ; RV32I-NEXT: or a0, a1, a0
3303 ; RV32B-LABEL: packu_i32:
3305 ; RV32B-NEXT: packu a0, a0, a1
3308 ; RV32ZBP-LABEL: packu_i32:
3310 ; RV32ZBP-NEXT: packu a0, a0, a1
3312 %shr = lshr i32 %a, 16
3313 %shr1 = and i32 %b, -65536
3314 %or = or i32 %shr1, %shr
3318 ; As we are not matching directly i64 code patterns on RV32 some i64 patterns
3319 ; don't have yet any matching bit manipulation instructions on RV32.
3320 ; This test is presented here in case future expansions of the experimental-b
3321 ; extension introduce instructions suitable for this pattern.
3323 define i64 @packu_i64(i64 %a, i64 %b) nounwind {
3324 ; RV32I-LABEL: packu_i64:
3326 ; RV32I-NEXT: mv a0, a1
3327 ; RV32I-NEXT: mv a1, a3
3330 ; RV32B-LABEL: packu_i64:
3332 ; RV32B-NEXT: mv a0, a1
3333 ; RV32B-NEXT: mv a1, a3
3336 ; RV32ZBP-LABEL: packu_i64:
3338 ; RV32ZBP-NEXT: mv a0, a1
3339 ; RV32ZBP-NEXT: mv a1, a3
3341 %shr = lshr i64 %a, 32
3342 %shr1 = and i64 %b, -4294967296
3343 %or = or i64 %shr1, %shr
3347 define i32 @packh_i32(i32 %a, i32 %b) nounwind {
3348 ; RV32I-LABEL: packh_i32:
3350 ; RV32I-NEXT: andi a0, a0, 255
3351 ; RV32I-NEXT: slli a1, a1, 24
3352 ; RV32I-NEXT: srli a1, a1, 16
3353 ; RV32I-NEXT: or a0, a1, a0
3356 ; RV32B-LABEL: packh_i32:
3358 ; RV32B-NEXT: packh a0, a0, a1
3361 ; RV32ZBP-LABEL: packh_i32:
3363 ; RV32ZBP-NEXT: packh a0, a0, a1
3365 %and = and i32 %a, 255
3366 %and1 = shl i32 %b, 8
3367 %shl = and i32 %and1, 65280
3368 %or = or i32 %shl, %and
3372 define i64 @packh_i64(i64 %a, i64 %b) nounwind {
3373 ; RV32I-LABEL: packh_i64:
3375 ; RV32I-NEXT: andi a0, a0, 255
3376 ; RV32I-NEXT: slli a1, a2, 24
3377 ; RV32I-NEXT: srli a1, a1, 16
3378 ; RV32I-NEXT: or a0, a1, a0
3379 ; RV32I-NEXT: mv a1, zero
3382 ; RV32B-LABEL: packh_i64:
3384 ; RV32B-NEXT: packh a0, a0, a2
3385 ; RV32B-NEXT: mv a1, zero
3388 ; RV32ZBP-LABEL: packh_i64:
3390 ; RV32ZBP-NEXT: packh a0, a0, a2
3391 ; RV32ZBP-NEXT: mv a1, zero
3393 %and = and i64 %a, 255
3394 %and1 = shl i64 %b, 8
3395 %shl = and i64 %and1, 65280
3396 %or = or i64 %shl, %and
3400 define i32 @zexth_i32(i32 %a) nounwind {
3401 ; RV32I-LABEL: zexth_i32:
3403 ; RV32I-NEXT: lui a1, 16
3404 ; RV32I-NEXT: addi a1, a1, -1
3405 ; RV32I-NEXT: and a0, a0, a1
3408 ; RV32B-LABEL: zexth_i32:
3410 ; RV32B-NEXT: zext.h a0, a0
3413 ; RV32ZBP-LABEL: zexth_i32:
3415 ; RV32ZBP-NEXT: zext.h a0, a0
3417 %and = and i32 %a, 65535
3421 define i64 @zexth_i64(i64 %a) nounwind {
3422 ; RV32I-LABEL: zexth_i64:
3424 ; RV32I-NEXT: lui a1, 16
3425 ; RV32I-NEXT: addi a1, a1, -1
3426 ; RV32I-NEXT: and a0, a0, a1
3427 ; RV32I-NEXT: mv a1, zero
3430 ; RV32B-LABEL: zexth_i64:
3432 ; RV32B-NEXT: zext.h a0, a0
3433 ; RV32B-NEXT: mv a1, zero
3436 ; RV32ZBP-LABEL: zexth_i64:
3438 ; RV32ZBP-NEXT: zext.h a0, a0
3439 ; RV32ZBP-NEXT: mv a1, zero
3441 %and = and i64 %a, 65535