1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV64I
4 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-b -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV64B
6 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-zbp -verify-machineinstrs < %s \
7 ; RUN: | FileCheck %s -check-prefix=RV64ZBP
9 define signext i32 @gorc1_i32(i32 signext %a) nounwind {
10 ; RV64I-LABEL: gorc1_i32:
12 ; RV64I-NEXT: slli a1, a0, 1
13 ; RV64I-NEXT: lui a2, 699051
14 ; RV64I-NEXT: addiw a2, a2, -1366
15 ; RV64I-NEXT: and a1, a1, a2
16 ; RV64I-NEXT: srli a2, a0, 1
17 ; RV64I-NEXT: lui a3, 349525
18 ; RV64I-NEXT: addiw a3, a3, 1365
19 ; RV64I-NEXT: and a2, a2, a3
20 ; RV64I-NEXT: or a0, a2, a0
21 ; RV64I-NEXT: or a0, a0, a1
22 ; RV64I-NEXT: sext.w a0, a0
25 ; RV64B-LABEL: gorc1_i32:
27 ; RV64B-NEXT: gorciw a0, a0, 1
30 ; RV64ZBP-LABEL: gorc1_i32:
32 ; RV64ZBP-NEXT: gorciw a0, a0, 1
35 %shl = and i32 %and, -1431655766
36 %and1 = lshr i32 %a, 1
37 %shr = and i32 %and1, 1431655765
39 %or2 = or i32 %or, %shl
43 define i64 @gorc1_i64(i64 %a) nounwind {
44 ; RV64I-LABEL: gorc1_i64:
46 ; RV64I-NEXT: slli a1, a0, 1
47 ; RV64I-NEXT: lui a2, 1026731
48 ; RV64I-NEXT: addiw a2, a2, -1365
49 ; RV64I-NEXT: slli a2, a2, 12
50 ; RV64I-NEXT: addi a2, a2, -1365
51 ; RV64I-NEXT: slli a2, a2, 12
52 ; RV64I-NEXT: addi a2, a2, -1365
53 ; RV64I-NEXT: slli a2, a2, 12
54 ; RV64I-NEXT: addi a2, a2, -1366
55 ; RV64I-NEXT: and a1, a1, a2
56 ; RV64I-NEXT: srli a2, a0, 1
57 ; RV64I-NEXT: lui a3, 21845
58 ; RV64I-NEXT: addiw a3, a3, 1365
59 ; RV64I-NEXT: slli a3, a3, 12
60 ; RV64I-NEXT: addi a3, a3, 1365
61 ; RV64I-NEXT: slli a3, a3, 12
62 ; RV64I-NEXT: addi a3, a3, 1365
63 ; RV64I-NEXT: slli a3, a3, 12
64 ; RV64I-NEXT: addi a3, a3, 1365
65 ; RV64I-NEXT: and a2, a2, a3
66 ; RV64I-NEXT: or a0, a2, a0
67 ; RV64I-NEXT: or a0, a0, a1
70 ; RV64B-LABEL: gorc1_i64:
72 ; RV64B-NEXT: orc.p a0, a0
75 ; RV64ZBP-LABEL: gorc1_i64:
77 ; RV64ZBP-NEXT: orc.p a0, a0
80 %shl = and i64 %and, -6148914691236517206
81 %and1 = lshr i64 %a, 1
82 %shr = and i64 %and1, 6148914691236517205
84 %or2 = or i64 %or, %shl
88 define signext i32 @gorc2_i32(i32 signext %a) nounwind {
89 ; RV64I-LABEL: gorc2_i32:
91 ; RV64I-NEXT: slli a1, a0, 2
92 ; RV64I-NEXT: lui a2, 838861
93 ; RV64I-NEXT: addiw a2, a2, -820
94 ; RV64I-NEXT: and a1, a1, a2
95 ; RV64I-NEXT: srli a2, a0, 2
96 ; RV64I-NEXT: lui a3, 209715
97 ; RV64I-NEXT: addiw a3, a3, 819
98 ; RV64I-NEXT: and a2, a2, a3
99 ; RV64I-NEXT: or a0, a2, a0
100 ; RV64I-NEXT: or a0, a0, a1
101 ; RV64I-NEXT: sext.w a0, a0
104 ; RV64B-LABEL: gorc2_i32:
106 ; RV64B-NEXT: gorciw a0, a0, 2
109 ; RV64ZBP-LABEL: gorc2_i32:
111 ; RV64ZBP-NEXT: gorciw a0, a0, 2
114 %shl = and i32 %and, -858993460
115 %and1 = lshr i32 %a, 2
116 %shr = and i32 %and1, 858993459
117 %or = or i32 %shr, %a
118 %or2 = or i32 %or, %shl
122 define i64 @gorc2_i64(i64 %a) nounwind {
123 ; RV64I-LABEL: gorc2_i64:
125 ; RV64I-NEXT: slli a1, a0, 2
126 ; RV64I-NEXT: lui a2, 1035469
127 ; RV64I-NEXT: addiw a2, a2, -819
128 ; RV64I-NEXT: slli a2, a2, 12
129 ; RV64I-NEXT: addi a2, a2, -819
130 ; RV64I-NEXT: slli a2, a2, 12
131 ; RV64I-NEXT: addi a2, a2, -819
132 ; RV64I-NEXT: slli a2, a2, 12
133 ; RV64I-NEXT: addi a2, a2, -820
134 ; RV64I-NEXT: and a1, a1, a2
135 ; RV64I-NEXT: srli a2, a0, 2
136 ; RV64I-NEXT: lui a3, 13107
137 ; RV64I-NEXT: addiw a3, a3, 819
138 ; RV64I-NEXT: slli a3, a3, 12
139 ; RV64I-NEXT: addi a3, a3, 819
140 ; RV64I-NEXT: slli a3, a3, 12
141 ; RV64I-NEXT: addi a3, a3, 819
142 ; RV64I-NEXT: slli a3, a3, 12
143 ; RV64I-NEXT: addi a3, a3, 819
144 ; RV64I-NEXT: and a2, a2, a3
145 ; RV64I-NEXT: or a0, a2, a0
146 ; RV64I-NEXT: or a0, a0, a1
149 ; RV64B-LABEL: gorc2_i64:
151 ; RV64B-NEXT: orc2.n a0, a0
154 ; RV64ZBP-LABEL: gorc2_i64:
156 ; RV64ZBP-NEXT: orc2.n a0, a0
159 %shl = and i64 %and, -3689348814741910324
160 %and1 = lshr i64 %a, 2
161 %shr = and i64 %and1, 3689348814741910323
162 %or = or i64 %shr, %a
163 %or2 = or i64 %or, %shl
167 define signext i32 @gorc3_i32(i32 signext %a) nounwind {
168 ; RV64I-LABEL: gorc3_i32:
170 ; RV64I-NEXT: slli a1, a0, 1
171 ; RV64I-NEXT: lui a2, 699051
172 ; RV64I-NEXT: addiw a2, a2, -1366
173 ; RV64I-NEXT: and a1, a1, a2
174 ; RV64I-NEXT: srli a2, a0, 1
175 ; RV64I-NEXT: lui a3, 349525
176 ; RV64I-NEXT: addiw a3, a3, 1365
177 ; RV64I-NEXT: and a2, a2, a3
178 ; RV64I-NEXT: or a0, a2, a0
179 ; RV64I-NEXT: or a0, a0, a1
180 ; RV64I-NEXT: slli a1, a0, 2
181 ; RV64I-NEXT: lui a2, 838861
182 ; RV64I-NEXT: addiw a2, a2, -820
183 ; RV64I-NEXT: and a1, a1, a2
184 ; RV64I-NEXT: srli a2, a0, 2
185 ; RV64I-NEXT: lui a3, 209715
186 ; RV64I-NEXT: addiw a3, a3, 819
187 ; RV64I-NEXT: and a2, a2, a3
188 ; RV64I-NEXT: or a0, a2, a0
189 ; RV64I-NEXT: or a0, a0, a1
190 ; RV64I-NEXT: sext.w a0, a0
193 ; RV64B-LABEL: gorc3_i32:
195 ; RV64B-NEXT: gorciw a0, a0, 3
198 ; RV64ZBP-LABEL: gorc3_i32:
200 ; RV64ZBP-NEXT: gorciw a0, a0, 3
202 %and1 = shl i32 %a, 1
203 %shl1 = and i32 %and1, -1431655766
204 %and1b = lshr i32 %a, 1
205 %shr1 = and i32 %and1b, 1431655765
206 %or1 = or i32 %shr1, %a
207 %or1b = or i32 %or1, %shl1
208 %and2 = shl i32 %or1b, 2
209 %shl2 = and i32 %and2, -858993460
210 %and2b = lshr i32 %or1b, 2
211 %shr2 = and i32 %and2b, 858993459
212 %or2 = or i32 %shr2, %or1b
213 %or2b = or i32 %or2, %shl2
217 define i64 @gorc3_i64(i64 %a) nounwind {
218 ; RV64I-LABEL: gorc3_i64:
220 ; RV64I-NEXT: slli a1, a0, 1
221 ; RV64I-NEXT: lui a2, 1026731
222 ; RV64I-NEXT: addiw a2, a2, -1365
223 ; RV64I-NEXT: slli a2, a2, 12
224 ; RV64I-NEXT: addi a2, a2, -1365
225 ; RV64I-NEXT: slli a2, a2, 12
226 ; RV64I-NEXT: addi a2, a2, -1365
227 ; RV64I-NEXT: slli a2, a2, 12
228 ; RV64I-NEXT: addi a2, a2, -1366
229 ; RV64I-NEXT: and a1, a1, a2
230 ; RV64I-NEXT: srli a2, a0, 1
231 ; RV64I-NEXT: lui a3, 21845
232 ; RV64I-NEXT: addiw a3, a3, 1365
233 ; RV64I-NEXT: slli a3, a3, 12
234 ; RV64I-NEXT: addi a3, a3, 1365
235 ; RV64I-NEXT: slli a3, a3, 12
236 ; RV64I-NEXT: addi a3, a3, 1365
237 ; RV64I-NEXT: slli a3, a3, 12
238 ; RV64I-NEXT: addi a3, a3, 1365
239 ; RV64I-NEXT: and a2, a2, a3
240 ; RV64I-NEXT: or a0, a2, a0
241 ; RV64I-NEXT: or a0, a0, a1
242 ; RV64I-NEXT: slli a1, a0, 2
243 ; RV64I-NEXT: lui a2, 1035469
244 ; RV64I-NEXT: addiw a2, a2, -819
245 ; RV64I-NEXT: slli a2, a2, 12
246 ; RV64I-NEXT: addi a2, a2, -819
247 ; RV64I-NEXT: slli a2, a2, 12
248 ; RV64I-NEXT: addi a2, a2, -819
249 ; RV64I-NEXT: slli a2, a2, 12
250 ; RV64I-NEXT: addi a2, a2, -820
251 ; RV64I-NEXT: and a1, a1, a2
252 ; RV64I-NEXT: srli a2, a0, 2
253 ; RV64I-NEXT: lui a3, 13107
254 ; RV64I-NEXT: addiw a3, a3, 819
255 ; RV64I-NEXT: slli a3, a3, 12
256 ; RV64I-NEXT: addi a3, a3, 819
257 ; RV64I-NEXT: slli a3, a3, 12
258 ; RV64I-NEXT: addi a3, a3, 819
259 ; RV64I-NEXT: slli a3, a3, 12
260 ; RV64I-NEXT: addi a3, a3, 819
261 ; RV64I-NEXT: and a2, a2, a3
262 ; RV64I-NEXT: or a0, a2, a0
263 ; RV64I-NEXT: or a0, a0, a1
266 ; RV64B-LABEL: gorc3_i64:
268 ; RV64B-NEXT: orc.n a0, a0
271 ; RV64ZBP-LABEL: gorc3_i64:
273 ; RV64ZBP-NEXT: orc.n a0, a0
275 %and1 = shl i64 %a, 1
276 %shl1 = and i64 %and1, -6148914691236517206
277 %and1b = lshr i64 %a, 1
278 %shr1 = and i64 %and1b, 6148914691236517205
279 %or1 = or i64 %shr1, %a
280 %or1b = or i64 %or1, %shl1
281 %and2 = shl i64 %or1b, 2
282 %shl2 = and i64 %and2, -3689348814741910324
283 %and2b = lshr i64 %or1b, 2
284 %shr2 = and i64 %and2b, 3689348814741910323
285 %or2 = or i64 %shr2, %or1b
286 %or2b = or i64 %or2, %shl2
290 define signext i32 @gorc4_i32(i32 signext %a) nounwind {
291 ; RV64I-LABEL: gorc4_i32:
293 ; RV64I-NEXT: slli a1, a0, 4
294 ; RV64I-NEXT: lui a2, 986895
295 ; RV64I-NEXT: addiw a2, a2, 240
296 ; RV64I-NEXT: and a1, a1, a2
297 ; RV64I-NEXT: srli a2, a0, 4
298 ; RV64I-NEXT: lui a3, 61681
299 ; RV64I-NEXT: addiw a3, a3, -241
300 ; RV64I-NEXT: and a2, a2, a3
301 ; RV64I-NEXT: or a0, a2, a0
302 ; RV64I-NEXT: or a0, a0, a1
303 ; RV64I-NEXT: sext.w a0, a0
306 ; RV64B-LABEL: gorc4_i32:
308 ; RV64B-NEXT: gorciw a0, a0, 4
311 ; RV64ZBP-LABEL: gorc4_i32:
313 ; RV64ZBP-NEXT: gorciw a0, a0, 4
316 %shl = and i32 %and, -252645136
317 %and1 = lshr i32 %a, 4
318 %shr = and i32 %and1, 252645135
319 %or = or i32 %shr, %a
320 %or2 = or i32 %or, %shl
324 define i64 @gorc4_i64(i64 %a) nounwind {
325 ; RV64I-LABEL: gorc4_i64:
327 ; RV64I-NEXT: slli a1, a0, 4
328 ; RV64I-NEXT: lui a2, 1044721
329 ; RV64I-NEXT: addiw a2, a2, -241
330 ; RV64I-NEXT: slli a2, a2, 12
331 ; RV64I-NEXT: addi a2, a2, 241
332 ; RV64I-NEXT: slli a2, a2, 12
333 ; RV64I-NEXT: addi a2, a2, -241
334 ; RV64I-NEXT: slli a2, a2, 12
335 ; RV64I-NEXT: addi a2, a2, 240
336 ; RV64I-NEXT: and a1, a1, a2
337 ; RV64I-NEXT: srli a2, a0, 4
338 ; RV64I-NEXT: lui a3, 3855
339 ; RV64I-NEXT: addiw a3, a3, 241
340 ; RV64I-NEXT: slli a3, a3, 12
341 ; RV64I-NEXT: addi a3, a3, -241
342 ; RV64I-NEXT: slli a3, a3, 12
343 ; RV64I-NEXT: addi a3, a3, 241
344 ; RV64I-NEXT: slli a3, a3, 12
345 ; RV64I-NEXT: addi a3, a3, -241
346 ; RV64I-NEXT: and a2, a2, a3
347 ; RV64I-NEXT: or a0, a2, a0
348 ; RV64I-NEXT: or a0, a0, a1
351 ; RV64B-LABEL: gorc4_i64:
353 ; RV64B-NEXT: orc4.b a0, a0
356 ; RV64ZBP-LABEL: gorc4_i64:
358 ; RV64ZBP-NEXT: orc4.b a0, a0
361 %shl = and i64 %and, -1085102592571150096
362 %and1 = lshr i64 %a, 4
363 %shr = and i64 %and1, 1085102592571150095
364 %or = or i64 %shr, %a
365 %or2 = or i64 %or, %shl
369 define signext i32 @gorc5_i32(i32 signext %a) nounwind {
370 ; RV64I-LABEL: gorc5_i32:
372 ; RV64I-NEXT: slli a1, a0, 1
373 ; RV64I-NEXT: lui a2, 699051
374 ; RV64I-NEXT: addiw a2, a2, -1366
375 ; RV64I-NEXT: and a1, a1, a2
376 ; RV64I-NEXT: srli a2, a0, 1
377 ; RV64I-NEXT: lui a3, 349525
378 ; RV64I-NEXT: addiw a3, a3, 1365
379 ; RV64I-NEXT: and a2, a2, a3
380 ; RV64I-NEXT: or a0, a2, a0
381 ; RV64I-NEXT: or a0, a0, a1
382 ; RV64I-NEXT: slli a1, a0, 4
383 ; RV64I-NEXT: lui a2, 986895
384 ; RV64I-NEXT: addiw a2, a2, 240
385 ; RV64I-NEXT: and a1, a1, a2
386 ; RV64I-NEXT: srli a2, a0, 4
387 ; RV64I-NEXT: lui a3, 61681
388 ; RV64I-NEXT: addiw a3, a3, -241
389 ; RV64I-NEXT: and a2, a2, a3
390 ; RV64I-NEXT: or a0, a2, a0
391 ; RV64I-NEXT: or a0, a0, a1
392 ; RV64I-NEXT: sext.w a0, a0
395 ; RV64B-LABEL: gorc5_i32:
397 ; RV64B-NEXT: gorciw a0, a0, 5
400 ; RV64ZBP-LABEL: gorc5_i32:
402 ; RV64ZBP-NEXT: gorciw a0, a0, 5
404 %and1 = shl i32 %a, 1
405 %shl1 = and i32 %and1, -1431655766
406 %and1b = lshr i32 %a, 1
407 %shr1 = and i32 %and1b, 1431655765
408 %or1 = or i32 %shr1, %a
409 %or1b = or i32 %or1, %shl1
410 %and2 = shl i32 %or1b, 4
411 %shl2 = and i32 %and2, -252645136
412 %and2b = lshr i32 %or1b, 4
413 %shr2 = and i32 %and2b, 252645135
414 %or2 = or i32 %shr2, %or1b
415 %or2b = or i32 %or2, %shl2
419 define i64 @gorc5_i64(i64 %a) nounwind {
420 ; RV64I-LABEL: gorc5_i64:
422 ; RV64I-NEXT: slli a1, a0, 1
423 ; RV64I-NEXT: lui a2, 1026731
424 ; RV64I-NEXT: addiw a2, a2, -1365
425 ; RV64I-NEXT: slli a2, a2, 12
426 ; RV64I-NEXT: addi a2, a2, -1365
427 ; RV64I-NEXT: slli a2, a2, 12
428 ; RV64I-NEXT: addi a2, a2, -1365
429 ; RV64I-NEXT: slli a2, a2, 12
430 ; RV64I-NEXT: addi a2, a2, -1366
431 ; RV64I-NEXT: and a1, a1, a2
432 ; RV64I-NEXT: srli a2, a0, 1
433 ; RV64I-NEXT: lui a3, 21845
434 ; RV64I-NEXT: addiw a3, a3, 1365
435 ; RV64I-NEXT: slli a3, a3, 12
436 ; RV64I-NEXT: addi a3, a3, 1365
437 ; RV64I-NEXT: slli a3, a3, 12
438 ; RV64I-NEXT: addi a3, a3, 1365
439 ; RV64I-NEXT: slli a3, a3, 12
440 ; RV64I-NEXT: addi a3, a3, 1365
441 ; RV64I-NEXT: and a2, a2, a3
442 ; RV64I-NEXT: or a0, a2, a0
443 ; RV64I-NEXT: or a0, a0, a1
444 ; RV64I-NEXT: slli a1, a0, 4
445 ; RV64I-NEXT: lui a2, 1044721
446 ; RV64I-NEXT: addiw a2, a2, -241
447 ; RV64I-NEXT: slli a2, a2, 12
448 ; RV64I-NEXT: addi a2, a2, 241
449 ; RV64I-NEXT: slli a2, a2, 12
450 ; RV64I-NEXT: addi a2, a2, -241
451 ; RV64I-NEXT: slli a2, a2, 12
452 ; RV64I-NEXT: addi a2, a2, 240
453 ; RV64I-NEXT: and a1, a1, a2
454 ; RV64I-NEXT: srli a2, a0, 4
455 ; RV64I-NEXT: lui a3, 3855
456 ; RV64I-NEXT: addiw a3, a3, 241
457 ; RV64I-NEXT: slli a3, a3, 12
458 ; RV64I-NEXT: addi a3, a3, -241
459 ; RV64I-NEXT: slli a3, a3, 12
460 ; RV64I-NEXT: addi a3, a3, 241
461 ; RV64I-NEXT: slli a3, a3, 12
462 ; RV64I-NEXT: addi a3, a3, -241
463 ; RV64I-NEXT: and a2, a2, a3
464 ; RV64I-NEXT: or a0, a2, a0
465 ; RV64I-NEXT: or a0, a0, a1
468 ; RV64B-LABEL: gorc5_i64:
470 ; RV64B-NEXT: gorci a0, a0, 5
473 ; RV64ZBP-LABEL: gorc5_i64:
475 ; RV64ZBP-NEXT: gorci a0, a0, 5
477 %and1 = shl i64 %a, 1
478 %shl1 = and i64 %and1, -6148914691236517206
479 %and1b = lshr i64 %a, 1
480 %shr1 = and i64 %and1b, 6148914691236517205
481 %or1 = or i64 %shr1, %a
482 %or1b = or i64 %or1, %shl1
483 %and2 = shl i64 %or1b, 4
484 %shl2 = and i64 %and2, -1085102592571150096
485 %and2b = lshr i64 %or1b, 4
486 %shr2 = and i64 %and2b, 1085102592571150095
487 %or2 = or i64 %shr2, %or1b
488 %or2b = or i64 %or2, %shl2
492 define signext i32 @gorc6_i32(i32 signext %a) nounwind {
493 ; RV64I-LABEL: gorc6_i32:
495 ; RV64I-NEXT: slli a1, a0, 2
496 ; RV64I-NEXT: lui a2, 838861
497 ; RV64I-NEXT: addiw a2, a2, -820
498 ; RV64I-NEXT: and a1, a1, a2
499 ; RV64I-NEXT: srli a2, a0, 2
500 ; RV64I-NEXT: lui a3, 209715
501 ; RV64I-NEXT: addiw a3, a3, 819
502 ; RV64I-NEXT: and a2, a2, a3
503 ; RV64I-NEXT: or a0, a2, a0
504 ; RV64I-NEXT: or a0, a0, a1
505 ; RV64I-NEXT: slli a1, a0, 4
506 ; RV64I-NEXT: lui a2, 986895
507 ; RV64I-NEXT: addiw a2, a2, 240
508 ; RV64I-NEXT: and a1, a1, a2
509 ; RV64I-NEXT: srli a2, a0, 4
510 ; RV64I-NEXT: lui a3, 61681
511 ; RV64I-NEXT: addiw a3, a3, -241
512 ; RV64I-NEXT: and a2, a2, a3
513 ; RV64I-NEXT: or a0, a2, a0
514 ; RV64I-NEXT: or a0, a0, a1
515 ; RV64I-NEXT: sext.w a0, a0
518 ; RV64B-LABEL: gorc6_i32:
520 ; RV64B-NEXT: gorciw a0, a0, 6
523 ; RV64ZBP-LABEL: gorc6_i32:
525 ; RV64ZBP-NEXT: gorciw a0, a0, 6
527 %and1 = shl i32 %a, 2
528 %shl1 = and i32 %and1, -858993460
529 %and1b = lshr i32 %a, 2
530 %shr1 = and i32 %and1b, 858993459
531 %or1 = or i32 %shr1, %a
532 %or1b = or i32 %or1, %shl1
533 %and2 = shl i32 %or1b, 4
534 %shl2 = and i32 %and2, -252645136
535 %and2b = lshr i32 %or1b, 4
536 %shr2 = and i32 %and2b, 252645135
537 %or2 = or i32 %shr2, %or1b
538 %or2b = or i32 %or2, %shl2
542 define i64 @gorc6_i64(i64 %a) nounwind {
543 ; RV64I-LABEL: gorc6_i64:
545 ; RV64I-NEXT: slli a1, a0, 2
546 ; RV64I-NEXT: lui a2, 1035469
547 ; RV64I-NEXT: addiw a2, a2, -819
548 ; RV64I-NEXT: slli a2, a2, 12
549 ; RV64I-NEXT: addi a2, a2, -819
550 ; RV64I-NEXT: slli a2, a2, 12
551 ; RV64I-NEXT: addi a2, a2, -819
552 ; RV64I-NEXT: slli a2, a2, 12
553 ; RV64I-NEXT: addi a2, a2, -820
554 ; RV64I-NEXT: and a1, a1, a2
555 ; RV64I-NEXT: srli a2, a0, 2
556 ; RV64I-NEXT: lui a3, 13107
557 ; RV64I-NEXT: addiw a3, a3, 819
558 ; RV64I-NEXT: slli a3, a3, 12
559 ; RV64I-NEXT: addi a3, a3, 819
560 ; RV64I-NEXT: slli a3, a3, 12
561 ; RV64I-NEXT: addi a3, a3, 819
562 ; RV64I-NEXT: slli a3, a3, 12
563 ; RV64I-NEXT: addi a3, a3, 819
564 ; RV64I-NEXT: and a2, a2, a3
565 ; RV64I-NEXT: or a0, a2, a0
566 ; RV64I-NEXT: or a0, a0, a1
567 ; RV64I-NEXT: slli a1, a0, 4
568 ; RV64I-NEXT: lui a2, 1044721
569 ; RV64I-NEXT: addiw a2, a2, -241
570 ; RV64I-NEXT: slli a2, a2, 12
571 ; RV64I-NEXT: addi a2, a2, 241
572 ; RV64I-NEXT: slli a2, a2, 12
573 ; RV64I-NEXT: addi a2, a2, -241
574 ; RV64I-NEXT: slli a2, a2, 12
575 ; RV64I-NEXT: addi a2, a2, 240
576 ; RV64I-NEXT: and a1, a1, a2
577 ; RV64I-NEXT: srli a2, a0, 4
578 ; RV64I-NEXT: lui a3, 3855
579 ; RV64I-NEXT: addiw a3, a3, 241
580 ; RV64I-NEXT: slli a3, a3, 12
581 ; RV64I-NEXT: addi a3, a3, -241
582 ; RV64I-NEXT: slli a3, a3, 12
583 ; RV64I-NEXT: addi a3, a3, 241
584 ; RV64I-NEXT: slli a3, a3, 12
585 ; RV64I-NEXT: addi a3, a3, -241
586 ; RV64I-NEXT: and a2, a2, a3
587 ; RV64I-NEXT: or a0, a2, a0
588 ; RV64I-NEXT: or a0, a0, a1
591 ; RV64B-LABEL: gorc6_i64:
593 ; RV64B-NEXT: orc2.b a0, a0
596 ; RV64ZBP-LABEL: gorc6_i64:
598 ; RV64ZBP-NEXT: orc2.b a0, a0
600 %and1 = shl i64 %a, 2
601 %shl1 = and i64 %and1, -3689348814741910324
602 %and1b = lshr i64 %a, 2
603 %shr1 = and i64 %and1b, 3689348814741910323
604 %or1 = or i64 %shr1, %a
605 %or1b = or i64 %or1, %shl1
606 %and2 = shl i64 %or1b, 4
607 %shl2 = and i64 %and2, -1085102592571150096
608 %and2b = lshr i64 %or1b, 4
609 %shr2 = and i64 %and2b, 1085102592571150095
610 %or2 = or i64 %shr2, %or1b
611 %or2b = or i64 %or2, %shl2
615 define signext i32 @gorc7_i32(i32 signext %a) nounwind {
616 ; RV64I-LABEL: gorc7_i32:
618 ; RV64I-NEXT: slli a1, a0, 1
619 ; RV64I-NEXT: lui a2, 699051
620 ; RV64I-NEXT: addiw a2, a2, -1366
621 ; RV64I-NEXT: and a1, a1, a2
622 ; RV64I-NEXT: srli a2, a0, 1
623 ; RV64I-NEXT: lui a3, 349525
624 ; RV64I-NEXT: addiw a3, a3, 1365
625 ; RV64I-NEXT: and a2, a2, a3
626 ; RV64I-NEXT: or a0, a2, a0
627 ; RV64I-NEXT: or a0, a0, a1
628 ; RV64I-NEXT: slli a1, a0, 2
629 ; RV64I-NEXT: lui a2, 838861
630 ; RV64I-NEXT: addiw a2, a2, -820
631 ; RV64I-NEXT: and a1, a1, a2
632 ; RV64I-NEXT: srli a2, a0, 2
633 ; RV64I-NEXT: lui a3, 209715
634 ; RV64I-NEXT: addiw a3, a3, 819
635 ; RV64I-NEXT: and a2, a2, a3
636 ; RV64I-NEXT: or a0, a2, a0
637 ; RV64I-NEXT: or a0, a0, a1
638 ; RV64I-NEXT: slli a1, a0, 4
639 ; RV64I-NEXT: lui a2, 986895
640 ; RV64I-NEXT: addiw a2, a2, 240
641 ; RV64I-NEXT: and a1, a1, a2
642 ; RV64I-NEXT: srli a2, a0, 4
643 ; RV64I-NEXT: lui a3, 61681
644 ; RV64I-NEXT: addiw a3, a3, -241
645 ; RV64I-NEXT: and a2, a2, a3
646 ; RV64I-NEXT: or a0, a2, a0
647 ; RV64I-NEXT: or a0, a0, a1
648 ; RV64I-NEXT: sext.w a0, a0
651 ; RV64B-LABEL: gorc7_i32:
653 ; RV64B-NEXT: gorciw a0, a0, 7
656 ; RV64ZBP-LABEL: gorc7_i32:
658 ; RV64ZBP-NEXT: gorciw a0, a0, 7
660 %and1 = shl i32 %a, 1
661 %shl1 = and i32 %and1, -1431655766
662 %and1b = lshr i32 %a, 1
663 %shr1 = and i32 %and1b, 1431655765
664 %or1 = or i32 %shr1, %a
665 %or1b = or i32 %or1, %shl1
666 %and2 = shl i32 %or1b, 2
667 %shl2 = and i32 %and2, -858993460
668 %and2b = lshr i32 %or1b, 2
669 %shr2 = and i32 %and2b, 858993459
670 %or2 = or i32 %shr2, %or1b
671 %or2b = or i32 %or2, %shl2
672 %and3 = shl i32 %or2b, 4
673 %shl3 = and i32 %and3, -252645136
674 %and3b = lshr i32 %or2b, 4
675 %shr3 = and i32 %and3b, 252645135
676 %or3 = or i32 %shr3, %or2b
677 %or3b = or i32 %or3, %shl3
681 define i64 @gorc7_i64(i64 %a) nounwind {
682 ; RV64I-LABEL: gorc7_i64:
684 ; RV64I-NEXT: slli a1, a0, 1
685 ; RV64I-NEXT: lui a2, 1026731
686 ; RV64I-NEXT: addiw a2, a2, -1365
687 ; RV64I-NEXT: slli a2, a2, 12
688 ; RV64I-NEXT: addi a2, a2, -1365
689 ; RV64I-NEXT: slli a2, a2, 12
690 ; RV64I-NEXT: addi a2, a2, -1365
691 ; RV64I-NEXT: slli a2, a2, 12
692 ; RV64I-NEXT: addi a2, a2, -1366
693 ; RV64I-NEXT: and a1, a1, a2
694 ; RV64I-NEXT: srli a2, a0, 1
695 ; RV64I-NEXT: lui a3, 21845
696 ; RV64I-NEXT: addiw a3, a3, 1365
697 ; RV64I-NEXT: slli a3, a3, 12
698 ; RV64I-NEXT: addi a3, a3, 1365
699 ; RV64I-NEXT: slli a3, a3, 12
700 ; RV64I-NEXT: addi a3, a3, 1365
701 ; RV64I-NEXT: slli a3, a3, 12
702 ; RV64I-NEXT: addi a3, a3, 1365
703 ; RV64I-NEXT: and a2, a2, a3
704 ; RV64I-NEXT: or a0, a2, a0
705 ; RV64I-NEXT: or a0, a0, a1
706 ; RV64I-NEXT: slli a1, a0, 2
707 ; RV64I-NEXT: lui a2, 1035469
708 ; RV64I-NEXT: addiw a2, a2, -819
709 ; RV64I-NEXT: slli a2, a2, 12
710 ; RV64I-NEXT: addi a2, a2, -819
711 ; RV64I-NEXT: slli a2, a2, 12
712 ; RV64I-NEXT: addi a2, a2, -819
713 ; RV64I-NEXT: slli a2, a2, 12
714 ; RV64I-NEXT: addi a2, a2, -820
715 ; RV64I-NEXT: and a1, a1, a2
716 ; RV64I-NEXT: srli a2, a0, 2
717 ; RV64I-NEXT: lui a3, 13107
718 ; RV64I-NEXT: addiw a3, a3, 819
719 ; RV64I-NEXT: slli a3, a3, 12
720 ; RV64I-NEXT: addi a3, a3, 819
721 ; RV64I-NEXT: slli a3, a3, 12
722 ; RV64I-NEXT: addi a3, a3, 819
723 ; RV64I-NEXT: slli a3, a3, 12
724 ; RV64I-NEXT: addi a3, a3, 819
725 ; RV64I-NEXT: and a2, a2, a3
726 ; RV64I-NEXT: or a0, a2, a0
727 ; RV64I-NEXT: or a0, a0, a1
728 ; RV64I-NEXT: slli a1, a0, 4
729 ; RV64I-NEXT: lui a2, 1044721
730 ; RV64I-NEXT: addiw a2, a2, -241
731 ; RV64I-NEXT: slli a2, a2, 12
732 ; RV64I-NEXT: addi a2, a2, 241
733 ; RV64I-NEXT: slli a2, a2, 12
734 ; RV64I-NEXT: addi a2, a2, -241
735 ; RV64I-NEXT: slli a2, a2, 12
736 ; RV64I-NEXT: addi a2, a2, 240
737 ; RV64I-NEXT: and a1, a1, a2
738 ; RV64I-NEXT: srli a2, a0, 4
739 ; RV64I-NEXT: lui a3, 3855
740 ; RV64I-NEXT: addiw a3, a3, 241
741 ; RV64I-NEXT: slli a3, a3, 12
742 ; RV64I-NEXT: addi a3, a3, -241
743 ; RV64I-NEXT: slli a3, a3, 12
744 ; RV64I-NEXT: addi a3, a3, 241
745 ; RV64I-NEXT: slli a3, a3, 12
746 ; RV64I-NEXT: addi a3, a3, -241
747 ; RV64I-NEXT: and a2, a2, a3
748 ; RV64I-NEXT: or a0, a2, a0
749 ; RV64I-NEXT: or a0, a0, a1
752 ; RV64B-LABEL: gorc7_i64:
754 ; RV64B-NEXT: orc.b a0, a0
757 ; RV64ZBP-LABEL: gorc7_i64:
759 ; RV64ZBP-NEXT: orc.b a0, a0
761 %and1 = shl i64 %a, 1
762 %shl1 = and i64 %and1, -6148914691236517206
763 %and1b = lshr i64 %a, 1
764 %shr1 = and i64 %and1b, 6148914691236517205
765 %or1 = or i64 %shr1, %a
766 %or1b = or i64 %or1, %shl1
767 %and2 = shl i64 %or1b, 2
768 %shl2 = and i64 %and2, -3689348814741910324
769 %and2b = lshr i64 %or1b, 2
770 %shr2 = and i64 %and2b, 3689348814741910323
771 %or2 = or i64 %shr2, %or1b
772 %or2b = or i64 %or2, %shl2
773 %and3 = shl i64 %or2b, 4
774 %shl3 = and i64 %and3, -1085102592571150096
775 %and3b = lshr i64 %or2b, 4
776 %shr3 = and i64 %and3b, 1085102592571150095
777 %or3 = or i64 %shr3, %or2b
778 %or3b = or i64 %or3, %shl3
782 define signext i32 @gorc8_i32(i32 signext %a) nounwind {
783 ; RV64I-LABEL: gorc8_i32:
785 ; RV64I-NEXT: slli a1, a0, 8
786 ; RV64I-NEXT: lui a2, 1044496
787 ; RV64I-NEXT: addiw a2, a2, -256
788 ; RV64I-NEXT: and a1, a1, a2
789 ; RV64I-NEXT: srli a2, a0, 8
790 ; RV64I-NEXT: lui a3, 4080
791 ; RV64I-NEXT: addiw a3, a3, 255
792 ; RV64I-NEXT: and a2, a2, a3
793 ; RV64I-NEXT: or a0, a2, a0
794 ; RV64I-NEXT: or a0, a0, a1
795 ; RV64I-NEXT: sext.w a0, a0
798 ; RV64B-LABEL: gorc8_i32:
800 ; RV64B-NEXT: gorciw a0, a0, 8
803 ; RV64ZBP-LABEL: gorc8_i32:
805 ; RV64ZBP-NEXT: gorciw a0, a0, 8
808 %shl = and i32 %and, -16711936
809 %and1 = lshr i32 %a, 8
810 %shr = and i32 %and1, 16711935
811 %or = or i32 %shr, %a
812 %or2 = or i32 %or, %shl
816 define i64 @gorc8_i64(i64 %a) nounwind {
817 ; RV64I-LABEL: gorc8_i64:
819 ; RV64I-NEXT: slli a1, a0, 8
820 ; RV64I-NEXT: lui a2, 1044496
821 ; RV64I-NEXT: addiw a2, a2, -255
822 ; RV64I-NEXT: slli a2, a2, 16
823 ; RV64I-NEXT: addi a2, a2, -255
824 ; RV64I-NEXT: slli a2, a2, 16
825 ; RV64I-NEXT: addi a2, a2, -256
826 ; RV64I-NEXT: and a1, a1, a2
827 ; RV64I-NEXT: srli a2, a0, 8
828 ; RV64I-NEXT: lui a3, 4080
829 ; RV64I-NEXT: addiw a3, a3, 255
830 ; RV64I-NEXT: slli a3, a3, 16
831 ; RV64I-NEXT: addi a3, a3, 255
832 ; RV64I-NEXT: slli a3, a3, 16
833 ; RV64I-NEXT: addi a3, a3, 255
834 ; RV64I-NEXT: and a2, a2, a3
835 ; RV64I-NEXT: or a0, a2, a0
836 ; RV64I-NEXT: or a0, a0, a1
839 ; RV64B-LABEL: gorc8_i64:
841 ; RV64B-NEXT: orc8.h a0, a0
844 ; RV64ZBP-LABEL: gorc8_i64:
846 ; RV64ZBP-NEXT: orc8.h a0, a0
849 %shl = and i64 %and, -71777214294589696
850 %and1 = lshr i64 %a, 8
851 %shr = and i64 %and1, 71777214294589695
852 %or = or i64 %shr, %a
853 %or2 = or i64 %or, %shl
857 define signext i32 @gorc16_i32(i32 signext %a) nounwind {
858 ; RV64I-LABEL: gorc16_i32:
860 ; RV64I-NEXT: slli a1, a0, 16
861 ; RV64I-NEXT: srliw a2, a0, 16
862 ; RV64I-NEXT: or a0, a2, a0
863 ; RV64I-NEXT: or a0, a0, a1
864 ; RV64I-NEXT: sext.w a0, a0
867 ; RV64B-LABEL: gorc16_i32:
869 ; RV64B-NEXT: gorciw a0, a0, 16
872 ; RV64ZBP-LABEL: gorc16_i32:
874 ; RV64ZBP-NEXT: gorciw a0, a0, 16
876 %shl = shl i32 %a, 16
877 %shr = lshr i32 %a, 16
878 %or = or i32 %shr, %a
879 %or2 = or i32 %or, %shl
883 define i32 @gorc16_rotl_i32(i32 %a) nounwind {
884 ; RV64I-LABEL: gorc16_rotl_i32:
886 ; RV64I-NEXT: srliw a1, a0, 16
887 ; RV64I-NEXT: slli a2, a0, 16
888 ; RV64I-NEXT: or a1, a2, a1
889 ; RV64I-NEXT: or a0, a1, a0
892 ; RV64B-LABEL: gorc16_rotl_i32:
894 ; RV64B-NEXT: gorciw a0, a0, 16
897 ; RV64ZBP-LABEL: gorc16_rotl_i32:
899 ; RV64ZBP-NEXT: gorciw a0, a0, 16
901 %rot = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 16)
902 %or = or i32 %rot, %a
906 define i32 @gorc16_rotr_i32(i32 %a) nounwind {
907 ; RV64I-LABEL: gorc16_rotr_i32:
909 ; RV64I-NEXT: slli a1, a0, 16
910 ; RV64I-NEXT: srliw a2, a0, 16
911 ; RV64I-NEXT: or a1, a2, a1
912 ; RV64I-NEXT: or a0, a1, a0
915 ; RV64B-LABEL: gorc16_rotr_i32:
917 ; RV64B-NEXT: gorciw a0, a0, 16
920 ; RV64ZBP-LABEL: gorc16_rotr_i32:
922 ; RV64ZBP-NEXT: gorciw a0, a0, 16
924 %rot = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 16)
925 %or = or i32 %rot, %a
929 define i64 @gorc16_i64(i64 %a) nounwind {
930 ; RV64I-LABEL: gorc16_i64:
932 ; RV64I-NEXT: slli a1, a0, 16
933 ; RV64I-NEXT: lui a2, 983041
934 ; RV64I-NEXT: slli a3, a2, 4
935 ; RV64I-NEXT: addi a3, a3, -1
936 ; RV64I-NEXT: slli a3, a3, 16
937 ; RV64I-NEXT: and a1, a1, a3
938 ; RV64I-NEXT: srli a3, a0, 16
939 ; RV64I-NEXT: slli a2, a2, 20
940 ; RV64I-NEXT: addi a2, a2, -1
941 ; RV64I-NEXT: srli a2, a2, 16
942 ; RV64I-NEXT: and a2, a3, a2
943 ; RV64I-NEXT: or a0, a2, a0
944 ; RV64I-NEXT: or a0, a0, a1
947 ; RV64B-LABEL: gorc16_i64:
949 ; RV64B-NEXT: orc16.w a0, a0
952 ; RV64ZBP-LABEL: gorc16_i64:
954 ; RV64ZBP-NEXT: orc16.w a0, a0
956 %and = shl i64 %a, 16
957 %shl = and i64 %and, -281470681808896
958 %and1 = lshr i64 %a, 16
959 %shr = and i64 %and1, 281470681808895
960 %or = or i64 %shr, %a
961 %or2 = or i64 %or, %shl
965 define i64 @gorc32(i64 %a) nounwind {
966 ; RV64I-LABEL: gorc32:
968 ; RV64I-NEXT: slli a1, a0, 32
969 ; RV64I-NEXT: srli a2, a0, 32
970 ; RV64I-NEXT: or a0, a2, a0
971 ; RV64I-NEXT: or a0, a0, a1
974 ; RV64B-LABEL: gorc32:
976 ; RV64B-NEXT: orc32 a0, a0
979 ; RV64ZBP-LABEL: gorc32:
981 ; RV64ZBP-NEXT: orc32 a0, a0
983 %shl = shl i64 %a, 32
984 %shr = lshr i64 %a, 32
985 %or = or i64 %shr, %a
986 %or2 = or i64 %or, %shl
990 ; gorc2, gorc2 -> gorc2
991 define signext i32 @gorc2b_i32(i32 signext %a) nounwind {
992 ; RV64I-LABEL: gorc2b_i32:
994 ; RV64I-NEXT: slli a1, a0, 2
995 ; RV64I-NEXT: lui a2, 838861
996 ; RV64I-NEXT: addiw a2, a2, -820
997 ; RV64I-NEXT: and a1, a1, a2
998 ; RV64I-NEXT: srli a3, a0, 2
999 ; RV64I-NEXT: lui a4, 209715
1000 ; RV64I-NEXT: addiw a4, a4, 819
1001 ; RV64I-NEXT: and a3, a3, a4
1002 ; RV64I-NEXT: or a0, a3, a0
1003 ; RV64I-NEXT: or a0, a0, a1
1004 ; RV64I-NEXT: slli a1, a0, 2
1005 ; RV64I-NEXT: and a1, a1, a2
1006 ; RV64I-NEXT: srli a2, a0, 2
1007 ; RV64I-NEXT: and a2, a2, a4
1008 ; RV64I-NEXT: or a0, a2, a0
1009 ; RV64I-NEXT: or a0, a0, a1
1010 ; RV64I-NEXT: sext.w a0, a0
1013 ; RV64B-LABEL: gorc2b_i32:
1015 ; RV64B-NEXT: gorciw a0, a0, 2
1018 ; RV64ZBP-LABEL: gorc2b_i32:
1020 ; RV64ZBP-NEXT: gorciw a0, a0, 2
1022 %and1 = shl i32 %a, 2
1023 %shl1 = and i32 %and1, -858993460
1024 %and1b = lshr i32 %a, 2
1025 %shr1 = and i32 %and1b, 858993459
1026 %or1 = or i32 %shr1, %a
1027 %or1b = or i32 %or1, %shl1
1028 %and2 = shl i32 %or1b, 2
1029 %shl2 = and i32 %and2, -858993460
1030 %and2b = lshr i32 %or1b, 2
1031 %shr2 = and i32 %and2b, 858993459
1032 %or2 = or i32 %shr2, %or1b
1033 %or2b = or i32 %or2, %shl2
1037 ; gorc2, gorc2 -> gorc2
1038 define i64 @gorc2b_i64(i64 %a) nounwind {
1039 ; RV64I-LABEL: gorc2b_i64:
1041 ; RV64I-NEXT: slli a1, a0, 2
1042 ; RV64I-NEXT: lui a2, 1035469
1043 ; RV64I-NEXT: addiw a2, a2, -819
1044 ; RV64I-NEXT: slli a2, a2, 12
1045 ; RV64I-NEXT: addi a2, a2, -819
1046 ; RV64I-NEXT: slli a2, a2, 12
1047 ; RV64I-NEXT: addi a2, a2, -819
1048 ; RV64I-NEXT: slli a2, a2, 12
1049 ; RV64I-NEXT: addi a2, a2, -820
1050 ; RV64I-NEXT: and a1, a1, a2
1051 ; RV64I-NEXT: srli a3, a0, 2
1052 ; RV64I-NEXT: lui a4, 13107
1053 ; RV64I-NEXT: addiw a4, a4, 819
1054 ; RV64I-NEXT: slli a4, a4, 12
1055 ; RV64I-NEXT: addi a4, a4, 819
1056 ; RV64I-NEXT: slli a4, a4, 12
1057 ; RV64I-NEXT: addi a4, a4, 819
1058 ; RV64I-NEXT: slli a4, a4, 12
1059 ; RV64I-NEXT: addi a4, a4, 819
1060 ; RV64I-NEXT: and a3, a3, a4
1061 ; RV64I-NEXT: or a0, a3, a0
1062 ; RV64I-NEXT: or a0, a0, a1
1063 ; RV64I-NEXT: slli a1, a0, 2
1064 ; RV64I-NEXT: and a1, a1, a2
1065 ; RV64I-NEXT: srli a2, a0, 2
1066 ; RV64I-NEXT: and a2, a2, a4
1067 ; RV64I-NEXT: or a0, a2, a0
1068 ; RV64I-NEXT: or a0, a0, a1
1071 ; RV64B-LABEL: gorc2b_i64:
1073 ; RV64B-NEXT: orc2.n a0, a0
1076 ; RV64ZBP-LABEL: gorc2b_i64:
1078 ; RV64ZBP-NEXT: orc2.n a0, a0
1080 %and1 = shl i64 %a, 2
1081 %shl1 = and i64 %and1, -3689348814741910324
1082 %and1b = lshr i64 %a, 2
1083 %shr1 = and i64 %and1b, 3689348814741910323
1084 %or1 = or i64 %shr1, %a
1085 %or1b = or i64 %or1, %shl1
1086 %and2 = shl i64 %or1b, 2
1087 %shl2 = and i64 %and2, -3689348814741910324
1088 %and2b = lshr i64 %or1b, 2
1089 %shr2 = and i64 %and2b, 3689348814741910323
1090 %or2 = or i64 %shr2, %or1b
1091 %or2b = or i64 %or2, %shl2
1095 ; gorc1, gorc2, gorc1 -> gorc2
1096 define signext i32 @gorc3b_i32(i32 signext %a) nounwind {
1097 ; RV64I-LABEL: gorc3b_i32:
1099 ; RV64I-NEXT: slli a1, a0, 1
1100 ; RV64I-NEXT: lui a2, 699051
1101 ; RV64I-NEXT: addiw a2, a2, -1366
1102 ; RV64I-NEXT: and a1, a1, a2
1103 ; RV64I-NEXT: srli a3, a0, 1
1104 ; RV64I-NEXT: lui a4, 349525
1105 ; RV64I-NEXT: addiw a4, a4, 1365
1106 ; RV64I-NEXT: and a3, a3, a4
1107 ; RV64I-NEXT: or a0, a3, a0
1108 ; RV64I-NEXT: or a0, a0, a1
1109 ; RV64I-NEXT: slli a1, a0, 2
1110 ; RV64I-NEXT: lui a3, 838861
1111 ; RV64I-NEXT: addiw a3, a3, -820
1112 ; RV64I-NEXT: and a1, a1, a3
1113 ; RV64I-NEXT: srli a3, a0, 2
1114 ; RV64I-NEXT: lui a5, 209715
1115 ; RV64I-NEXT: addiw a5, a5, 819
1116 ; RV64I-NEXT: and a3, a3, a5
1117 ; RV64I-NEXT: or a0, a3, a0
1118 ; RV64I-NEXT: or a0, a0, a1
1119 ; RV64I-NEXT: slli a1, a0, 1
1120 ; RV64I-NEXT: and a1, a1, a2
1121 ; RV64I-NEXT: srli a2, a0, 1
1122 ; RV64I-NEXT: and a2, a2, a4
1123 ; RV64I-NEXT: or a0, a2, a0
1124 ; RV64I-NEXT: or a0, a0, a1
1125 ; RV64I-NEXT: sext.w a0, a0
1128 ; RV64B-LABEL: gorc3b_i32:
1130 ; RV64B-NEXT: gorciw a0, a0, 3
1133 ; RV64ZBP-LABEL: gorc3b_i32:
1135 ; RV64ZBP-NEXT: gorciw a0, a0, 3
1137 %and1 = shl i32 %a, 1
1138 %shl1 = and i32 %and1, -1431655766
1139 %and1b = lshr i32 %a, 1
1140 %shr1 = and i32 %and1b, 1431655765
1141 %or1 = or i32 %shr1, %a
1142 %or1b = or i32 %or1, %shl1
1143 %and2 = shl i32 %or1b, 2
1144 %shl2 = and i32 %and2, -858993460
1145 %and2b = lshr i32 %or1b, 2
1146 %shr2 = and i32 %and2b, 858993459
1147 %or2 = or i32 %shr2, %or1b
1148 %or2b = or i32 %or2, %shl2
1149 %and3 = shl i32 %or2b, 1
1150 %shl3 = and i32 %and3, -1431655766
1151 %and3b = lshr i32 %or2b, 1
1152 %shr3 = and i32 %and3b, 1431655765
1153 %or3 = or i32 %shr3, %or2b
1154 %or3b = or i32 %or3, %shl3
1158 ; gorc1, gorc2, gorc1 -> gorc2
1159 define i64 @gorc3b_i64(i64 %a) nounwind {
1160 ; RV64I-LABEL: gorc3b_i64:
1162 ; RV64I-NEXT: slli a1, a0, 1
1163 ; RV64I-NEXT: lui a2, 1026731
1164 ; RV64I-NEXT: addiw a2, a2, -1365
1165 ; RV64I-NEXT: slli a2, a2, 12
1166 ; RV64I-NEXT: addi a2, a2, -1365
1167 ; RV64I-NEXT: slli a2, a2, 12
1168 ; RV64I-NEXT: addi a2, a2, -1365
1169 ; RV64I-NEXT: slli a2, a2, 12
1170 ; RV64I-NEXT: addi a2, a2, -1366
1171 ; RV64I-NEXT: and a1, a1, a2
1172 ; RV64I-NEXT: srli a3, a0, 1
1173 ; RV64I-NEXT: lui a4, 21845
1174 ; RV64I-NEXT: addiw a4, a4, 1365
1175 ; RV64I-NEXT: slli a4, a4, 12
1176 ; RV64I-NEXT: addi a4, a4, 1365
1177 ; RV64I-NEXT: slli a4, a4, 12
1178 ; RV64I-NEXT: addi a4, a4, 1365
1179 ; RV64I-NEXT: slli a4, a4, 12
1180 ; RV64I-NEXT: addi a4, a4, 1365
1181 ; RV64I-NEXT: and a3, a3, a4
1182 ; RV64I-NEXT: or a0, a3, a0
1183 ; RV64I-NEXT: or a0, a0, a1
1184 ; RV64I-NEXT: slli a1, a0, 2
1185 ; RV64I-NEXT: lui a3, 1035469
1186 ; RV64I-NEXT: addiw a3, a3, -819
1187 ; RV64I-NEXT: slli a3, a3, 12
1188 ; RV64I-NEXT: addi a3, a3, -819
1189 ; RV64I-NEXT: slli a3, a3, 12
1190 ; RV64I-NEXT: addi a3, a3, -819
1191 ; RV64I-NEXT: slli a3, a3, 12
1192 ; RV64I-NEXT: addi a3, a3, -820
1193 ; RV64I-NEXT: and a1, a1, a3
1194 ; RV64I-NEXT: srli a3, a0, 2
1195 ; RV64I-NEXT: lui a5, 13107
1196 ; RV64I-NEXT: addiw a5, a5, 819
1197 ; RV64I-NEXT: slli a5, a5, 12
1198 ; RV64I-NEXT: addi a5, a5, 819
1199 ; RV64I-NEXT: slli a5, a5, 12
1200 ; RV64I-NEXT: addi a5, a5, 819
1201 ; RV64I-NEXT: slli a5, a5, 12
1202 ; RV64I-NEXT: addi a5, a5, 819
1203 ; RV64I-NEXT: and a3, a3, a5
1204 ; RV64I-NEXT: or a0, a3, a0
1205 ; RV64I-NEXT: or a0, a0, a1
1206 ; RV64I-NEXT: slli a1, a0, 1
1207 ; RV64I-NEXT: and a1, a1, a2
1208 ; RV64I-NEXT: srli a2, a0, 1
1209 ; RV64I-NEXT: and a2, a2, a4
1210 ; RV64I-NEXT: or a0, a2, a0
1211 ; RV64I-NEXT: or a0, a0, a1
1214 ; RV64B-LABEL: gorc3b_i64:
1216 ; RV64B-NEXT: orc.n a0, a0
1219 ; RV64ZBP-LABEL: gorc3b_i64:
1221 ; RV64ZBP-NEXT: orc.n a0, a0
1223 %and1 = shl i64 %a, 1
1224 %shl1 = and i64 %and1, -6148914691236517206
1225 %and1b = lshr i64 %a, 1
1226 %shr1 = and i64 %and1b, 6148914691236517205
1227 %or1 = or i64 %shr1, %a
1228 %or1b = or i64 %or1, %shl1
1229 %and2 = shl i64 %or1b, 2
1230 %shl2 = and i64 %and2, -3689348814741910324
1231 %and2b = lshr i64 %or1b, 2
1232 %shr2 = and i64 %and2b, 3689348814741910323
1233 %or2 = or i64 %shr2, %or1b
1234 %or2b = or i64 %or2, %shl2
1235 %and3 = shl i64 %or2b, 1
1236 %shl3 = and i64 %and3, -6148914691236517206
1237 %and3b = lshr i64 %or2b, 1
1238 %shr3 = and i64 %and3b, 6148914691236517205
1239 %or3 = or i64 %shr3, %or2b
1240 %or3b = or i64 %or3, %shl3
1244 define i64 @gorc32_rotl(i64 %a) nounwind {
1245 ; RV64I-LABEL: gorc32_rotl:
1247 ; RV64I-NEXT: srli a1, a0, 32
1248 ; RV64I-NEXT: slli a2, a0, 32
1249 ; RV64I-NEXT: or a1, a2, a1
1250 ; RV64I-NEXT: or a0, a1, a0
1253 ; RV64B-LABEL: gorc32_rotl:
1255 ; RV64B-NEXT: orc32 a0, a0
1258 ; RV64ZBP-LABEL: gorc32_rotl:
1260 ; RV64ZBP-NEXT: orc32 a0, a0
1262 %rot = tail call i64 @llvm.fshl.i64(i64 %a, i64 %a, i64 32)
1263 %or = or i64 %rot, %a
1267 define i64 @gorc32_rotr(i64 %a) nounwind {
1268 ; RV64I-LABEL: gorc32_rotr:
1270 ; RV64I-NEXT: slli a1, a0, 32
1271 ; RV64I-NEXT: srli a2, a0, 32
1272 ; RV64I-NEXT: or a1, a2, a1
1273 ; RV64I-NEXT: or a0, a1, a0
1276 ; RV64B-LABEL: gorc32_rotr:
1278 ; RV64B-NEXT: orc32 a0, a0
1281 ; RV64ZBP-LABEL: gorc32_rotr:
1283 ; RV64ZBP-NEXT: orc32 a0, a0
1285 %rot = tail call i64 @llvm.fshr.i64(i64 %a, i64 %a, i64 32)
1286 %or = or i64 %rot, %a
1290 define signext i32 @grev1_i32(i32 signext %a) nounwind {
1291 ; RV64I-LABEL: grev1_i32:
1293 ; RV64I-NEXT: slli a1, a0, 1
1294 ; RV64I-NEXT: lui a2, 699051
1295 ; RV64I-NEXT: addiw a2, a2, -1366
1296 ; RV64I-NEXT: and a1, a1, a2
1297 ; RV64I-NEXT: srli a0, a0, 1
1298 ; RV64I-NEXT: lui a2, 349525
1299 ; RV64I-NEXT: addiw a2, a2, 1365
1300 ; RV64I-NEXT: and a0, a0, a2
1301 ; RV64I-NEXT: or a0, a1, a0
1302 ; RV64I-NEXT: sext.w a0, a0
1305 ; RV64B-LABEL: grev1_i32:
1307 ; RV64B-NEXT: greviw a0, a0, 1
1310 ; RV64ZBP-LABEL: grev1_i32:
1312 ; RV64ZBP-NEXT: greviw a0, a0, 1
1314 %and = shl i32 %a, 1
1315 %shl = and i32 %and, -1431655766
1316 %and1 = lshr i32 %a, 1
1317 %shr = and i32 %and1, 1431655765
1318 %or = or i32 %shl, %shr
1322 define i64 @grev1_i64(i64 %a) nounwind {
1323 ; RV64I-LABEL: grev1_i64:
1325 ; RV64I-NEXT: slli a1, a0, 1
1326 ; RV64I-NEXT: lui a2, 1026731
1327 ; RV64I-NEXT: addiw a2, a2, -1365
1328 ; RV64I-NEXT: slli a2, a2, 12
1329 ; RV64I-NEXT: addi a2, a2, -1365
1330 ; RV64I-NEXT: slli a2, a2, 12
1331 ; RV64I-NEXT: addi a2, a2, -1365
1332 ; RV64I-NEXT: slli a2, a2, 12
1333 ; RV64I-NEXT: addi a2, a2, -1366
1334 ; RV64I-NEXT: and a1, a1, a2
1335 ; RV64I-NEXT: srli a0, a0, 1
1336 ; RV64I-NEXT: lui a2, 21845
1337 ; RV64I-NEXT: addiw a2, a2, 1365
1338 ; RV64I-NEXT: slli a2, a2, 12
1339 ; RV64I-NEXT: addi a2, a2, 1365
1340 ; RV64I-NEXT: slli a2, a2, 12
1341 ; RV64I-NEXT: addi a2, a2, 1365
1342 ; RV64I-NEXT: slli a2, a2, 12
1343 ; RV64I-NEXT: addi a2, a2, 1365
1344 ; RV64I-NEXT: and a0, a0, a2
1345 ; RV64I-NEXT: or a0, a1, a0
1348 ; RV64B-LABEL: grev1_i64:
1350 ; RV64B-NEXT: rev.p a0, a0
1353 ; RV64ZBP-LABEL: grev1_i64:
1355 ; RV64ZBP-NEXT: rev.p a0, a0
1357 %and = shl i64 %a, 1
1358 %shl = and i64 %and, -6148914691236517206
1359 %and1 = lshr i64 %a, 1
1360 %shr = and i64 %and1, 6148914691236517205
1361 %or = or i64 %shl, %shr
1365 define signext i32 @grev2_i32(i32 signext %a) nounwind {
1366 ; RV64I-LABEL: grev2_i32:
1368 ; RV64I-NEXT: slli a1, a0, 2
1369 ; RV64I-NEXT: lui a2, 838861
1370 ; RV64I-NEXT: addiw a2, a2, -820
1371 ; RV64I-NEXT: and a1, a1, a2
1372 ; RV64I-NEXT: srli a0, a0, 2
1373 ; RV64I-NEXT: lui a2, 209715
1374 ; RV64I-NEXT: addiw a2, a2, 819
1375 ; RV64I-NEXT: and a0, a0, a2
1376 ; RV64I-NEXT: or a0, a1, a0
1377 ; RV64I-NEXT: sext.w a0, a0
1380 ; RV64B-LABEL: grev2_i32:
1382 ; RV64B-NEXT: greviw a0, a0, 2
1385 ; RV64ZBP-LABEL: grev2_i32:
1387 ; RV64ZBP-NEXT: greviw a0, a0, 2
1389 %and = shl i32 %a, 2
1390 %shl = and i32 %and, -858993460
1391 %and1 = lshr i32 %a, 2
1392 %shr = and i32 %and1, 858993459
1393 %or = or i32 %shl, %shr
1397 define i64 @grev2_i64(i64 %a) nounwind {
1398 ; RV64I-LABEL: grev2_i64:
1400 ; RV64I-NEXT: slli a1, a0, 2
1401 ; RV64I-NEXT: lui a2, 1035469
1402 ; RV64I-NEXT: addiw a2, a2, -819
1403 ; RV64I-NEXT: slli a2, a2, 12
1404 ; RV64I-NEXT: addi a2, a2, -819
1405 ; RV64I-NEXT: slli a2, a2, 12
1406 ; RV64I-NEXT: addi a2, a2, -819
1407 ; RV64I-NEXT: slli a2, a2, 12
1408 ; RV64I-NEXT: addi a2, a2, -820
1409 ; RV64I-NEXT: and a1, a1, a2
1410 ; RV64I-NEXT: srli a0, a0, 2
1411 ; RV64I-NEXT: lui a2, 13107
1412 ; RV64I-NEXT: addiw a2, a2, 819
1413 ; RV64I-NEXT: slli a2, a2, 12
1414 ; RV64I-NEXT: addi a2, a2, 819
1415 ; RV64I-NEXT: slli a2, a2, 12
1416 ; RV64I-NEXT: addi a2, a2, 819
1417 ; RV64I-NEXT: slli a2, a2, 12
1418 ; RV64I-NEXT: addi a2, a2, 819
1419 ; RV64I-NEXT: and a0, a0, a2
1420 ; RV64I-NEXT: or a0, a1, a0
1423 ; RV64B-LABEL: grev2_i64:
1425 ; RV64B-NEXT: rev2.n a0, a0
1428 ; RV64ZBP-LABEL: grev2_i64:
1430 ; RV64ZBP-NEXT: rev2.n a0, a0
1432 %and = shl i64 %a, 2
1433 %shl = and i64 %and, -3689348814741910324
1434 %and1 = lshr i64 %a, 2
1435 %shr = and i64 %and1, 3689348814741910323
1436 %or = or i64 %shl, %shr
1440 define signext i32 @grev3_i32(i32 signext %a) nounwind {
1441 ; RV64I-LABEL: grev3_i32:
1443 ; RV64I-NEXT: slli a1, a0, 1
1444 ; RV64I-NEXT: lui a2, 699051
1445 ; RV64I-NEXT: addiw a2, a2, -1366
1446 ; RV64I-NEXT: and a1, a1, a2
1447 ; RV64I-NEXT: srli a0, a0, 1
1448 ; RV64I-NEXT: lui a2, 349525
1449 ; RV64I-NEXT: addiw a2, a2, 1365
1450 ; RV64I-NEXT: and a0, a0, a2
1451 ; RV64I-NEXT: or a0, a1, a0
1452 ; RV64I-NEXT: slli a1, a0, 2
1453 ; RV64I-NEXT: lui a2, 838861
1454 ; RV64I-NEXT: addiw a2, a2, -820
1455 ; RV64I-NEXT: and a1, a1, a2
1456 ; RV64I-NEXT: srli a0, a0, 2
1457 ; RV64I-NEXT: lui a2, 209715
1458 ; RV64I-NEXT: addiw a2, a2, 819
1459 ; RV64I-NEXT: and a0, a0, a2
1460 ; RV64I-NEXT: or a0, a1, a0
1461 ; RV64I-NEXT: sext.w a0, a0
1464 ; RV64B-LABEL: grev3_i32:
1466 ; RV64B-NEXT: greviw a0, a0, 3
1469 ; RV64ZBP-LABEL: grev3_i32:
1471 ; RV64ZBP-NEXT: greviw a0, a0, 3
1473 %and1 = shl i32 %a, 1
1474 %shl1 = and i32 %and1, -1431655766
1475 %and1b = lshr i32 %a, 1
1476 %shr1 = and i32 %and1b, 1431655765
1477 %or1 = or i32 %shl1, %shr1
1478 %and2 = shl i32 %or1, 2
1479 %shl2 = and i32 %and2, -858993460
1480 %and2b = lshr i32 %or1, 2
1481 %shr2 = and i32 %and2b, 858993459
1482 %or2 = or i32 %shl2, %shr2
1486 define i64 @grev3_i64(i64 %a) nounwind {
1487 ; RV64I-LABEL: grev3_i64:
1489 ; RV64I-NEXT: slli a1, a0, 1
1490 ; RV64I-NEXT: lui a2, 1026731
1491 ; RV64I-NEXT: addiw a2, a2, -1365
1492 ; RV64I-NEXT: slli a2, a2, 12
1493 ; RV64I-NEXT: addi a2, a2, -1365
1494 ; RV64I-NEXT: slli a2, a2, 12
1495 ; RV64I-NEXT: addi a2, a2, -1365
1496 ; RV64I-NEXT: slli a2, a2, 12
1497 ; RV64I-NEXT: addi a2, a2, -1366
1498 ; RV64I-NEXT: and a1, a1, a2
1499 ; RV64I-NEXT: srli a0, a0, 1
1500 ; RV64I-NEXT: lui a2, 21845
1501 ; RV64I-NEXT: addiw a2, a2, 1365
1502 ; RV64I-NEXT: slli a2, a2, 12
1503 ; RV64I-NEXT: addi a2, a2, 1365
1504 ; RV64I-NEXT: slli a2, a2, 12
1505 ; RV64I-NEXT: addi a2, a2, 1365
1506 ; RV64I-NEXT: slli a2, a2, 12
1507 ; RV64I-NEXT: addi a2, a2, 1365
1508 ; RV64I-NEXT: and a0, a0, a2
1509 ; RV64I-NEXT: or a0, a1, a0
1510 ; RV64I-NEXT: slli a1, a0, 2
1511 ; RV64I-NEXT: lui a2, 1035469
1512 ; RV64I-NEXT: addiw a2, a2, -819
1513 ; RV64I-NEXT: slli a2, a2, 12
1514 ; RV64I-NEXT: addi a2, a2, -819
1515 ; RV64I-NEXT: slli a2, a2, 12
1516 ; RV64I-NEXT: addi a2, a2, -819
1517 ; RV64I-NEXT: slli a2, a2, 12
1518 ; RV64I-NEXT: addi a2, a2, -820
1519 ; RV64I-NEXT: and a1, a1, a2
1520 ; RV64I-NEXT: srli a0, a0, 2
1521 ; RV64I-NEXT: lui a2, 13107
1522 ; RV64I-NEXT: addiw a2, a2, 819
1523 ; RV64I-NEXT: slli a2, a2, 12
1524 ; RV64I-NEXT: addi a2, a2, 819
1525 ; RV64I-NEXT: slli a2, a2, 12
1526 ; RV64I-NEXT: addi a2, a2, 819
1527 ; RV64I-NEXT: slli a2, a2, 12
1528 ; RV64I-NEXT: addi a2, a2, 819
1529 ; RV64I-NEXT: and a0, a0, a2
1530 ; RV64I-NEXT: or a0, a1, a0
1533 ; RV64B-LABEL: grev3_i64:
1535 ; RV64B-NEXT: rev.n a0, a0
1538 ; RV64ZBP-LABEL: grev3_i64:
1540 ; RV64ZBP-NEXT: rev.n a0, a0
1542 %and1 = shl i64 %a, 1
1543 %shl1 = and i64 %and1, -6148914691236517206
1544 %and1b = lshr i64 %a, 1
1545 %shr1 = and i64 %and1b, 6148914691236517205
1546 %or1 = or i64 %shl1, %shr1
1547 %and2 = shl i64 %or1, 2
1548 %shl2 = and i64 %and2, -3689348814741910324
1549 %and2b = lshr i64 %or1, 2
1550 %shr2 = and i64 %and2b, 3689348814741910323
1551 %or2 = or i64 %shl2, %shr2
1555 define signext i32 @grev4_i32(i32 signext %a) nounwind {
1556 ; RV64I-LABEL: grev4_i32:
1558 ; RV64I-NEXT: slli a1, a0, 4
1559 ; RV64I-NEXT: lui a2, 986895
1560 ; RV64I-NEXT: addiw a2, a2, 240
1561 ; RV64I-NEXT: and a1, a1, a2
1562 ; RV64I-NEXT: srli a0, a0, 4
1563 ; RV64I-NEXT: lui a2, 61681
1564 ; RV64I-NEXT: addiw a2, a2, -241
1565 ; RV64I-NEXT: and a0, a0, a2
1566 ; RV64I-NEXT: or a0, a1, a0
1567 ; RV64I-NEXT: sext.w a0, a0
1570 ; RV64B-LABEL: grev4_i32:
1572 ; RV64B-NEXT: greviw a0, a0, 4
1575 ; RV64ZBP-LABEL: grev4_i32:
1577 ; RV64ZBP-NEXT: greviw a0, a0, 4
1579 %and = shl i32 %a, 4
1580 %shl = and i32 %and, -252645136
1581 %and1 = lshr i32 %a, 4
1582 %shr = and i32 %and1, 252645135
1583 %or = or i32 %shl, %shr
1587 define i64 @grev4_i64(i64 %a) nounwind {
1588 ; RV64I-LABEL: grev4_i64:
1590 ; RV64I-NEXT: slli a1, a0, 4
1591 ; RV64I-NEXT: lui a2, 1044721
1592 ; RV64I-NEXT: addiw a2, a2, -241
1593 ; RV64I-NEXT: slli a2, a2, 12
1594 ; RV64I-NEXT: addi a2, a2, 241
1595 ; RV64I-NEXT: slli a2, a2, 12
1596 ; RV64I-NEXT: addi a2, a2, -241
1597 ; RV64I-NEXT: slli a2, a2, 12
1598 ; RV64I-NEXT: addi a2, a2, 240
1599 ; RV64I-NEXT: and a1, a1, a2
1600 ; RV64I-NEXT: srli a0, a0, 4
1601 ; RV64I-NEXT: lui a2, 3855
1602 ; RV64I-NEXT: addiw a2, a2, 241
1603 ; RV64I-NEXT: slli a2, a2, 12
1604 ; RV64I-NEXT: addi a2, a2, -241
1605 ; RV64I-NEXT: slli a2, a2, 12
1606 ; RV64I-NEXT: addi a2, a2, 241
1607 ; RV64I-NEXT: slli a2, a2, 12
1608 ; RV64I-NEXT: addi a2, a2, -241
1609 ; RV64I-NEXT: and a0, a0, a2
1610 ; RV64I-NEXT: or a0, a1, a0
1613 ; RV64B-LABEL: grev4_i64:
1615 ; RV64B-NEXT: rev4.b a0, a0
1618 ; RV64ZBP-LABEL: grev4_i64:
1620 ; RV64ZBP-NEXT: rev4.b a0, a0
1622 %and = shl i64 %a, 4
1623 %shl = and i64 %and, -1085102592571150096
1624 %and1 = lshr i64 %a, 4
1625 %shr = and i64 %and1, 1085102592571150095
1626 %or = or i64 %shl, %shr
1630 define signext i32 @grev5_i32(i32 signext %a) nounwind {
1631 ; RV64I-LABEL: grev5_i32:
1633 ; RV64I-NEXT: slli a1, a0, 1
1634 ; RV64I-NEXT: lui a2, 699051
1635 ; RV64I-NEXT: addiw a2, a2, -1366
1636 ; RV64I-NEXT: and a1, a1, a2
1637 ; RV64I-NEXT: srli a0, a0, 1
1638 ; RV64I-NEXT: lui a2, 349525
1639 ; RV64I-NEXT: addiw a2, a2, 1365
1640 ; RV64I-NEXT: and a0, a0, a2
1641 ; RV64I-NEXT: or a0, a1, a0
1642 ; RV64I-NEXT: slli a1, a0, 4
1643 ; RV64I-NEXT: lui a2, 986895
1644 ; RV64I-NEXT: addiw a2, a2, 240
1645 ; RV64I-NEXT: and a1, a1, a2
1646 ; RV64I-NEXT: srli a0, a0, 4
1647 ; RV64I-NEXT: lui a2, 61681
1648 ; RV64I-NEXT: addiw a2, a2, -241
1649 ; RV64I-NEXT: and a0, a0, a2
1650 ; RV64I-NEXT: or a0, a1, a0
1651 ; RV64I-NEXT: sext.w a0, a0
1654 ; RV64B-LABEL: grev5_i32:
1656 ; RV64B-NEXT: greviw a0, a0, 5
1659 ; RV64ZBP-LABEL: grev5_i32:
1661 ; RV64ZBP-NEXT: greviw a0, a0, 5
1663 %and1 = shl i32 %a, 1
1664 %shl1 = and i32 %and1, -1431655766
1665 %and1b = lshr i32 %a, 1
1666 %shr1 = and i32 %and1b, 1431655765
1667 %or1 = or i32 %shl1, %shr1
1668 %and2 = shl i32 %or1, 4
1669 %shl2 = and i32 %and2, -252645136
1670 %and2b = lshr i32 %or1, 4
1671 %shr2 = and i32 %and2b, 252645135
1672 %or2 = or i32 %shl2, %shr2
1676 define i64 @grev5_i64(i64 %a) nounwind {
1677 ; RV64I-LABEL: grev5_i64:
1679 ; RV64I-NEXT: slli a1, a0, 1
1680 ; RV64I-NEXT: lui a2, 1026731
1681 ; RV64I-NEXT: addiw a2, a2, -1365
1682 ; RV64I-NEXT: slli a2, a2, 12
1683 ; RV64I-NEXT: addi a2, a2, -1365
1684 ; RV64I-NEXT: slli a2, a2, 12
1685 ; RV64I-NEXT: addi a2, a2, -1365
1686 ; RV64I-NEXT: slli a2, a2, 12
1687 ; RV64I-NEXT: addi a2, a2, -1366
1688 ; RV64I-NEXT: and a1, a1, a2
1689 ; RV64I-NEXT: srli a0, a0, 1
1690 ; RV64I-NEXT: lui a2, 21845
1691 ; RV64I-NEXT: addiw a2, a2, 1365
1692 ; RV64I-NEXT: slli a2, a2, 12
1693 ; RV64I-NEXT: addi a2, a2, 1365
1694 ; RV64I-NEXT: slli a2, a2, 12
1695 ; RV64I-NEXT: addi a2, a2, 1365
1696 ; RV64I-NEXT: slli a2, a2, 12
1697 ; RV64I-NEXT: addi a2, a2, 1365
1698 ; RV64I-NEXT: and a0, a0, a2
1699 ; RV64I-NEXT: or a0, a1, a0
1700 ; RV64I-NEXT: slli a1, a0, 4
1701 ; RV64I-NEXT: lui a2, 1044721
1702 ; RV64I-NEXT: addiw a2, a2, -241
1703 ; RV64I-NEXT: slli a2, a2, 12
1704 ; RV64I-NEXT: addi a2, a2, 241
1705 ; RV64I-NEXT: slli a2, a2, 12
1706 ; RV64I-NEXT: addi a2, a2, -241
1707 ; RV64I-NEXT: slli a2, a2, 12
1708 ; RV64I-NEXT: addi a2, a2, 240
1709 ; RV64I-NEXT: and a1, a1, a2
1710 ; RV64I-NEXT: srli a0, a0, 4
1711 ; RV64I-NEXT: lui a2, 3855
1712 ; RV64I-NEXT: addiw a2, a2, 241
1713 ; RV64I-NEXT: slli a2, a2, 12
1714 ; RV64I-NEXT: addi a2, a2, -241
1715 ; RV64I-NEXT: slli a2, a2, 12
1716 ; RV64I-NEXT: addi a2, a2, 241
1717 ; RV64I-NEXT: slli a2, a2, 12
1718 ; RV64I-NEXT: addi a2, a2, -241
1719 ; RV64I-NEXT: and a0, a0, a2
1720 ; RV64I-NEXT: or a0, a1, a0
1723 ; RV64B-LABEL: grev5_i64:
1725 ; RV64B-NEXT: grevi a0, a0, 5
1728 ; RV64ZBP-LABEL: grev5_i64:
1730 ; RV64ZBP-NEXT: grevi a0, a0, 5
1732 %and1 = shl i64 %a, 1
1733 %shl1 = and i64 %and1, -6148914691236517206
1734 %and1b = lshr i64 %a, 1
1735 %shr1 = and i64 %and1b, 6148914691236517205
1736 %or1 = or i64 %shl1, %shr1
1738 %and2 = shl i64 %or1, 4
1739 %shl2 = and i64 %and2, -1085102592571150096
1740 %and2b = lshr i64 %or1, 4
1741 %shr2 = and i64 %and2b, 1085102592571150095
1742 %or2 = or i64 %shl2, %shr2
1746 define signext i32 @grev6_i32(i32 signext %a) nounwind {
1747 ; RV64I-LABEL: grev6_i32:
1749 ; RV64I-NEXT: slli a1, a0, 2
1750 ; RV64I-NEXT: lui a2, 838861
1751 ; RV64I-NEXT: addiw a2, a2, -820
1752 ; RV64I-NEXT: and a1, a1, a2
1753 ; RV64I-NEXT: srli a0, a0, 2
1754 ; RV64I-NEXT: lui a2, 209715
1755 ; RV64I-NEXT: addiw a2, a2, 819
1756 ; RV64I-NEXT: and a0, a0, a2
1757 ; RV64I-NEXT: or a0, a1, a0
1758 ; RV64I-NEXT: slli a1, a0, 4
1759 ; RV64I-NEXT: lui a2, 986895
1760 ; RV64I-NEXT: addiw a2, a2, 240
1761 ; RV64I-NEXT: and a1, a1, a2
1762 ; RV64I-NEXT: srli a0, a0, 4
1763 ; RV64I-NEXT: lui a2, 61681
1764 ; RV64I-NEXT: addiw a2, a2, -241
1765 ; RV64I-NEXT: and a0, a0, a2
1766 ; RV64I-NEXT: or a0, a1, a0
1767 ; RV64I-NEXT: sext.w a0, a0
1770 ; RV64B-LABEL: grev6_i32:
1772 ; RV64B-NEXT: greviw a0, a0, 6
1775 ; RV64ZBP-LABEL: grev6_i32:
1777 ; RV64ZBP-NEXT: greviw a0, a0, 6
1779 %and1 = shl i32 %a, 2
1780 %shl1 = and i32 %and1, -858993460
1781 %and1b = lshr i32 %a, 2
1782 %shr1 = and i32 %and1b, 858993459
1783 %or1 = or i32 %shl1, %shr1
1784 %and2 = shl i32 %or1, 4
1785 %shl2 = and i32 %and2, -252645136
1786 %and2b = lshr i32 %or1, 4
1787 %shr2 = and i32 %and2b, 252645135
1788 %or2 = or i32 %shl2, %shr2
1792 define i64 @grev6_i64(i64 %a) nounwind {
1793 ; RV64I-LABEL: grev6_i64:
1795 ; RV64I-NEXT: slli a1, a0, 2
1796 ; RV64I-NEXT: lui a2, 1035469
1797 ; RV64I-NEXT: addiw a2, a2, -819
1798 ; RV64I-NEXT: slli a2, a2, 12
1799 ; RV64I-NEXT: addi a2, a2, -819
1800 ; RV64I-NEXT: slli a2, a2, 12
1801 ; RV64I-NEXT: addi a2, a2, -819
1802 ; RV64I-NEXT: slli a2, a2, 12
1803 ; RV64I-NEXT: addi a2, a2, -820
1804 ; RV64I-NEXT: and a1, a1, a2
1805 ; RV64I-NEXT: srli a0, a0, 2
1806 ; RV64I-NEXT: lui a2, 13107
1807 ; RV64I-NEXT: addiw a2, a2, 819
1808 ; RV64I-NEXT: slli a2, a2, 12
1809 ; RV64I-NEXT: addi a2, a2, 819
1810 ; RV64I-NEXT: slli a2, a2, 12
1811 ; RV64I-NEXT: addi a2, a2, 819
1812 ; RV64I-NEXT: slli a2, a2, 12
1813 ; RV64I-NEXT: addi a2, a2, 819
1814 ; RV64I-NEXT: and a0, a0, a2
1815 ; RV64I-NEXT: or a0, a1, a0
1816 ; RV64I-NEXT: slli a1, a0, 4
1817 ; RV64I-NEXT: lui a2, 1044721
1818 ; RV64I-NEXT: addiw a2, a2, -241
1819 ; RV64I-NEXT: slli a2, a2, 12
1820 ; RV64I-NEXT: addi a2, a2, 241
1821 ; RV64I-NEXT: slli a2, a2, 12
1822 ; RV64I-NEXT: addi a2, a2, -241
1823 ; RV64I-NEXT: slli a2, a2, 12
1824 ; RV64I-NEXT: addi a2, a2, 240
1825 ; RV64I-NEXT: and a1, a1, a2
1826 ; RV64I-NEXT: srli a0, a0, 4
1827 ; RV64I-NEXT: lui a2, 3855
1828 ; RV64I-NEXT: addiw a2, a2, 241
1829 ; RV64I-NEXT: slli a2, a2, 12
1830 ; RV64I-NEXT: addi a2, a2, -241
1831 ; RV64I-NEXT: slli a2, a2, 12
1832 ; RV64I-NEXT: addi a2, a2, 241
1833 ; RV64I-NEXT: slli a2, a2, 12
1834 ; RV64I-NEXT: addi a2, a2, -241
1835 ; RV64I-NEXT: and a0, a0, a2
1836 ; RV64I-NEXT: or a0, a1, a0
1839 ; RV64B-LABEL: grev6_i64:
1841 ; RV64B-NEXT: rev2.b a0, a0
1844 ; RV64ZBP-LABEL: grev6_i64:
1846 ; RV64ZBP-NEXT: rev2.b a0, a0
1848 %and1 = shl i64 %a, 2
1849 %shl1 = and i64 %and1, -3689348814741910324
1850 %and1b = lshr i64 %a, 2
1851 %shr1 = and i64 %and1b, 3689348814741910323
1852 %or1 = or i64 %shl1, %shr1
1853 %and2 = shl i64 %or1, 4
1854 %shl2 = and i64 %and2, -1085102592571150096
1855 %and2b = lshr i64 %or1, 4
1856 %shr2 = and i64 %and2b, 1085102592571150095
1857 %or2 = or i64 %shl2, %shr2
1861 define signext i32 @grev7_i32(i32 signext %a) nounwind {
1862 ; RV64I-LABEL: grev7_i32:
1864 ; RV64I-NEXT: slli a1, a0, 1
1865 ; RV64I-NEXT: lui a2, 699051
1866 ; RV64I-NEXT: addiw a2, a2, -1366
1867 ; RV64I-NEXT: and a1, a1, a2
1868 ; RV64I-NEXT: srli a0, a0, 1
1869 ; RV64I-NEXT: lui a2, 349525
1870 ; RV64I-NEXT: addiw a2, a2, 1365
1871 ; RV64I-NEXT: and a0, a0, a2
1872 ; RV64I-NEXT: or a0, a1, a0
1873 ; RV64I-NEXT: slli a1, a0, 2
1874 ; RV64I-NEXT: lui a2, 838861
1875 ; RV64I-NEXT: addiw a2, a2, -820
1876 ; RV64I-NEXT: and a1, a1, a2
1877 ; RV64I-NEXT: srli a0, a0, 2
1878 ; RV64I-NEXT: lui a2, 209715
1879 ; RV64I-NEXT: addiw a2, a2, 819
1880 ; RV64I-NEXT: and a0, a0, a2
1881 ; RV64I-NEXT: or a0, a1, a0
1882 ; RV64I-NEXT: slli a1, a0, 4
1883 ; RV64I-NEXT: lui a2, 986895
1884 ; RV64I-NEXT: addiw a2, a2, 240
1885 ; RV64I-NEXT: and a1, a1, a2
1886 ; RV64I-NEXT: srli a0, a0, 4
1887 ; RV64I-NEXT: lui a2, 61681
1888 ; RV64I-NEXT: addiw a2, a2, -241
1889 ; RV64I-NEXT: and a0, a0, a2
1890 ; RV64I-NEXT: or a0, a1, a0
1891 ; RV64I-NEXT: sext.w a0, a0
1894 ; RV64B-LABEL: grev7_i32:
1896 ; RV64B-NEXT: greviw a0, a0, 7
1899 ; RV64ZBP-LABEL: grev7_i32:
1901 ; RV64ZBP-NEXT: greviw a0, a0, 7
1903 %and1 = shl i32 %a, 1
1904 %shl1 = and i32 %and1, -1431655766
1905 %and1b = lshr i32 %a, 1
1906 %shr1 = and i32 %and1b, 1431655765
1907 %or1 = or i32 %shl1, %shr1
1908 %and2 = shl i32 %or1, 2
1909 %shl2 = and i32 %and2, -858993460
1910 %and2b = lshr i32 %or1, 2
1911 %shr2 = and i32 %and2b, 858993459
1912 %or2 = or i32 %shl2, %shr2
1913 %and3 = shl i32 %or2, 4
1914 %shl3 = and i32 %and3, -252645136
1915 %and3b = lshr i32 %or2, 4
1916 %shr3 = and i32 %and3b, 252645135
1917 %or3 = or i32 %shl3, %shr3
1921 define i64 @grev7_i64(i64 %a) nounwind {
1922 ; RV64I-LABEL: grev7_i64:
1924 ; RV64I-NEXT: slli a1, a0, 1
1925 ; RV64I-NEXT: lui a2, 1026731
1926 ; RV64I-NEXT: addiw a2, a2, -1365
1927 ; RV64I-NEXT: slli a2, a2, 12
1928 ; RV64I-NEXT: addi a2, a2, -1365
1929 ; RV64I-NEXT: slli a2, a2, 12
1930 ; RV64I-NEXT: addi a2, a2, -1365
1931 ; RV64I-NEXT: slli a2, a2, 12
1932 ; RV64I-NEXT: addi a2, a2, -1366
1933 ; RV64I-NEXT: and a1, a1, a2
1934 ; RV64I-NEXT: srli a0, a0, 1
1935 ; RV64I-NEXT: lui a2, 21845
1936 ; RV64I-NEXT: addiw a2, a2, 1365
1937 ; RV64I-NEXT: slli a2, a2, 12
1938 ; RV64I-NEXT: addi a2, a2, 1365
1939 ; RV64I-NEXT: slli a2, a2, 12
1940 ; RV64I-NEXT: addi a2, a2, 1365
1941 ; RV64I-NEXT: slli a2, a2, 12
1942 ; RV64I-NEXT: addi a2, a2, 1365
1943 ; RV64I-NEXT: and a0, a0, a2
1944 ; RV64I-NEXT: or a0, a1, a0
1945 ; RV64I-NEXT: slli a1, a0, 2
1946 ; RV64I-NEXT: lui a2, 1035469
1947 ; RV64I-NEXT: addiw a2, a2, -819
1948 ; RV64I-NEXT: slli a2, a2, 12
1949 ; RV64I-NEXT: addi a2, a2, -819
1950 ; RV64I-NEXT: slli a2, a2, 12
1951 ; RV64I-NEXT: addi a2, a2, -819
1952 ; RV64I-NEXT: slli a2, a2, 12
1953 ; RV64I-NEXT: addi a2, a2, -820
1954 ; RV64I-NEXT: and a1, a1, a2
1955 ; RV64I-NEXT: srli a0, a0, 2
1956 ; RV64I-NEXT: lui a2, 13107
1957 ; RV64I-NEXT: addiw a2, a2, 819
1958 ; RV64I-NEXT: slli a2, a2, 12
1959 ; RV64I-NEXT: addi a2, a2, 819
1960 ; RV64I-NEXT: slli a2, a2, 12
1961 ; RV64I-NEXT: addi a2, a2, 819
1962 ; RV64I-NEXT: slli a2, a2, 12
1963 ; RV64I-NEXT: addi a2, a2, 819
1964 ; RV64I-NEXT: and a0, a0, a2
1965 ; RV64I-NEXT: or a0, a1, a0
1966 ; RV64I-NEXT: slli a1, a0, 4
1967 ; RV64I-NEXT: lui a2, 1044721
1968 ; RV64I-NEXT: addiw a2, a2, -241
1969 ; RV64I-NEXT: slli a2, a2, 12
1970 ; RV64I-NEXT: addi a2, a2, 241
1971 ; RV64I-NEXT: slli a2, a2, 12
1972 ; RV64I-NEXT: addi a2, a2, -241
1973 ; RV64I-NEXT: slli a2, a2, 12
1974 ; RV64I-NEXT: addi a2, a2, 240
1975 ; RV64I-NEXT: and a1, a1, a2
1976 ; RV64I-NEXT: srli a0, a0, 4
1977 ; RV64I-NEXT: lui a2, 3855
1978 ; RV64I-NEXT: addiw a2, a2, 241
1979 ; RV64I-NEXT: slli a2, a2, 12
1980 ; RV64I-NEXT: addi a2, a2, -241
1981 ; RV64I-NEXT: slli a2, a2, 12
1982 ; RV64I-NEXT: addi a2, a2, 241
1983 ; RV64I-NEXT: slli a2, a2, 12
1984 ; RV64I-NEXT: addi a2, a2, -241
1985 ; RV64I-NEXT: and a0, a0, a2
1986 ; RV64I-NEXT: or a0, a1, a0
1989 ; RV64B-LABEL: grev7_i64:
1991 ; RV64B-NEXT: rev.b a0, a0
1994 ; RV64ZBP-LABEL: grev7_i64:
1996 ; RV64ZBP-NEXT: rev.b a0, a0
1998 %and1 = shl i64 %a, 1
1999 %shl1 = and i64 %and1, -6148914691236517206
2000 %and1b = lshr i64 %a, 1
2001 %shr1 = and i64 %and1b, 6148914691236517205
2002 %or1 = or i64 %shl1, %shr1
2003 %and2 = shl i64 %or1, 2
2004 %shl2 = and i64 %and2, -3689348814741910324
2005 %and2b = lshr i64 %or1, 2
2006 %shr2 = and i64 %and2b, 3689348814741910323
2007 %or2 = or i64 %shl2, %shr2
2008 %and3 = shl i64 %or2, 4
2009 %shl3 = and i64 %and3, -1085102592571150096
2010 %and3b = lshr i64 %or2, 4
2011 %shr3 = and i64 %and3b, 1085102592571150095
2012 %or3 = or i64 %shl3, %shr3
2016 define signext i32 @grev8_i32(i32 signext %a) nounwind {
2017 ; RV64I-LABEL: grev8_i32:
2019 ; RV64I-NEXT: slli a1, a0, 8
2020 ; RV64I-NEXT: lui a2, 1044496
2021 ; RV64I-NEXT: addiw a2, a2, -256
2022 ; RV64I-NEXT: and a1, a1, a2
2023 ; RV64I-NEXT: srli a0, a0, 8
2024 ; RV64I-NEXT: lui a2, 4080
2025 ; RV64I-NEXT: addiw a2, a2, 255
2026 ; RV64I-NEXT: and a0, a0, a2
2027 ; RV64I-NEXT: or a0, a1, a0
2028 ; RV64I-NEXT: sext.w a0, a0
2031 ; RV64B-LABEL: grev8_i32:
2033 ; RV64B-NEXT: greviw a0, a0, 8
2036 ; RV64ZBP-LABEL: grev8_i32:
2038 ; RV64ZBP-NEXT: greviw a0, a0, 8
2040 %and = shl i32 %a, 8
2041 %shl = and i32 %and, -16711936
2042 %and1 = lshr i32 %a, 8
2043 %shr = and i32 %and1, 16711935
2044 %or = or i32 %shl, %shr
2048 define i64 @grev8_i64(i64 %a) nounwind {
2049 ; RV64I-LABEL: grev8_i64:
2051 ; RV64I-NEXT: slli a1, a0, 8
2052 ; RV64I-NEXT: lui a2, 1044496
2053 ; RV64I-NEXT: addiw a2, a2, -255
2054 ; RV64I-NEXT: slli a2, a2, 16
2055 ; RV64I-NEXT: addi a2, a2, -255
2056 ; RV64I-NEXT: slli a2, a2, 16
2057 ; RV64I-NEXT: addi a2, a2, -256
2058 ; RV64I-NEXT: and a1, a1, a2
2059 ; RV64I-NEXT: srli a0, a0, 8
2060 ; RV64I-NEXT: lui a2, 4080
2061 ; RV64I-NEXT: addiw a2, a2, 255
2062 ; RV64I-NEXT: slli a2, a2, 16
2063 ; RV64I-NEXT: addi a2, a2, 255
2064 ; RV64I-NEXT: slli a2, a2, 16
2065 ; RV64I-NEXT: addi a2, a2, 255
2066 ; RV64I-NEXT: and a0, a0, a2
2067 ; RV64I-NEXT: or a0, a1, a0
2070 ; RV64B-LABEL: grev8_i64:
2072 ; RV64B-NEXT: rev8.h a0, a0
2075 ; RV64ZBP-LABEL: grev8_i64:
2077 ; RV64ZBP-NEXT: rev8.h a0, a0
2079 %and = shl i64 %a, 8
2080 %shl = and i64 %and, -71777214294589696
2081 %and1 = lshr i64 %a, 8
2082 %shr = and i64 %and1, 71777214294589695
2083 %or = or i64 %shl, %shr
2087 define signext i32 @grev16_i32(i32 signext %a) nounwind {
2088 ; RV64I-LABEL: grev16_i32:
2090 ; RV64I-NEXT: slli a1, a0, 16
2091 ; RV64I-NEXT: srliw a0, a0, 16
2092 ; RV64I-NEXT: or a0, a1, a0
2093 ; RV64I-NEXT: sext.w a0, a0
2096 ; RV64B-LABEL: grev16_i32:
2098 ; RV64B-NEXT: greviw a0, a0, 16
2101 ; RV64ZBP-LABEL: grev16_i32:
2103 ; RV64ZBP-NEXT: greviw a0, a0, 16
2105 %shl = shl i32 %a, 16
2106 %shr = lshr i32 %a, 16
2107 %or = or i32 %shl, %shr
2111 declare i32 @llvm.fshl.i32(i32, i32, i32)
2112 declare i32 @llvm.fshr.i32(i32, i32, i32)
2114 define signext i32 @grev16_i32_fshl(i32 signext %a) nounwind {
2115 ; RV64I-LABEL: grev16_i32_fshl:
2117 ; RV64I-NEXT: srliw a1, a0, 16
2118 ; RV64I-NEXT: slli a0, a0, 16
2119 ; RV64I-NEXT: or a0, a0, a1
2120 ; RV64I-NEXT: sext.w a0, a0
2123 ; RV64B-LABEL: grev16_i32_fshl:
2125 ; RV64B-NEXT: roriw a0, a0, 16
2128 ; RV64ZBP-LABEL: grev16_i32_fshl:
2130 ; RV64ZBP-NEXT: roriw a0, a0, 16
2132 %or = tail call i32 @llvm.fshl.i32(i32 %a, i32 %a, i32 16)
2136 define signext i32 @grev16_i32_fshr(i32 signext %a) nounwind {
2137 ; RV64I-LABEL: grev16_i32_fshr:
2139 ; RV64I-NEXT: slli a1, a0, 16
2140 ; RV64I-NEXT: srliw a0, a0, 16
2141 ; RV64I-NEXT: or a0, a0, a1
2142 ; RV64I-NEXT: sext.w a0, a0
2145 ; RV64B-LABEL: grev16_i32_fshr:
2147 ; RV64B-NEXT: roriw a0, a0, 16
2150 ; RV64ZBP-LABEL: grev16_i32_fshr:
2152 ; RV64ZBP-NEXT: roriw a0, a0, 16
2154 %or = tail call i32 @llvm.fshr.i32(i32 %a, i32 %a, i32 16)
2158 define i64 @grev16_i64(i64 %a) nounwind {
2159 ; RV64I-LABEL: grev16_i64:
2161 ; RV64I-NEXT: slli a1, a0, 16
2162 ; RV64I-NEXT: lui a2, 983041
2163 ; RV64I-NEXT: slli a3, a2, 4
2164 ; RV64I-NEXT: addi a3, a3, -1
2165 ; RV64I-NEXT: slli a3, a3, 16
2166 ; RV64I-NEXT: and a1, a1, a3
2167 ; RV64I-NEXT: srli a0, a0, 16
2168 ; RV64I-NEXT: slli a2, a2, 20
2169 ; RV64I-NEXT: addi a2, a2, -1
2170 ; RV64I-NEXT: srli a2, a2, 16
2171 ; RV64I-NEXT: and a0, a0, a2
2172 ; RV64I-NEXT: or a0, a1, a0
2175 ; RV64B-LABEL: grev16_i64:
2177 ; RV64B-NEXT: rev16.w a0, a0
2180 ; RV64ZBP-LABEL: grev16_i64:
2182 ; RV64ZBP-NEXT: rev16.w a0, a0
2184 %and = shl i64 %a, 16
2185 %shl = and i64 %and, -281470681808896
2186 %and1 = lshr i64 %a, 16
2187 %shr = and i64 %and1, 281470681808895
2188 %or = or i64 %shl, %shr
2192 define i64 @grev32(i64 %a) nounwind {
2193 ; RV64I-LABEL: grev32:
2195 ; RV64I-NEXT: slli a1, a0, 32
2196 ; RV64I-NEXT: srli a0, a0, 32
2197 ; RV64I-NEXT: or a0, a1, a0
2200 ; RV64B-LABEL: grev32:
2202 ; RV64B-NEXT: rori a0, a0, 32
2205 ; RV64ZBP-LABEL: grev32:
2207 ; RV64ZBP-NEXT: rori a0, a0, 32
2209 %shl = shl i64 %a, 32
2210 %shr = lshr i64 %a, 32
2211 %or = or i64 %shl, %shr
2215 define signext i32 @grev3b_i32(i32 signext %a) nounwind {
2216 ; RV64I-LABEL: grev3b_i32:
2218 ; RV64I-NEXT: slli a1, a0, 2
2219 ; RV64I-NEXT: lui a2, 838861
2220 ; RV64I-NEXT: addiw a2, a2, -820
2221 ; RV64I-NEXT: and a1, a1, a2
2222 ; RV64I-NEXT: srli a0, a0, 2
2223 ; RV64I-NEXT: lui a2, 209715
2224 ; RV64I-NEXT: addiw a2, a2, 819
2225 ; RV64I-NEXT: and a0, a0, a2
2226 ; RV64I-NEXT: or a0, a1, a0
2227 ; RV64I-NEXT: slli a1, a0, 1
2228 ; RV64I-NEXT: lui a2, 699051
2229 ; RV64I-NEXT: addiw a2, a2, -1366
2230 ; RV64I-NEXT: and a1, a1, a2
2231 ; RV64I-NEXT: srli a0, a0, 1
2232 ; RV64I-NEXT: lui a2, 349525
2233 ; RV64I-NEXT: addiw a2, a2, 1365
2234 ; RV64I-NEXT: and a0, a0, a2
2235 ; RV64I-NEXT: or a0, a1, a0
2236 ; RV64I-NEXT: sext.w a0, a0
2239 ; RV64B-LABEL: grev3b_i32:
2241 ; RV64B-NEXT: greviw a0, a0, 3
2244 ; RV64ZBP-LABEL: grev3b_i32:
2246 ; RV64ZBP-NEXT: greviw a0, a0, 3
2248 %and2 = shl i32 %a, 2
2249 %shl2 = and i32 %and2, -858993460
2250 %and2b = lshr i32 %a, 2
2251 %shr2 = and i32 %and2b, 858993459
2252 %or2 = or i32 %shl2, %shr2
2253 %and1 = shl i32 %or2, 1
2254 %shl1 = and i32 %and1, -1431655766
2255 %and1b = lshr i32 %or2, 1
2256 %shr1 = and i32 %and1b, 1431655765
2257 %or1 = or i32 %shl1, %shr1
2261 define i64 @grev3b_i64(i64 %a) nounwind {
2262 ; RV64I-LABEL: grev3b_i64:
2264 ; RV64I-NEXT: slli a1, a0, 2
2265 ; RV64I-NEXT: lui a2, 1035469
2266 ; RV64I-NEXT: addiw a2, a2, -819
2267 ; RV64I-NEXT: slli a2, a2, 12
2268 ; RV64I-NEXT: addi a2, a2, -819
2269 ; RV64I-NEXT: slli a2, a2, 12
2270 ; RV64I-NEXT: addi a2, a2, -819
2271 ; RV64I-NEXT: slli a2, a2, 12
2272 ; RV64I-NEXT: addi a2, a2, -820
2273 ; RV64I-NEXT: and a1, a1, a2
2274 ; RV64I-NEXT: srli a0, a0, 2
2275 ; RV64I-NEXT: lui a2, 13107
2276 ; RV64I-NEXT: addiw a2, a2, 819
2277 ; RV64I-NEXT: slli a2, a2, 12
2278 ; RV64I-NEXT: addi a2, a2, 819
2279 ; RV64I-NEXT: slli a2, a2, 12
2280 ; RV64I-NEXT: addi a2, a2, 819
2281 ; RV64I-NEXT: slli a2, a2, 12
2282 ; RV64I-NEXT: addi a2, a2, 819
2283 ; RV64I-NEXT: and a0, a0, a2
2284 ; RV64I-NEXT: or a0, a1, a0
2285 ; RV64I-NEXT: slli a1, a0, 1
2286 ; RV64I-NEXT: lui a2, 1026731
2287 ; RV64I-NEXT: addiw a2, a2, -1365
2288 ; RV64I-NEXT: slli a2, a2, 12
2289 ; RV64I-NEXT: addi a2, a2, -1365
2290 ; RV64I-NEXT: slli a2, a2, 12
2291 ; RV64I-NEXT: addi a2, a2, -1365
2292 ; RV64I-NEXT: slli a2, a2, 12
2293 ; RV64I-NEXT: addi a2, a2, -1366
2294 ; RV64I-NEXT: and a1, a1, a2
2295 ; RV64I-NEXT: srli a0, a0, 1
2296 ; RV64I-NEXT: lui a2, 21845
2297 ; RV64I-NEXT: addiw a2, a2, 1365
2298 ; RV64I-NEXT: slli a2, a2, 12
2299 ; RV64I-NEXT: addi a2, a2, 1365
2300 ; RV64I-NEXT: slli a2, a2, 12
2301 ; RV64I-NEXT: addi a2, a2, 1365
2302 ; RV64I-NEXT: slli a2, a2, 12
2303 ; RV64I-NEXT: addi a2, a2, 1365
2304 ; RV64I-NEXT: and a0, a0, a2
2305 ; RV64I-NEXT: or a0, a1, a0
2308 ; RV64B-LABEL: grev3b_i64:
2310 ; RV64B-NEXT: rev.n a0, a0
2313 ; RV64ZBP-LABEL: grev3b_i64:
2315 ; RV64ZBP-NEXT: rev.n a0, a0
2317 %and2 = shl i64 %a, 2
2318 %shl2 = and i64 %and2, -3689348814741910324
2319 %and2b = lshr i64 %a, 2
2320 %shr2 = and i64 %and2b, 3689348814741910323
2321 %or2 = or i64 %shl2, %shr2
2322 %and1 = shl i64 %or2, 1
2323 %shl1 = and i64 %and1, -6148914691236517206
2324 %and1b = lshr i64 %or2, 1
2325 %shr1 = and i64 %and1b, 6148914691236517205
2326 %or1 = or i64 %shl1, %shr1
2330 ; grev1, grev2, grev1 -> grev2
2331 define signext i32 @grev2b_i32(i32 signext %a) nounwind {
2332 ; RV64I-LABEL: grev2b_i32:
2334 ; RV64I-NEXT: slli a1, a0, 1
2335 ; RV64I-NEXT: lui a2, 699051
2336 ; RV64I-NEXT: addiw a2, a2, -1366
2337 ; RV64I-NEXT: and a1, a1, a2
2338 ; RV64I-NEXT: srli a0, a0, 1
2339 ; RV64I-NEXT: lui a3, 349525
2340 ; RV64I-NEXT: addiw a3, a3, 1365
2341 ; RV64I-NEXT: and a0, a0, a3
2342 ; RV64I-NEXT: or a0, a1, a0
2343 ; RV64I-NEXT: slli a1, a0, 2
2344 ; RV64I-NEXT: lui a4, 838861
2345 ; RV64I-NEXT: addiw a4, a4, -820
2346 ; RV64I-NEXT: and a1, a1, a4
2347 ; RV64I-NEXT: srli a0, a0, 2
2348 ; RV64I-NEXT: lui a4, 209715
2349 ; RV64I-NEXT: addiw a4, a4, 819
2350 ; RV64I-NEXT: and a0, a0, a4
2351 ; RV64I-NEXT: or a0, a1, a0
2352 ; RV64I-NEXT: slli a1, a0, 1
2353 ; RV64I-NEXT: and a1, a1, a2
2354 ; RV64I-NEXT: srli a0, a0, 1
2355 ; RV64I-NEXT: and a0, a0, a3
2356 ; RV64I-NEXT: or a0, a1, a0
2357 ; RV64I-NEXT: sext.w a0, a0
2360 ; RV64B-LABEL: grev2b_i32:
2362 ; RV64B-NEXT: greviw a0, a0, 2
2365 ; RV64ZBP-LABEL: grev2b_i32:
2367 ; RV64ZBP-NEXT: greviw a0, a0, 2
2369 %and1 = shl i32 %a, 1
2370 %shl1 = and i32 %and1, -1431655766
2371 %and1b = lshr i32 %a, 1
2372 %shr1 = and i32 %and1b, 1431655765
2373 %or1 = or i32 %shl1, %shr1
2374 %and2 = shl i32 %or1, 2
2375 %shl2 = and i32 %and2, -858993460
2376 %and2b = lshr i32 %or1, 2
2377 %shr2 = and i32 %and2b, 858993459
2378 %or2 = or i32 %shl2, %shr2
2379 %and3 = shl i32 %or2, 1
2380 %shl3 = and i32 %and3, -1431655766
2381 %and3b = lshr i32 %or2, 1
2382 %shr3 = and i32 %and3b, 1431655765
2383 %or3 = or i32 %shl3, %shr3
2387 ; grev1, grev2, grev1 -> grev2
2388 define i64 @grev2b_i64(i64 %a) nounwind {
2389 ; RV64I-LABEL: grev2b_i64:
2391 ; RV64I-NEXT: slli a1, a0, 1
2392 ; RV64I-NEXT: lui a2, 1026731
2393 ; RV64I-NEXT: addiw a2, a2, -1365
2394 ; RV64I-NEXT: slli a2, a2, 12
2395 ; RV64I-NEXT: addi a2, a2, -1365
2396 ; RV64I-NEXT: slli a2, a2, 12
2397 ; RV64I-NEXT: addi a2, a2, -1365
2398 ; RV64I-NEXT: slli a2, a2, 12
2399 ; RV64I-NEXT: addi a2, a2, -1366
2400 ; RV64I-NEXT: and a1, a1, a2
2401 ; RV64I-NEXT: srli a0, a0, 1
2402 ; RV64I-NEXT: lui a3, 21845
2403 ; RV64I-NEXT: addiw a3, a3, 1365
2404 ; RV64I-NEXT: slli a3, a3, 12
2405 ; RV64I-NEXT: addi a3, a3, 1365
2406 ; RV64I-NEXT: slli a3, a3, 12
2407 ; RV64I-NEXT: addi a3, a3, 1365
2408 ; RV64I-NEXT: slli a3, a3, 12
2409 ; RV64I-NEXT: addi a3, a3, 1365
2410 ; RV64I-NEXT: and a0, a0, a3
2411 ; RV64I-NEXT: or a0, a1, a0
2412 ; RV64I-NEXT: slli a1, a0, 2
2413 ; RV64I-NEXT: lui a4, 1035469
2414 ; RV64I-NEXT: addiw a4, a4, -819
2415 ; RV64I-NEXT: slli a4, a4, 12
2416 ; RV64I-NEXT: addi a4, a4, -819
2417 ; RV64I-NEXT: slli a4, a4, 12
2418 ; RV64I-NEXT: addi a4, a4, -819
2419 ; RV64I-NEXT: slli a4, a4, 12
2420 ; RV64I-NEXT: addi a4, a4, -820
2421 ; RV64I-NEXT: and a1, a1, a4
2422 ; RV64I-NEXT: srli a0, a0, 2
2423 ; RV64I-NEXT: lui a4, 13107
2424 ; RV64I-NEXT: addiw a4, a4, 819
2425 ; RV64I-NEXT: slli a4, a4, 12
2426 ; RV64I-NEXT: addi a4, a4, 819
2427 ; RV64I-NEXT: slli a4, a4, 12
2428 ; RV64I-NEXT: addi a4, a4, 819
2429 ; RV64I-NEXT: slli a4, a4, 12
2430 ; RV64I-NEXT: addi a4, a4, 819
2431 ; RV64I-NEXT: and a0, a0, a4
2432 ; RV64I-NEXT: or a0, a1, a0
2433 ; RV64I-NEXT: slli a1, a0, 1
2434 ; RV64I-NEXT: and a1, a1, a2
2435 ; RV64I-NEXT: srli a0, a0, 1
2436 ; RV64I-NEXT: and a0, a0, a3
2437 ; RV64I-NEXT: or a0, a1, a0
2440 ; RV64B-LABEL: grev2b_i64:
2442 ; RV64B-NEXT: rev2.n a0, a0
2445 ; RV64ZBP-LABEL: grev2b_i64:
2447 ; RV64ZBP-NEXT: rev2.n a0, a0
2449 %and1 = shl i64 %a, 1
2450 %shl1 = and i64 %and1, -6148914691236517206
2451 %and1b = lshr i64 %a, 1
2452 %shr1 = and i64 %and1b, 6148914691236517205
2453 %or1 = or i64 %shl1, %shr1
2454 %and2 = shl i64 %or1, 2
2455 %shl2 = and i64 %and2, -3689348814741910324
2456 %and2b = lshr i64 %or1, 2
2457 %shr2 = and i64 %and2b, 3689348814741910323
2458 %or2 = or i64 %shl2, %shr2
2459 %and3 = shl i64 %or2, 1
2460 %shl3 = and i64 %and3, -6148914691236517206
2461 %and3b = lshr i64 %or2, 1
2462 %shr3 = and i64 %and3b, 6148914691236517205
2463 %or3 = or i64 %shl3, %shr3
2467 ; grev1, grev2, grev1, grev2 -> identity
2468 define signext i32 @grev0_i32(i32 signext %a) nounwind {
2469 ; RV64I-LABEL: grev0_i32:
2471 ; RV64I-NEXT: slli a1, a0, 1
2472 ; RV64I-NEXT: lui a2, 699051
2473 ; RV64I-NEXT: addiw a2, a2, -1366
2474 ; RV64I-NEXT: and a1, a1, a2
2475 ; RV64I-NEXT: srli a0, a0, 1
2476 ; RV64I-NEXT: lui a3, 349525
2477 ; RV64I-NEXT: addiw a3, a3, 1365
2478 ; RV64I-NEXT: and a0, a0, a3
2479 ; RV64I-NEXT: or a0, a1, a0
2480 ; RV64I-NEXT: slli a1, a0, 2
2481 ; RV64I-NEXT: lui a4, 838861
2482 ; RV64I-NEXT: addiw a4, a4, -820
2483 ; RV64I-NEXT: and a1, a1, a4
2484 ; RV64I-NEXT: srli a0, a0, 2
2485 ; RV64I-NEXT: lui a5, 209715
2486 ; RV64I-NEXT: addiw a5, a5, 819
2487 ; RV64I-NEXT: and a0, a0, a5
2488 ; RV64I-NEXT: or a0, a1, a0
2489 ; RV64I-NEXT: slli a1, a0, 1
2490 ; RV64I-NEXT: and a1, a1, a2
2491 ; RV64I-NEXT: srli a0, a0, 1
2492 ; RV64I-NEXT: and a0, a0, a3
2493 ; RV64I-NEXT: or a0, a1, a0
2494 ; RV64I-NEXT: slli a1, a0, 2
2495 ; RV64I-NEXT: and a1, a1, a4
2496 ; RV64I-NEXT: srli a0, a0, 2
2497 ; RV64I-NEXT: and a0, a0, a5
2498 ; RV64I-NEXT: or a0, a1, a0
2499 ; RV64I-NEXT: sext.w a0, a0
2502 ; RV64B-LABEL: grev0_i32:
2506 ; RV64ZBP-LABEL: grev0_i32:
2509 %and1 = shl i32 %a, 1
2510 %shl1 = and i32 %and1, -1431655766
2511 %and1b = lshr i32 %a, 1
2512 %shr1 = and i32 %and1b, 1431655765
2513 %or1 = or i32 %shl1, %shr1
2514 %and2 = shl i32 %or1, 2
2515 %shl2 = and i32 %and2, -858993460
2516 %and2b = lshr i32 %or1, 2
2517 %shr2 = and i32 %and2b, 858993459
2518 %or2 = or i32 %shl2, %shr2
2519 %and3 = shl i32 %or2, 1
2520 %shl3 = and i32 %and3, -1431655766
2521 %and3b = lshr i32 %or2, 1
2522 %shr3 = and i32 %and3b, 1431655765
2523 %or3 = or i32 %shl3, %shr3
2524 %and4 = shl i32 %or3, 2
2525 %shl4 = and i32 %and4, -858993460
2526 %and4b = lshr i32 %or3, 2
2527 %shr4 = and i32 %and4b, 858993459
2528 %or4 = or i32 %shl4, %shr4
2532 ; grev1, grev2, grev1, grev2 -> identity
2533 define i64 @grev0_i64(i64 %a) nounwind {
2534 ; RV64I-LABEL: grev0_i64:
2536 ; RV64I-NEXT: slli a1, a0, 1
2537 ; RV64I-NEXT: lui a2, 1026731
2538 ; RV64I-NEXT: addiw a2, a2, -1365
2539 ; RV64I-NEXT: slli a2, a2, 12
2540 ; RV64I-NEXT: addi a2, a2, -1365
2541 ; RV64I-NEXT: slli a2, a2, 12
2542 ; RV64I-NEXT: addi a2, a2, -1365
2543 ; RV64I-NEXT: slli a2, a2, 12
2544 ; RV64I-NEXT: addi a2, a2, -1366
2545 ; RV64I-NEXT: and a1, a1, a2
2546 ; RV64I-NEXT: srli a0, a0, 1
2547 ; RV64I-NEXT: lui a3, 21845
2548 ; RV64I-NEXT: addiw a3, a3, 1365
2549 ; RV64I-NEXT: slli a3, a3, 12
2550 ; RV64I-NEXT: addi a3, a3, 1365
2551 ; RV64I-NEXT: slli a3, a3, 12
2552 ; RV64I-NEXT: addi a3, a3, 1365
2553 ; RV64I-NEXT: slli a3, a3, 12
2554 ; RV64I-NEXT: addi a3, a3, 1365
2555 ; RV64I-NEXT: and a0, a0, a3
2556 ; RV64I-NEXT: or a0, a1, a0
2557 ; RV64I-NEXT: slli a1, a0, 2
2558 ; RV64I-NEXT: lui a4, 1035469
2559 ; RV64I-NEXT: addiw a4, a4, -819
2560 ; RV64I-NEXT: slli a4, a4, 12
2561 ; RV64I-NEXT: addi a4, a4, -819
2562 ; RV64I-NEXT: slli a4, a4, 12
2563 ; RV64I-NEXT: addi a4, a4, -819
2564 ; RV64I-NEXT: slli a4, a4, 12
2565 ; RV64I-NEXT: addi a4, a4, -820
2566 ; RV64I-NEXT: and a1, a1, a4
2567 ; RV64I-NEXT: srli a0, a0, 2
2568 ; RV64I-NEXT: lui a5, 13107
2569 ; RV64I-NEXT: addiw a5, a5, 819
2570 ; RV64I-NEXT: slli a5, a5, 12
2571 ; RV64I-NEXT: addi a5, a5, 819
2572 ; RV64I-NEXT: slli a5, a5, 12
2573 ; RV64I-NEXT: addi a5, a5, 819
2574 ; RV64I-NEXT: slli a5, a5, 12
2575 ; RV64I-NEXT: addi a5, a5, 819
2576 ; RV64I-NEXT: and a0, a0, a5
2577 ; RV64I-NEXT: or a0, a1, a0
2578 ; RV64I-NEXT: slli a1, a0, 1
2579 ; RV64I-NEXT: and a1, a1, a2
2580 ; RV64I-NEXT: srli a0, a0, 1
2581 ; RV64I-NEXT: and a0, a0, a3
2582 ; RV64I-NEXT: or a0, a1, a0
2583 ; RV64I-NEXT: slli a1, a0, 2
2584 ; RV64I-NEXT: and a1, a1, a4
2585 ; RV64I-NEXT: srli a0, a0, 2
2586 ; RV64I-NEXT: and a0, a0, a5
2587 ; RV64I-NEXT: or a0, a1, a0
2590 ; RV64B-LABEL: grev0_i64:
2594 ; RV64ZBP-LABEL: grev0_i64:
2597 %and1 = shl i64 %a, 1
2598 %shl1 = and i64 %and1, -6148914691236517206
2599 %and1b = lshr i64 %a, 1
2600 %shr1 = and i64 %and1b, 6148914691236517205
2601 %or1 = or i64 %shl1, %shr1
2602 %and2 = shl i64 %or1, 2
2603 %shl2 = and i64 %and2, -3689348814741910324
2604 %and2b = lshr i64 %or1, 2
2605 %shr2 = and i64 %and2b, 3689348814741910323
2606 %or2 = or i64 %shl2, %shr2
2607 %and3 = shl i64 %or2, 1
2608 %shl3 = and i64 %and3, -6148914691236517206
2609 %and3b = lshr i64 %or2, 1
2610 %shr3 = and i64 %and3b, 6148914691236517205
2611 %or3 = or i64 %shl3, %shr3
2612 %and4 = shl i64 %or3, 2
2613 %shl4 = and i64 %and4, -3689348814741910324
2614 %and4b = lshr i64 %or3, 2
2615 %shr4 = and i64 %and4b, 3689348814741910323
2616 %or4 = or i64 %shl4, %shr4
2620 declare i64 @llvm.fshl.i64(i64, i64, i64)
2621 declare i64 @llvm.fshr.i64(i64, i64, i64)
2623 define i64 @grev32_fshl(i64 %a) nounwind {
2624 ; RV64I-LABEL: grev32_fshl:
2626 ; RV64I-NEXT: srli a1, a0, 32
2627 ; RV64I-NEXT: slli a0, a0, 32
2628 ; RV64I-NEXT: or a0, a0, a1
2631 ; RV64B-LABEL: grev32_fshl:
2633 ; RV64B-NEXT: rori a0, a0, 32
2636 ; RV64ZBP-LABEL: grev32_fshl:
2638 ; RV64ZBP-NEXT: rori a0, a0, 32
2640 %or = tail call i64 @llvm.fshl.i64(i64 %a, i64 %a, i64 32)
2644 define i64 @grev32_fshr(i64 %a) nounwind {
2645 ; RV64I-LABEL: grev32_fshr:
2647 ; RV64I-NEXT: slli a1, a0, 32
2648 ; RV64I-NEXT: srli a0, a0, 32
2649 ; RV64I-NEXT: or a0, a0, a1
2652 ; RV64B-LABEL: grev32_fshr:
2654 ; RV64B-NEXT: rori a0, a0, 32
2657 ; RV64ZBP-LABEL: grev32_fshr:
2659 ; RV64ZBP-NEXT: rori a0, a0, 32
2661 %or = tail call i64 @llvm.fshr.i64(i64 %a, i64 %a, i64 32)
2665 declare i16 @llvm.bswap.i16(i16)
2667 define zeroext i16 @bswap_i16(i16 zeroext %a) nounwind {
2668 ; RV64I-LABEL: bswap_i16:
2670 ; RV64I-NEXT: srli a1, a0, 8
2671 ; RV64I-NEXT: slli a0, a0, 8
2672 ; RV64I-NEXT: or a0, a0, a1
2673 ; RV64I-NEXT: lui a1, 16
2674 ; RV64I-NEXT: addiw a1, a1, -1
2675 ; RV64I-NEXT: and a0, a0, a1
2678 ; RV64B-LABEL: bswap_i16:
2680 ; RV64B-NEXT: greviw a0, a0, 8
2683 ; RV64ZBP-LABEL: bswap_i16:
2685 ; RV64ZBP-NEXT: greviw a0, a0, 8
2687 %1 = tail call i16 @llvm.bswap.i16(i16 %a)
2691 declare i32 @llvm.bswap.i32(i32)
2693 define signext i32 @bswap_i32(i32 signext %a) nounwind {
2694 ; RV64I-LABEL: bswap_i32:
2696 ; RV64I-NEXT: srliw a1, a0, 8
2697 ; RV64I-NEXT: lui a2, 16
2698 ; RV64I-NEXT: addiw a2, a2, -256
2699 ; RV64I-NEXT: and a1, a1, a2
2700 ; RV64I-NEXT: srliw a2, a0, 24
2701 ; RV64I-NEXT: or a1, a1, a2
2702 ; RV64I-NEXT: slli a2, a0, 8
2703 ; RV64I-NEXT: lui a3, 4080
2704 ; RV64I-NEXT: and a2, a2, a3
2705 ; RV64I-NEXT: slli a0, a0, 24
2706 ; RV64I-NEXT: or a0, a0, a2
2707 ; RV64I-NEXT: or a0, a0, a1
2708 ; RV64I-NEXT: sext.w a0, a0
2711 ; RV64B-LABEL: bswap_i32:
2713 ; RV64B-NEXT: greviw a0, a0, 24
2716 ; RV64ZBP-LABEL: bswap_i32:
2718 ; RV64ZBP-NEXT: greviw a0, a0, 24
2720 %1 = tail call i32 @llvm.bswap.i32(i32 %a)
2724 ; Similar to bswap_i32 but the result is not sign extended.
2725 define void @bswap_i32_nosext(i32 signext %a, i32* %x) nounwind {
2726 ; RV64I-LABEL: bswap_i32_nosext:
2728 ; RV64I-NEXT: srliw a2, a0, 8
2729 ; RV64I-NEXT: lui a3, 16
2730 ; RV64I-NEXT: addiw a3, a3, -256
2731 ; RV64I-NEXT: and a2, a2, a3
2732 ; RV64I-NEXT: srliw a3, a0, 24
2733 ; RV64I-NEXT: or a2, a2, a3
2734 ; RV64I-NEXT: slli a3, a0, 8
2735 ; RV64I-NEXT: lui a4, 4080
2736 ; RV64I-NEXT: and a3, a3, a4
2737 ; RV64I-NEXT: slli a0, a0, 24
2738 ; RV64I-NEXT: or a0, a0, a3
2739 ; RV64I-NEXT: or a0, a0, a2
2740 ; RV64I-NEXT: sw a0, 0(a1)
2743 ; RV64B-LABEL: bswap_i32_nosext:
2745 ; RV64B-NEXT: greviw a0, a0, 24
2746 ; RV64B-NEXT: sw a0, 0(a1)
2749 ; RV64ZBP-LABEL: bswap_i32_nosext:
2751 ; RV64ZBP-NEXT: greviw a0, a0, 24
2752 ; RV64ZBP-NEXT: sw a0, 0(a1)
2754 %1 = tail call i32 @llvm.bswap.i32(i32 %a)
2755 store i32 %1, i32* %x
2759 declare i64 @llvm.bswap.i64(i64)
2761 define i64 @bswap_i64(i64 %a) {
2762 ; RV64I-LABEL: bswap_i64:
2764 ; RV64I-NEXT: srli a1, a0, 24
2765 ; RV64I-NEXT: lui a2, 4080
2766 ; RV64I-NEXT: and a1, a1, a2
2767 ; RV64I-NEXT: srli a2, a0, 8
2768 ; RV64I-NEXT: addi a3, zero, 255
2769 ; RV64I-NEXT: slli a4, a3, 24
2770 ; RV64I-NEXT: and a2, a2, a4
2771 ; RV64I-NEXT: or a1, a2, a1
2772 ; RV64I-NEXT: srli a2, a0, 40
2773 ; RV64I-NEXT: lui a4, 16
2774 ; RV64I-NEXT: addiw a4, a4, -256
2775 ; RV64I-NEXT: and a2, a2, a4
2776 ; RV64I-NEXT: srli a4, a0, 56
2777 ; RV64I-NEXT: or a2, a2, a4
2778 ; RV64I-NEXT: or a1, a1, a2
2779 ; RV64I-NEXT: slli a2, a0, 8
2780 ; RV64I-NEXT: slli a4, a3, 32
2781 ; RV64I-NEXT: and a2, a2, a4
2782 ; RV64I-NEXT: slli a4, a0, 24
2783 ; RV64I-NEXT: slli a5, a3, 40
2784 ; RV64I-NEXT: and a4, a4, a5
2785 ; RV64I-NEXT: or a2, a4, a2
2786 ; RV64I-NEXT: slli a4, a0, 40
2787 ; RV64I-NEXT: slli a3, a3, 48
2788 ; RV64I-NEXT: and a3, a4, a3
2789 ; RV64I-NEXT: slli a0, a0, 56
2790 ; RV64I-NEXT: or a0, a0, a3
2791 ; RV64I-NEXT: or a0, a0, a2
2792 ; RV64I-NEXT: or a0, a0, a1
2795 ; RV64B-LABEL: bswap_i64:
2797 ; RV64B-NEXT: rev8 a0, a0
2800 ; RV64ZBP-LABEL: bswap_i64:
2802 ; RV64ZBP-NEXT: rev8 a0, a0
2804 %1 = call i64 @llvm.bswap.i64(i64 %a)
2808 declare i8 @llvm.bitreverse.i8(i8)
2810 define zeroext i8 @bitreverse_i8(i8 zeroext %a) nounwind {
2811 ; RV64I-LABEL: bitreverse_i8:
2813 ; RV64I-NEXT: srli a1, a0, 4
2814 ; RV64I-NEXT: andi a0, a0, 15
2815 ; RV64I-NEXT: slli a0, a0, 4
2816 ; RV64I-NEXT: or a0, a1, a0
2817 ; RV64I-NEXT: andi a1, a0, 51
2818 ; RV64I-NEXT: slli a1, a1, 2
2819 ; RV64I-NEXT: andi a0, a0, 204
2820 ; RV64I-NEXT: srli a0, a0, 2
2821 ; RV64I-NEXT: or a0, a0, a1
2822 ; RV64I-NEXT: andi a1, a0, 85
2823 ; RV64I-NEXT: slli a1, a1, 1
2824 ; RV64I-NEXT: andi a0, a0, 170
2825 ; RV64I-NEXT: srli a0, a0, 1
2826 ; RV64I-NEXT: or a0, a0, a1
2829 ; RV64B-LABEL: bitreverse_i8:
2831 ; RV64B-NEXT: greviw a0, a0, 7
2834 ; RV64ZBP-LABEL: bitreverse_i8:
2836 ; RV64ZBP-NEXT: greviw a0, a0, 7
2838 %1 = tail call i8 @llvm.bitreverse.i8(i8 %a)
2842 declare i16 @llvm.bitreverse.i16(i16)
2844 define zeroext i16 @bitreverse_i16(i16 zeroext %a) nounwind {
2845 ; RV64I-LABEL: bitreverse_i16:
2847 ; RV64I-NEXT: srli a1, a0, 8
2848 ; RV64I-NEXT: slli a0, a0, 8
2849 ; RV64I-NEXT: or a0, a0, a1
2850 ; RV64I-NEXT: lui a1, 1
2851 ; RV64I-NEXT: addiw a1, a1, -241
2852 ; RV64I-NEXT: and a1, a0, a1
2853 ; RV64I-NEXT: slli a1, a1, 4
2854 ; RV64I-NEXT: lui a2, 15
2855 ; RV64I-NEXT: addiw a2, a2, 240
2856 ; RV64I-NEXT: and a0, a0, a2
2857 ; RV64I-NEXT: srli a0, a0, 4
2858 ; RV64I-NEXT: or a0, a0, a1
2859 ; RV64I-NEXT: lui a1, 3
2860 ; RV64I-NEXT: addiw a1, a1, 819
2861 ; RV64I-NEXT: and a1, a0, a1
2862 ; RV64I-NEXT: slli a1, a1, 2
2863 ; RV64I-NEXT: lui a2, 13
2864 ; RV64I-NEXT: addiw a2, a2, -820
2865 ; RV64I-NEXT: and a0, a0, a2
2866 ; RV64I-NEXT: srli a0, a0, 2
2867 ; RV64I-NEXT: or a0, a0, a1
2868 ; RV64I-NEXT: lui a1, 5
2869 ; RV64I-NEXT: addiw a1, a1, 1365
2870 ; RV64I-NEXT: and a1, a0, a1
2871 ; RV64I-NEXT: slli a1, a1, 1
2872 ; RV64I-NEXT: lui a2, 11
2873 ; RV64I-NEXT: addiw a2, a2, -1366
2874 ; RV64I-NEXT: and a0, a0, a2
2875 ; RV64I-NEXT: srli a0, a0, 1
2876 ; RV64I-NEXT: or a0, a0, a1
2879 ; RV64B-LABEL: bitreverse_i16:
2881 ; RV64B-NEXT: greviw a0, a0, 15
2884 ; RV64ZBP-LABEL: bitreverse_i16:
2886 ; RV64ZBP-NEXT: greviw a0, a0, 15
2888 %1 = tail call i16 @llvm.bitreverse.i16(i16 %a)
2892 declare i32 @llvm.bitreverse.i32(i32)
2894 define signext i32 @bitreverse_i32(i32 signext %a) nounwind {
2895 ; RV64I-LABEL: bitreverse_i32:
2897 ; RV64I-NEXT: srliw a1, a0, 8
2898 ; RV64I-NEXT: lui a2, 16
2899 ; RV64I-NEXT: addiw a2, a2, -256
2900 ; RV64I-NEXT: and a1, a1, a2
2901 ; RV64I-NEXT: srliw a2, a0, 24
2902 ; RV64I-NEXT: or a1, a1, a2
2903 ; RV64I-NEXT: slli a2, a0, 8
2904 ; RV64I-NEXT: lui a3, 4080
2905 ; RV64I-NEXT: and a2, a2, a3
2906 ; RV64I-NEXT: slli a0, a0, 24
2907 ; RV64I-NEXT: or a0, a0, a2
2908 ; RV64I-NEXT: or a0, a0, a1
2909 ; RV64I-NEXT: lui a1, 61681
2910 ; RV64I-NEXT: addiw a1, a1, -241
2911 ; RV64I-NEXT: and a1, a0, a1
2912 ; RV64I-NEXT: slli a1, a1, 4
2913 ; RV64I-NEXT: lui a2, 241
2914 ; RV64I-NEXT: addiw a2, a2, -241
2915 ; RV64I-NEXT: slli a2, a2, 12
2916 ; RV64I-NEXT: addi a2, a2, 240
2917 ; RV64I-NEXT: and a0, a0, a2
2918 ; RV64I-NEXT: srli a0, a0, 4
2919 ; RV64I-NEXT: or a0, a0, a1
2920 ; RV64I-NEXT: lui a1, 209715
2921 ; RV64I-NEXT: addiw a1, a1, 819
2922 ; RV64I-NEXT: and a1, a0, a1
2923 ; RV64I-NEXT: slli a1, a1, 2
2924 ; RV64I-NEXT: lui a2, 838861
2925 ; RV64I-NEXT: addiw a2, a2, -820
2926 ; RV64I-NEXT: and a0, a0, a2
2927 ; RV64I-NEXT: srli a0, a0, 2
2928 ; RV64I-NEXT: or a0, a0, a1
2929 ; RV64I-NEXT: lui a1, 349525
2930 ; RV64I-NEXT: addiw a1, a1, 1365
2931 ; RV64I-NEXT: and a1, a0, a1
2932 ; RV64I-NEXT: slli a1, a1, 1
2933 ; RV64I-NEXT: lui a2, 699051
2934 ; RV64I-NEXT: addiw a2, a2, -1366
2935 ; RV64I-NEXT: and a0, a0, a2
2936 ; RV64I-NEXT: srli a0, a0, 1
2937 ; RV64I-NEXT: or a0, a0, a1
2938 ; RV64I-NEXT: sext.w a0, a0
2941 ; RV64B-LABEL: bitreverse_i32:
2943 ; RV64B-NEXT: greviw a0, a0, 31
2946 ; RV64ZBP-LABEL: bitreverse_i32:
2948 ; RV64ZBP-NEXT: greviw a0, a0, 31
2950 %1 = tail call i32 @llvm.bitreverse.i32(i32 %a)
2954 ; Similar to bitreverse_i32 but the result is not sign extended.
2955 define void @bitreverse_i32_nosext(i32 signext %a, i32* %x) nounwind {
2956 ; RV64I-LABEL: bitreverse_i32_nosext:
2958 ; RV64I-NEXT: srliw a2, a0, 8
2959 ; RV64I-NEXT: lui a3, 16
2960 ; RV64I-NEXT: addiw a3, a3, -256
2961 ; RV64I-NEXT: and a2, a2, a3
2962 ; RV64I-NEXT: srliw a3, a0, 24
2963 ; RV64I-NEXT: or a2, a2, a3
2964 ; RV64I-NEXT: slli a3, a0, 8
2965 ; RV64I-NEXT: lui a4, 4080
2966 ; RV64I-NEXT: and a3, a3, a4
2967 ; RV64I-NEXT: slli a0, a0, 24
2968 ; RV64I-NEXT: or a0, a0, a3
2969 ; RV64I-NEXT: or a0, a0, a2
2970 ; RV64I-NEXT: lui a2, 61681
2971 ; RV64I-NEXT: addiw a2, a2, -241
2972 ; RV64I-NEXT: and a2, a0, a2
2973 ; RV64I-NEXT: slli a2, a2, 4
2974 ; RV64I-NEXT: lui a3, 241
2975 ; RV64I-NEXT: addiw a3, a3, -241
2976 ; RV64I-NEXT: slli a3, a3, 12
2977 ; RV64I-NEXT: addi a3, a3, 240
2978 ; RV64I-NEXT: and a0, a0, a3
2979 ; RV64I-NEXT: srli a0, a0, 4
2980 ; RV64I-NEXT: or a0, a0, a2
2981 ; RV64I-NEXT: lui a2, 209715
2982 ; RV64I-NEXT: addiw a2, a2, 819
2983 ; RV64I-NEXT: and a2, a0, a2
2984 ; RV64I-NEXT: slli a2, a2, 2
2985 ; RV64I-NEXT: lui a3, 838861
2986 ; RV64I-NEXT: addiw a3, a3, -820
2987 ; RV64I-NEXT: and a0, a0, a3
2988 ; RV64I-NEXT: srli a0, a0, 2
2989 ; RV64I-NEXT: or a0, a0, a2
2990 ; RV64I-NEXT: lui a2, 349525
2991 ; RV64I-NEXT: addiw a2, a2, 1365
2992 ; RV64I-NEXT: and a2, a0, a2
2993 ; RV64I-NEXT: slli a2, a2, 1
2994 ; RV64I-NEXT: lui a3, 699051
2995 ; RV64I-NEXT: addiw a3, a3, -1366
2996 ; RV64I-NEXT: and a0, a0, a3
2997 ; RV64I-NEXT: srli a0, a0, 1
2998 ; RV64I-NEXT: or a0, a0, a2
2999 ; RV64I-NEXT: sw a0, 0(a1)
3002 ; RV64B-LABEL: bitreverse_i32_nosext:
3004 ; RV64B-NEXT: greviw a0, a0, 31
3005 ; RV64B-NEXT: sw a0, 0(a1)
3008 ; RV64ZBP-LABEL: bitreverse_i32_nosext:
3010 ; RV64ZBP-NEXT: greviw a0, a0, 31
3011 ; RV64ZBP-NEXT: sw a0, 0(a1)
3013 %1 = tail call i32 @llvm.bitreverse.i32(i32 %a)
3014 store i32 %1, i32* %x
3018 declare i64 @llvm.bitreverse.i64(i64)
3020 define i64 @bitreverse_i64(i64 %a) nounwind {
3021 ; RV64I-LABEL: bitreverse_i64:
3023 ; RV64I-NEXT: srli a1, a0, 24
3024 ; RV64I-NEXT: lui a2, 4080
3025 ; RV64I-NEXT: and a1, a1, a2
3026 ; RV64I-NEXT: srli a2, a0, 8
3027 ; RV64I-NEXT: addi a3, zero, 255
3028 ; RV64I-NEXT: slli a4, a3, 24
3029 ; RV64I-NEXT: and a2, a2, a4
3030 ; RV64I-NEXT: or a1, a2, a1
3031 ; RV64I-NEXT: srli a2, a0, 40
3032 ; RV64I-NEXT: lui a4, 16
3033 ; RV64I-NEXT: addiw a4, a4, -256
3034 ; RV64I-NEXT: and a2, a2, a4
3035 ; RV64I-NEXT: srli a4, a0, 56
3036 ; RV64I-NEXT: or a2, a2, a4
3037 ; RV64I-NEXT: or a1, a1, a2
3038 ; RV64I-NEXT: slli a2, a0, 8
3039 ; RV64I-NEXT: slli a4, a3, 32
3040 ; RV64I-NEXT: and a2, a2, a4
3041 ; RV64I-NEXT: slli a4, a0, 24
3042 ; RV64I-NEXT: slli a5, a3, 40
3043 ; RV64I-NEXT: and a4, a4, a5
3044 ; RV64I-NEXT: or a2, a4, a2
3045 ; RV64I-NEXT: slli a4, a0, 40
3046 ; RV64I-NEXT: slli a3, a3, 48
3047 ; RV64I-NEXT: and a3, a4, a3
3048 ; RV64I-NEXT: slli a0, a0, 56
3049 ; RV64I-NEXT: or a0, a0, a3
3050 ; RV64I-NEXT: or a0, a0, a2
3051 ; RV64I-NEXT: or a0, a0, a1
3052 ; RV64I-NEXT: lui a1, 3855
3053 ; RV64I-NEXT: addiw a1, a1, 241
3054 ; RV64I-NEXT: slli a1, a1, 12
3055 ; RV64I-NEXT: addi a1, a1, -241
3056 ; RV64I-NEXT: slli a1, a1, 12
3057 ; RV64I-NEXT: addi a1, a1, 241
3058 ; RV64I-NEXT: slli a1, a1, 12
3059 ; RV64I-NEXT: addi a1, a1, -241
3060 ; RV64I-NEXT: and a1, a0, a1
3061 ; RV64I-NEXT: slli a1, a1, 4
3062 ; RV64I-NEXT: lui a2, 1044721
3063 ; RV64I-NEXT: addiw a2, a2, -241
3064 ; RV64I-NEXT: slli a2, a2, 12
3065 ; RV64I-NEXT: addi a2, a2, 241
3066 ; RV64I-NEXT: slli a2, a2, 12
3067 ; RV64I-NEXT: addi a2, a2, -241
3068 ; RV64I-NEXT: slli a2, a2, 12
3069 ; RV64I-NEXT: addi a2, a2, 240
3070 ; RV64I-NEXT: and a0, a0, a2
3071 ; RV64I-NEXT: srli a0, a0, 4
3072 ; RV64I-NEXT: or a0, a0, a1
3073 ; RV64I-NEXT: lui a1, 13107
3074 ; RV64I-NEXT: addiw a1, a1, 819
3075 ; RV64I-NEXT: slli a1, a1, 12
3076 ; RV64I-NEXT: addi a1, a1, 819
3077 ; RV64I-NEXT: slli a1, a1, 12
3078 ; RV64I-NEXT: addi a1, a1, 819
3079 ; RV64I-NEXT: slli a1, a1, 12
3080 ; RV64I-NEXT: addi a1, a1, 819
3081 ; RV64I-NEXT: and a1, a0, a1
3082 ; RV64I-NEXT: slli a1, a1, 2
3083 ; RV64I-NEXT: lui a2, 1035469
3084 ; RV64I-NEXT: addiw a2, a2, -819
3085 ; RV64I-NEXT: slli a2, a2, 12
3086 ; RV64I-NEXT: addi a2, a2, -819
3087 ; RV64I-NEXT: slli a2, a2, 12
3088 ; RV64I-NEXT: addi a2, a2, -819
3089 ; RV64I-NEXT: slli a2, a2, 12
3090 ; RV64I-NEXT: addi a2, a2, -820
3091 ; RV64I-NEXT: and a0, a0, a2
3092 ; RV64I-NEXT: srli a0, a0, 2
3093 ; RV64I-NEXT: or a0, a0, a1
3094 ; RV64I-NEXT: lui a1, 21845
3095 ; RV64I-NEXT: addiw a1, a1, 1365
3096 ; RV64I-NEXT: slli a1, a1, 12
3097 ; RV64I-NEXT: addi a1, a1, 1365
3098 ; RV64I-NEXT: slli a1, a1, 12
3099 ; RV64I-NEXT: addi a1, a1, 1365
3100 ; RV64I-NEXT: slli a1, a1, 12
3101 ; RV64I-NEXT: addi a1, a1, 1365
3102 ; RV64I-NEXT: and a1, a0, a1
3103 ; RV64I-NEXT: slli a1, a1, 1
3104 ; RV64I-NEXT: lui a2, 1026731
3105 ; RV64I-NEXT: addiw a2, a2, -1365
3106 ; RV64I-NEXT: slli a2, a2, 12
3107 ; RV64I-NEXT: addi a2, a2, -1365
3108 ; RV64I-NEXT: slli a2, a2, 12
3109 ; RV64I-NEXT: addi a2, a2, -1365
3110 ; RV64I-NEXT: slli a2, a2, 12
3111 ; RV64I-NEXT: addi a2, a2, -1366
3112 ; RV64I-NEXT: and a0, a0, a2
3113 ; RV64I-NEXT: srli a0, a0, 1
3114 ; RV64I-NEXT: or a0, a0, a1
3117 ; RV64B-LABEL: bitreverse_i64:
3119 ; RV64B-NEXT: rev a0, a0
3122 ; RV64ZBP-LABEL: bitreverse_i64:
3124 ; RV64ZBP-NEXT: rev a0, a0
3126 %1 = call i64 @llvm.bitreverse.i64(i64 %a)
3130 define i32 @bswap_rotr_i32(i32 %a) {
3131 ; RV64I-LABEL: bswap_rotr_i32:
3133 ; RV64I-NEXT: srliw a1, a0, 8
3134 ; RV64I-NEXT: lui a2, 16
3135 ; RV64I-NEXT: addiw a2, a2, -256
3136 ; RV64I-NEXT: and a1, a1, a2
3137 ; RV64I-NEXT: srliw a2, a0, 24
3138 ; RV64I-NEXT: or a1, a1, a2
3139 ; RV64I-NEXT: slli a2, a0, 8
3140 ; RV64I-NEXT: lui a3, 4080
3141 ; RV64I-NEXT: and a2, a2, a3
3142 ; RV64I-NEXT: slli a0, a0, 24
3143 ; RV64I-NEXT: or a0, a0, a2
3144 ; RV64I-NEXT: or a1, a0, a1
3145 ; RV64I-NEXT: slli a1, a1, 16
3146 ; RV64I-NEXT: srliw a0, a0, 16
3147 ; RV64I-NEXT: or a0, a0, a1
3150 ; RV64B-LABEL: bswap_rotr_i32:
3152 ; RV64B-NEXT: greviw a0, a0, 8
3155 ; RV64ZBP-LABEL: bswap_rotr_i32:
3157 ; RV64ZBP-NEXT: greviw a0, a0, 8
3159 %1 = call i32 @llvm.bswap.i32(i32 %a)
3160 %2 = call i32 @llvm.fshr.i32(i32 %1, i32 %1, i32 16)
3164 define i32 @bswap_rotl_i32(i32 %a) {
3165 ; RV64I-LABEL: bswap_rotl_i32:
3167 ; RV64I-NEXT: srliw a1, a0, 8
3168 ; RV64I-NEXT: lui a2, 16
3169 ; RV64I-NEXT: addiw a2, a2, -256
3170 ; RV64I-NEXT: and a1, a1, a2
3171 ; RV64I-NEXT: srliw a2, a0, 24
3172 ; RV64I-NEXT: or a1, a1, a2
3173 ; RV64I-NEXT: slli a2, a0, 8
3174 ; RV64I-NEXT: lui a3, 4080
3175 ; RV64I-NEXT: and a2, a2, a3
3176 ; RV64I-NEXT: slli a0, a0, 24
3177 ; RV64I-NEXT: or a0, a0, a2
3178 ; RV64I-NEXT: or a1, a0, a1
3179 ; RV64I-NEXT: slli a1, a1, 16
3180 ; RV64I-NEXT: srliw a0, a0, 16
3181 ; RV64I-NEXT: or a0, a1, a0
3184 ; RV64B-LABEL: bswap_rotl_i32:
3186 ; RV64B-NEXT: greviw a0, a0, 8
3189 ; RV64ZBP-LABEL: bswap_rotl_i32:
3191 ; RV64ZBP-NEXT: greviw a0, a0, 8
3193 %1 = call i32 @llvm.bswap.i32(i32 %a)
3194 %2 = call i32 @llvm.fshl.i32(i32 %1, i32 %1, i32 16)
3198 define i32 @bitreverse_bswap_i32(i32 %a) {
3199 ; RV64I-LABEL: bitreverse_bswap_i32:
3201 ; RV64I-NEXT: srliw a1, a0, 8
3202 ; RV64I-NEXT: lui a2, 16
3203 ; RV64I-NEXT: addiw a2, a2, -256
3204 ; RV64I-NEXT: and a1, a1, a2
3205 ; RV64I-NEXT: srliw a3, a0, 24
3206 ; RV64I-NEXT: or a1, a1, a3
3207 ; RV64I-NEXT: slli a3, a0, 8
3208 ; RV64I-NEXT: lui a4, 4080
3209 ; RV64I-NEXT: and a3, a3, a4
3210 ; RV64I-NEXT: slli a0, a0, 24
3211 ; RV64I-NEXT: or a0, a0, a3
3212 ; RV64I-NEXT: or a0, a0, a1
3213 ; RV64I-NEXT: lui a1, 61681
3214 ; RV64I-NEXT: addiw a1, a1, -241
3215 ; RV64I-NEXT: and a1, a0, a1
3216 ; RV64I-NEXT: slli a1, a1, 4
3217 ; RV64I-NEXT: lui a3, 241
3218 ; RV64I-NEXT: addiw a3, a3, -241
3219 ; RV64I-NEXT: slli a3, a3, 12
3220 ; RV64I-NEXT: addi a3, a3, 240
3221 ; RV64I-NEXT: and a0, a0, a3
3222 ; RV64I-NEXT: srli a0, a0, 4
3223 ; RV64I-NEXT: or a0, a0, a1
3224 ; RV64I-NEXT: lui a1, 209715
3225 ; RV64I-NEXT: addiw a1, a1, 819
3226 ; RV64I-NEXT: and a1, a0, a1
3227 ; RV64I-NEXT: slli a1, a1, 2
3228 ; RV64I-NEXT: lui a3, 838861
3229 ; RV64I-NEXT: addiw a3, a3, -820
3230 ; RV64I-NEXT: and a0, a0, a3
3231 ; RV64I-NEXT: srli a0, a0, 2
3232 ; RV64I-NEXT: or a0, a0, a1
3233 ; RV64I-NEXT: lui a1, 349525
3234 ; RV64I-NEXT: addiw a1, a1, 1365
3235 ; RV64I-NEXT: and a1, a0, a1
3236 ; RV64I-NEXT: slli a1, a1, 1
3237 ; RV64I-NEXT: lui a3, 699051
3238 ; RV64I-NEXT: addiw a3, a3, -1366
3239 ; RV64I-NEXT: and a0, a0, a3
3240 ; RV64I-NEXT: srli a0, a0, 1
3241 ; RV64I-NEXT: or a0, a0, a1
3242 ; RV64I-NEXT: srli a1, a0, 8
3243 ; RV64I-NEXT: and a1, a1, a2
3244 ; RV64I-NEXT: srli a2, a0, 24
3245 ; RV64I-NEXT: or a1, a1, a2
3246 ; RV64I-NEXT: slli a2, a0, 8
3247 ; RV64I-NEXT: and a2, a2, a4
3248 ; RV64I-NEXT: slli a0, a0, 24
3249 ; RV64I-NEXT: or a0, a0, a2
3250 ; RV64I-NEXT: or a0, a0, a1
3253 ; RV64B-LABEL: bitreverse_bswap_i32:
3255 ; RV64B-NEXT: greviw a0, a0, 7
3258 ; RV64ZBP-LABEL: bitreverse_bswap_i32:
3260 ; RV64ZBP-NEXT: greviw a0, a0, 7
3262 %1 = call i32 @llvm.bitreverse.i32(i32 %a)
3263 %2 = call i32 @llvm.bswap.i32(i32 %1)
3267 define i64 @bitreverse_bswap_i64(i64 %a) {
3268 ; RV64I-LABEL: bitreverse_bswap_i64:
3270 ; RV64I-NEXT: srli a1, a0, 24
3271 ; RV64I-NEXT: lui a6, 4080
3272 ; RV64I-NEXT: and a1, a1, a6
3273 ; RV64I-NEXT: srli a3, a0, 8
3274 ; RV64I-NEXT: addi a5, zero, 255
3275 ; RV64I-NEXT: slli a7, a5, 24
3276 ; RV64I-NEXT: and a3, a3, a7
3277 ; RV64I-NEXT: or a3, a3, a1
3278 ; RV64I-NEXT: srli a4, a0, 40
3279 ; RV64I-NEXT: lui a1, 16
3280 ; RV64I-NEXT: addiw a1, a1, -256
3281 ; RV64I-NEXT: and a4, a4, a1
3282 ; RV64I-NEXT: srli a2, a0, 56
3283 ; RV64I-NEXT: or a2, a4, a2
3284 ; RV64I-NEXT: or a2, a3, a2
3285 ; RV64I-NEXT: slli a4, a0, 8
3286 ; RV64I-NEXT: slli t0, a5, 32
3287 ; RV64I-NEXT: and a3, a4, t0
3288 ; RV64I-NEXT: slli a4, a0, 24
3289 ; RV64I-NEXT: slli t1, a5, 40
3290 ; RV64I-NEXT: and a4, a4, t1
3291 ; RV64I-NEXT: or a3, a4, a3
3292 ; RV64I-NEXT: slli a4, a0, 40
3293 ; RV64I-NEXT: slli a5, a5, 48
3294 ; RV64I-NEXT: and a4, a4, a5
3295 ; RV64I-NEXT: slli a0, a0, 56
3296 ; RV64I-NEXT: or a0, a0, a4
3297 ; RV64I-NEXT: or a0, a0, a3
3298 ; RV64I-NEXT: or a0, a0, a2
3299 ; RV64I-NEXT: lui a2, 3855
3300 ; RV64I-NEXT: addiw a2, a2, 241
3301 ; RV64I-NEXT: slli a2, a2, 12
3302 ; RV64I-NEXT: addi a2, a2, -241
3303 ; RV64I-NEXT: slli a2, a2, 12
3304 ; RV64I-NEXT: addi a2, a2, 241
3305 ; RV64I-NEXT: slli a2, a2, 12
3306 ; RV64I-NEXT: addi a2, a2, -241
3307 ; RV64I-NEXT: and a2, a0, a2
3308 ; RV64I-NEXT: slli a2, a2, 4
3309 ; RV64I-NEXT: lui a3, 1044721
3310 ; RV64I-NEXT: addiw a3, a3, -241
3311 ; RV64I-NEXT: slli a3, a3, 12
3312 ; RV64I-NEXT: addi a3, a3, 241
3313 ; RV64I-NEXT: slli a3, a3, 12
3314 ; RV64I-NEXT: addi a3, a3, -241
3315 ; RV64I-NEXT: slli a3, a3, 12
3316 ; RV64I-NEXT: addi a3, a3, 240
3317 ; RV64I-NEXT: and a0, a0, a3
3318 ; RV64I-NEXT: srli a0, a0, 4
3319 ; RV64I-NEXT: or a0, a0, a2
3320 ; RV64I-NEXT: lui a2, 13107
3321 ; RV64I-NEXT: addiw a2, a2, 819
3322 ; RV64I-NEXT: slli a2, a2, 12
3323 ; RV64I-NEXT: addi a2, a2, 819
3324 ; RV64I-NEXT: slli a2, a2, 12
3325 ; RV64I-NEXT: addi a2, a2, 819
3326 ; RV64I-NEXT: slli a2, a2, 12
3327 ; RV64I-NEXT: addi a2, a2, 819
3328 ; RV64I-NEXT: and a2, a0, a2
3329 ; RV64I-NEXT: slli a2, a2, 2
3330 ; RV64I-NEXT: lui a3, 1035469
3331 ; RV64I-NEXT: addiw a3, a3, -819
3332 ; RV64I-NEXT: slli a3, a3, 12
3333 ; RV64I-NEXT: addi a3, a3, -819
3334 ; RV64I-NEXT: slli a3, a3, 12
3335 ; RV64I-NEXT: addi a3, a3, -819
3336 ; RV64I-NEXT: slli a3, a3, 12
3337 ; RV64I-NEXT: addi a3, a3, -820
3338 ; RV64I-NEXT: and a0, a0, a3
3339 ; RV64I-NEXT: srli a0, a0, 2
3340 ; RV64I-NEXT: or a0, a0, a2
3341 ; RV64I-NEXT: lui a2, 21845
3342 ; RV64I-NEXT: addiw a2, a2, 1365
3343 ; RV64I-NEXT: slli a2, a2, 12
3344 ; RV64I-NEXT: addi a2, a2, 1365
3345 ; RV64I-NEXT: slli a2, a2, 12
3346 ; RV64I-NEXT: addi a2, a2, 1365
3347 ; RV64I-NEXT: slli a2, a2, 12
3348 ; RV64I-NEXT: addi a2, a2, 1365
3349 ; RV64I-NEXT: and a2, a0, a2
3350 ; RV64I-NEXT: slli a2, a2, 1
3351 ; RV64I-NEXT: lui a3, 1026731
3352 ; RV64I-NEXT: addiw a3, a3, -1365
3353 ; RV64I-NEXT: slli a3, a3, 12
3354 ; RV64I-NEXT: addi a3, a3, -1365
3355 ; RV64I-NEXT: slli a3, a3, 12
3356 ; RV64I-NEXT: addi a3, a3, -1365
3357 ; RV64I-NEXT: slli a3, a3, 12
3358 ; RV64I-NEXT: addi a3, a3, -1366
3359 ; RV64I-NEXT: and a0, a0, a3
3360 ; RV64I-NEXT: srli a0, a0, 1
3361 ; RV64I-NEXT: or a0, a0, a2
3362 ; RV64I-NEXT: srli a2, a0, 40
3363 ; RV64I-NEXT: and a1, a2, a1
3364 ; RV64I-NEXT: srli a2, a0, 56
3365 ; RV64I-NEXT: or a1, a1, a2
3366 ; RV64I-NEXT: srli a2, a0, 24
3367 ; RV64I-NEXT: and a2, a2, a6
3368 ; RV64I-NEXT: srli a3, a0, 8
3369 ; RV64I-NEXT: and a3, a3, a7
3370 ; RV64I-NEXT: or a2, a3, a2
3371 ; RV64I-NEXT: or a1, a2, a1
3372 ; RV64I-NEXT: slli a2, a0, 8
3373 ; RV64I-NEXT: and a2, a2, t0
3374 ; RV64I-NEXT: slli a3, a0, 24
3375 ; RV64I-NEXT: and a3, a3, t1
3376 ; RV64I-NEXT: or a2, a3, a2
3377 ; RV64I-NEXT: slli a3, a0, 40
3378 ; RV64I-NEXT: and a3, a3, a5
3379 ; RV64I-NEXT: slli a0, a0, 56
3380 ; RV64I-NEXT: or a0, a0, a3
3381 ; RV64I-NEXT: or a0, a0, a2
3382 ; RV64I-NEXT: or a0, a0, a1
3385 ; RV64B-LABEL: bitreverse_bswap_i64:
3387 ; RV64B-NEXT: rev.b a0, a0
3390 ; RV64ZBP-LABEL: bitreverse_bswap_i64:
3392 ; RV64ZBP-NEXT: rev.b a0, a0
3394 %1 = call i64 @llvm.bitreverse.i64(i64 %a)
3395 %2 = call i64 @llvm.bswap.i64(i64 %1)
3399 define signext i32 @shfl1_i32(i32 signext %a, i32 signext %b) nounwind {
3400 ; RV64I-LABEL: shfl1_i32:
3402 ; RV64I-NEXT: lui a1, 629146
3403 ; RV64I-NEXT: addiw a1, a1, -1639
3404 ; RV64I-NEXT: and a1, a0, a1
3405 ; RV64I-NEXT: slli a2, a0, 1
3406 ; RV64I-NEXT: lui a3, 279620
3407 ; RV64I-NEXT: addiw a3, a3, 1092
3408 ; RV64I-NEXT: and a2, a2, a3
3409 ; RV64I-NEXT: or a1, a2, a1
3410 ; RV64I-NEXT: srli a0, a0, 1
3411 ; RV64I-NEXT: lui a2, 139810
3412 ; RV64I-NEXT: addiw a2, a2, 546
3413 ; RV64I-NEXT: and a0, a0, a2
3414 ; RV64I-NEXT: or a0, a1, a0
3417 ; RV64B-LABEL: shfl1_i32:
3419 ; RV64B-NEXT: zip.n a0, a0
3422 ; RV64ZBP-LABEL: shfl1_i32:
3424 ; RV64ZBP-NEXT: zip.n a0, a0
3426 %and = and i32 %a, -1717986919
3427 %shl = shl i32 %a, 1
3428 %and1 = and i32 %shl, 1145324612
3429 %or = or i32 %and1, %and
3430 %shr = lshr i32 %a, 1
3431 %and2 = and i32 %shr, 572662306
3432 %or3 = or i32 %or, %and2
3436 define i64 @shfl1_i64(i64 %a, i64 %b) nounwind {
3437 ; RV64I-LABEL: shfl1_i64:
3439 ; RV64I-NEXT: lui a1, 1035469
3440 ; RV64I-NEXT: addiw a1, a1, -819
3441 ; RV64I-NEXT: slli a1, a1, 12
3442 ; RV64I-NEXT: addi a1, a1, -819
3443 ; RV64I-NEXT: slli a1, a1, 12
3444 ; RV64I-NEXT: addi a1, a1, -819
3445 ; RV64I-NEXT: slli a1, a1, 13
3446 ; RV64I-NEXT: addi a1, a1, -1639
3447 ; RV64I-NEXT: and a1, a0, a1
3448 ; RV64I-NEXT: slli a2, a0, 1
3449 ; RV64I-NEXT: lui a3, 4369
3450 ; RV64I-NEXT: addiw a3, a3, 273
3451 ; RV64I-NEXT: slli a3, a3, 12
3452 ; RV64I-NEXT: addi a3, a3, 273
3453 ; RV64I-NEXT: slli a3, a3, 12
3454 ; RV64I-NEXT: addi a3, a3, 273
3455 ; RV64I-NEXT: slli a4, a3, 14
3456 ; RV64I-NEXT: addi a4, a4, 1092
3457 ; RV64I-NEXT: and a2, a2, a4
3458 ; RV64I-NEXT: or a1, a1, a2
3459 ; RV64I-NEXT: srli a0, a0, 1
3460 ; RV64I-NEXT: slli a2, a3, 13
3461 ; RV64I-NEXT: addi a2, a2, 546
3462 ; RV64I-NEXT: and a0, a0, a2
3463 ; RV64I-NEXT: or a0, a1, a0
3466 ; RV64B-LABEL: shfl1_i64:
3468 ; RV64B-NEXT: zip.n a0, a0
3471 ; RV64ZBP-LABEL: shfl1_i64:
3473 ; RV64ZBP-NEXT: zip.n a0, a0
3475 %and = and i64 %a, -7378697629483820647
3476 %shl = shl i64 %a, 1
3477 %and1 = and i64 %shl, 4919131752989213764
3478 %or = or i64 %and, %and1
3479 %shr = lshr i64 %a, 1
3480 %and2 = and i64 %shr, 2459565876494606882
3481 %or3 = or i64 %or, %and2
3485 define signext i32 @shfl2_i32(i32 signext %a, i32 signext %b) nounwind {
3486 ; RV64I-LABEL: shfl2_i32:
3488 ; RV64I-NEXT: lui a1, 801852
3489 ; RV64I-NEXT: addiw a1, a1, 963
3490 ; RV64I-NEXT: and a1, a0, a1
3491 ; RV64I-NEXT: slli a2, a0, 2
3492 ; RV64I-NEXT: lui a3, 197379
3493 ; RV64I-NEXT: addiw a3, a3, 48
3494 ; RV64I-NEXT: and a2, a2, a3
3495 ; RV64I-NEXT: or a1, a2, a1
3496 ; RV64I-NEXT: srli a0, a0, 2
3497 ; RV64I-NEXT: lui a2, 49345
3498 ; RV64I-NEXT: addiw a2, a2, -1012
3499 ; RV64I-NEXT: and a0, a0, a2
3500 ; RV64I-NEXT: or a0, a0, a1
3503 ; RV64B-LABEL: shfl2_i32:
3505 ; RV64B-NEXT: zip2.b a0, a0
3508 ; RV64ZBP-LABEL: shfl2_i32:
3510 ; RV64ZBP-NEXT: zip2.b a0, a0
3512 %and = and i32 %a, -1010580541
3513 %shl = shl i32 %a, 2
3514 %and1 = and i32 %shl, 808464432
3515 %or = or i32 %and1, %and
3516 %shr = lshr i32 %a, 2
3517 %and2 = and i32 %shr, 202116108
3518 %or3 = or i32 %and2, %or
3522 define i64 @shfl2_i64(i64 %a, i64 %b) nounwind {
3523 ; RV64I-LABEL: shfl2_i64:
3525 ; RV64I-NEXT: lui a1, 1044721
3526 ; RV64I-NEXT: addiw a1, a1, -241
3527 ; RV64I-NEXT: slli a1, a1, 12
3528 ; RV64I-NEXT: addi a1, a1, 241
3529 ; RV64I-NEXT: slli a1, a1, 12
3530 ; RV64I-NEXT: addi a1, a1, -241
3531 ; RV64I-NEXT: slli a1, a1, 14
3532 ; RV64I-NEXT: addi a1, a1, 963
3533 ; RV64I-NEXT: and a1, a0, a1
3534 ; RV64I-NEXT: slli a2, a0, 2
3535 ; RV64I-NEXT: lui a3, 197379
3536 ; RV64I-NEXT: slli a3, a3, 4
3537 ; RV64I-NEXT: addi a3, a3, 771
3538 ; RV64I-NEXT: slli a4, a3, 16
3539 ; RV64I-NEXT: addi a4, a4, 771
3540 ; RV64I-NEXT: slli a4, a4, 12
3541 ; RV64I-NEXT: addi a4, a4, 48
3542 ; RV64I-NEXT: and a2, a2, a4
3543 ; RV64I-NEXT: or a1, a1, a2
3544 ; RV64I-NEXT: srli a0, a0, 2
3545 ; RV64I-NEXT: slli a2, a3, 14
3546 ; RV64I-NEXT: addi a2, a2, 193
3547 ; RV64I-NEXT: slli a2, a2, 12
3548 ; RV64I-NEXT: addi a2, a2, -1012
3549 ; RV64I-NEXT: and a0, a0, a2
3550 ; RV64I-NEXT: or a0, a0, a1
3553 ; RV64B-LABEL: shfl2_i64:
3555 ; RV64B-NEXT: zip2.b a0, a0
3558 ; RV64ZBP-LABEL: shfl2_i64:
3560 ; RV64ZBP-NEXT: zip2.b a0, a0
3562 %and = and i64 %a, -4340410370284600381
3563 %shl = shl i64 %a, 2
3564 %and1 = and i64 %shl, 3472328296227680304
3565 %or = or i64 %and, %and1
3566 %shr = lshr i64 %a, 2
3567 %and2 = and i64 %shr, 868082074056920076
3568 %or3 = or i64 %and2, %or
3572 define signext i32 @shfl4_i32(i32 signext %a, i32 signext %b) nounwind {
3573 ; RV64I-LABEL: shfl4_i32:
3575 ; RV64I-NEXT: lui a1, 983295
3576 ; RV64I-NEXT: addiw a1, a1, 15
3577 ; RV64I-NEXT: and a1, a0, a1
3578 ; RV64I-NEXT: slli a2, a0, 4
3579 ; RV64I-NEXT: lui a3, 61441
3580 ; RV64I-NEXT: addiw a3, a3, -256
3581 ; RV64I-NEXT: and a2, a2, a3
3582 ; RV64I-NEXT: srli a0, a0, 4
3583 ; RV64I-NEXT: lui a3, 3840
3584 ; RV64I-NEXT: addiw a3, a3, 240
3585 ; RV64I-NEXT: and a0, a0, a3
3586 ; RV64I-NEXT: or a0, a0, a1
3587 ; RV64I-NEXT: or a0, a0, a2
3590 ; RV64B-LABEL: shfl4_i32:
3592 ; RV64B-NEXT: zip4.h a0, a0
3595 ; RV64ZBP-LABEL: shfl4_i32:
3597 ; RV64ZBP-NEXT: zip4.h a0, a0
3599 %and = and i32 %a, -267390961
3600 %shl = shl i32 %a, 4
3601 %and1 = and i32 %shl, 251662080
3602 %shr = lshr i32 %a, 4
3603 %and2 = and i32 %shr, 15728880
3604 %or = or i32 %and2, %and
3605 %or3 = or i32 %or, %and1
3609 define i64 @shfl4_i64(i64 %a, i64 %b) nounwind {
3610 ; RV64I-LABEL: shfl4_i64:
3612 ; RV64I-NEXT: lui a1, 983295
3613 ; RV64I-NEXT: slli a1, a1, 4
3614 ; RV64I-NEXT: addi a1, a1, 255
3615 ; RV64I-NEXT: slli a1, a1, 16
3616 ; RV64I-NEXT: addi a1, a1, 255
3617 ; RV64I-NEXT: slli a1, a1, 12
3618 ; RV64I-NEXT: addi a1, a1, 15
3619 ; RV64I-NEXT: and a1, a0, a1
3620 ; RV64I-NEXT: slli a2, a0, 4
3621 ; RV64I-NEXT: lui a3, 983055
3622 ; RV64I-NEXT: slli a3, a3, 4
3623 ; RV64I-NEXT: addi a3, a3, 15
3624 ; RV64I-NEXT: slli a3, a3, 16
3625 ; RV64I-NEXT: addi a3, a3, 15
3626 ; RV64I-NEXT: slli a3, a3, 12
3627 ; RV64I-NEXT: srli a3, a3, 4
3628 ; RV64I-NEXT: and a2, a2, a3
3629 ; RV64I-NEXT: srli a0, a0, 4
3630 ; RV64I-NEXT: lui a3, 240
3631 ; RV64I-NEXT: addiw a3, a3, 15
3632 ; RV64I-NEXT: slli a3, a3, 16
3633 ; RV64I-NEXT: addi a3, a3, 15
3634 ; RV64I-NEXT: slli a3, a3, 20
3635 ; RV64I-NEXT: addi a3, a3, 240
3636 ; RV64I-NEXT: and a0, a0, a3
3637 ; RV64I-NEXT: or a0, a2, a0
3638 ; RV64I-NEXT: or a0, a0, a1
3641 ; RV64B-LABEL: shfl4_i64:
3643 ; RV64B-NEXT: zip4.h a0, a0
3646 ; RV64ZBP-LABEL: shfl4_i64:
3648 ; RV64ZBP-NEXT: zip4.h a0, a0
3650 %and = and i64 %a, -1148435428713435121
3651 %shl = shl i64 %a, 4
3652 %and1 = and i64 %shl, 1080880403494997760
3653 %shr = lshr i64 %a, 4
3654 %and2 = and i64 %shr, 67555025218437360
3655 %or = or i64 %and1, %and2
3656 %or3 = or i64 %or, %and
3660 define signext i32 @shfl8_i32(i32 signext %a, i32 signext %b) nounwind {
3661 ; RV64I-LABEL: shfl8_i32:
3663 ; RV64I-NEXT: lui a1, 1044480
3664 ; RV64I-NEXT: addiw a1, a1, 255
3665 ; RV64I-NEXT: and a1, a0, a1
3666 ; RV64I-NEXT: slli a2, a0, 8
3667 ; RV64I-NEXT: lui a3, 4080
3668 ; RV64I-NEXT: and a2, a2, a3
3669 ; RV64I-NEXT: srli a0, a0, 8
3670 ; RV64I-NEXT: lui a3, 16
3671 ; RV64I-NEXT: addiw a3, a3, -256
3672 ; RV64I-NEXT: and a0, a0, a3
3673 ; RV64I-NEXT: or a0, a1, a0
3674 ; RV64I-NEXT: or a0, a0, a2
3677 ; RV64B-LABEL: shfl8_i32:
3679 ; RV64B-NEXT: zip8.w a0, a0
3682 ; RV64ZBP-LABEL: shfl8_i32:
3684 ; RV64ZBP-NEXT: zip8.w a0, a0
3686 %and = and i32 %a, -16776961
3687 %shl = shl i32 %a, 8
3688 %and1 = and i32 %shl, 16711680
3689 %shr = lshr i32 %a, 8
3690 %and2 = and i32 %shr, 65280
3691 %or = or i32 %and, %and2
3692 %or3 = or i32 %or, %and1
3696 define i64 @shfl8_i64(i64 %a, i64 %b) nounwind {
3697 ; RV64I-LABEL: shfl8_i64:
3699 ; RV64I-NEXT: lui a1, 983041
3700 ; RV64I-NEXT: slli a1, a1, 4
3701 ; RV64I-NEXT: addi a1, a1, -1
3702 ; RV64I-NEXT: slli a1, a1, 24
3703 ; RV64I-NEXT: addi a1, a1, 255
3704 ; RV64I-NEXT: and a1, a0, a1
3705 ; RV64I-NEXT: slli a2, a0, 8
3706 ; RV64I-NEXT: addi a3, zero, 255
3707 ; RV64I-NEXT: slli a4, a3, 32
3708 ; RV64I-NEXT: addi a4, a4, 255
3709 ; RV64I-NEXT: slli a4, a4, 16
3710 ; RV64I-NEXT: and a2, a2, a4
3711 ; RV64I-NEXT: srli a0, a0, 8
3712 ; RV64I-NEXT: slli a3, a3, 24
3713 ; RV64I-NEXT: addi a3, a3, 1
3714 ; RV64I-NEXT: slli a3, a3, 16
3715 ; RV64I-NEXT: addi a3, a3, -256
3716 ; RV64I-NEXT: and a0, a0, a3
3717 ; RV64I-NEXT: or a0, a0, a1
3718 ; RV64I-NEXT: or a0, a2, a0
3721 ; RV64B-LABEL: shfl8_i64:
3723 ; RV64B-NEXT: zip8.w a0, a0
3726 ; RV64ZBP-LABEL: shfl8_i64:
3728 ; RV64ZBP-NEXT: zip8.w a0, a0
3730 %and = and i64 %a, -72056494543077121
3731 %shl = shl i64 %a, 8
3732 %and1 = and i64 %shl, 71776119077928960
3733 %shr = lshr i64 %a, 8
3734 %and2 = and i64 %shr, 280375465148160
3735 %or = or i64 %and2, %and
3736 %or3 = or i64 %and1, %or
3740 define i64 @shfl16(i64 %a, i64 %b) nounwind {
3741 ; RV64I-LABEL: shfl16:
3743 ; RV64I-NEXT: addi a1, zero, -1
3744 ; RV64I-NEXT: slli a1, a1, 32
3745 ; RV64I-NEXT: addi a1, a1, 1
3746 ; RV64I-NEXT: slli a1, a1, 16
3747 ; RV64I-NEXT: addi a1, a1, -1
3748 ; RV64I-NEXT: and a1, a0, a1
3749 ; RV64I-NEXT: slli a2, a0, 16
3750 ; RV64I-NEXT: lui a3, 65535
3751 ; RV64I-NEXT: slli a4, a3, 20
3752 ; RV64I-NEXT: and a2, a2, a4
3753 ; RV64I-NEXT: or a1, a2, a1
3754 ; RV64I-NEXT: srli a0, a0, 16
3755 ; RV64I-NEXT: slli a2, a3, 4
3756 ; RV64I-NEXT: and a0, a0, a2
3757 ; RV64I-NEXT: or a0, a1, a0
3760 ; RV64B-LABEL: shfl16:
3762 ; RV64B-NEXT: zip16 a0, a0
3765 ; RV64ZBP-LABEL: shfl16:
3767 ; RV64ZBP-NEXT: zip16 a0, a0
3769 %and = and i64 %a, -281474976645121
3770 %shl = shl i64 %a, 16
3771 %and1 = and i64 %shl, 281470681743360
3772 %or = or i64 %and1, %and
3773 %shr = lshr i64 %a, 16
3774 %and2 = and i64 %shr, 4294901760
3775 %or3 = or i64 %or, %and2
3779 define signext i32 @pack_i32(i32 signext %a, i32 signext %b) nounwind {
3780 ; RV64I-LABEL: pack_i32:
3782 ; RV64I-NEXT: lui a2, 16
3783 ; RV64I-NEXT: addiw a2, a2, -1
3784 ; RV64I-NEXT: and a0, a0, a2
3785 ; RV64I-NEXT: slli a1, a1, 16
3786 ; RV64I-NEXT: or a0, a1, a0
3787 ; RV64I-NEXT: sext.w a0, a0
3790 ; RV64B-LABEL: pack_i32:
3792 ; RV64B-NEXT: packw a0, a0, a1
3795 ; RV64ZBP-LABEL: pack_i32:
3797 ; RV64ZBP-NEXT: packw a0, a0, a1
3799 %shl = and i32 %a, 65535
3800 %shl1 = shl i32 %b, 16
3801 %or = or i32 %shl1, %shl
3805 define i64 @pack_i64(i64 %a, i64 %b) nounwind {
3806 ; RV64I-LABEL: pack_i64:
3808 ; RV64I-NEXT: slli a0, a0, 32
3809 ; RV64I-NEXT: srli a0, a0, 32
3810 ; RV64I-NEXT: slli a1, a1, 32
3811 ; RV64I-NEXT: or a0, a1, a0
3814 ; RV64B-LABEL: pack_i64:
3816 ; RV64B-NEXT: pack a0, a0, a1
3819 ; RV64ZBP-LABEL: pack_i64:
3821 ; RV64ZBP-NEXT: pack a0, a0, a1
3823 %shl = and i64 %a, 4294967295
3824 %shl1 = shl i64 %b, 32
3825 %or = or i64 %shl1, %shl
3829 define signext i32 @packu_i32(i32 signext %a, i32 signext %b) nounwind {
3830 ; RV64I-LABEL: packu_i32:
3832 ; RV64I-NEXT: srliw a0, a0, 16
3833 ; RV64I-NEXT: lui a2, 1048560
3834 ; RV64I-NEXT: and a1, a1, a2
3835 ; RV64I-NEXT: or a0, a1, a0
3838 ; RV64B-LABEL: packu_i32:
3840 ; RV64B-NEXT: packuw a0, a0, a1
3843 ; RV64ZBP-LABEL: packu_i32:
3845 ; RV64ZBP-NEXT: packuw a0, a0, a1
3847 %shr = lshr i32 %a, 16
3848 %shr1 = and i32 %b, -65536
3849 %or = or i32 %shr1, %shr
3853 define i64 @packu_i64(i64 %a, i64 %b) nounwind {
3854 ; RV64I-LABEL: packu_i64:
3856 ; RV64I-NEXT: srli a0, a0, 32
3857 ; RV64I-NEXT: addi a2, zero, -1
3858 ; RV64I-NEXT: slli a2, a2, 32
3859 ; RV64I-NEXT: and a1, a1, a2
3860 ; RV64I-NEXT: or a0, a1, a0
3863 ; RV64B-LABEL: packu_i64:
3865 ; RV64B-NEXT: packu a0, a0, a1
3868 ; RV64ZBP-LABEL: packu_i64:
3870 ; RV64ZBP-NEXT: packu a0, a0, a1
3872 %shr = lshr i64 %a, 32
3873 %shr1 = and i64 %b, -4294967296
3874 %or = or i64 %shr1, %shr
3878 define signext i32 @packh_i32(i32 signext %a, i32 signext %b) nounwind {
3879 ; RV64I-LABEL: packh_i32:
3881 ; RV64I-NEXT: andi a0, a0, 255
3882 ; RV64I-NEXT: slli a1, a1, 56
3883 ; RV64I-NEXT: srli a1, a1, 48
3884 ; RV64I-NEXT: or a0, a1, a0
3887 ; RV64B-LABEL: packh_i32:
3889 ; RV64B-NEXT: packh a0, a0, a1
3892 ; RV64ZBP-LABEL: packh_i32:
3894 ; RV64ZBP-NEXT: packh a0, a0, a1
3896 %and = and i32 %a, 255
3897 %and1 = shl i32 %b, 8
3898 %shl = and i32 %and1, 65280
3899 %or = or i32 %shl, %and
3903 define i64 @packh_i64(i64 %a, i64 %b) nounwind {
3904 ; RV64I-LABEL: packh_i64:
3906 ; RV64I-NEXT: andi a0, a0, 255
3907 ; RV64I-NEXT: slli a1, a1, 56
3908 ; RV64I-NEXT: srli a1, a1, 48
3909 ; RV64I-NEXT: or a0, a1, a0
3912 ; RV64B-LABEL: packh_i64:
3914 ; RV64B-NEXT: packh a0, a0, a1
3917 ; RV64ZBP-LABEL: packh_i64:
3919 ; RV64ZBP-NEXT: packh a0, a0, a1
3921 %and = and i64 %a, 255
3922 %and1 = shl i64 %b, 8
3923 %shl = and i64 %and1, 65280
3924 %or = or i64 %shl, %and
3928 define i32 @zexth_i32(i32 %a) nounwind {
3929 ; RV64I-LABEL: zexth_i32:
3931 ; RV64I-NEXT: lui a1, 16
3932 ; RV64I-NEXT: addiw a1, a1, -1
3933 ; RV64I-NEXT: and a0, a0, a1
3936 ; RV64B-LABEL: zexth_i32:
3938 ; RV64B-NEXT: zext.h a0, a0
3941 ; RV64ZBP-LABEL: zexth_i32:
3943 ; RV64ZBP-NEXT: zext.h a0, a0
3945 %and = and i32 %a, 65535
3949 define i64 @zexth_i64(i64 %a) nounwind {
3950 ; RV64I-LABEL: zexth_i64:
3952 ; RV64I-NEXT: lui a1, 16
3953 ; RV64I-NEXT: addiw a1, a1, -1
3954 ; RV64I-NEXT: and a0, a0, a1
3957 ; RV64B-LABEL: zexth_i64:
3959 ; RV64B-NEXT: zext.h a0, a0
3962 ; RV64ZBP-LABEL: zexth_i64:
3964 ; RV64ZBP-NEXT: zext.h a0, a0
3966 %and = and i64 %a, 65535