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-zbs -verify-machineinstrs < %s \
7 ; RUN: | FileCheck %s -check-prefix=RV64ZBS
9 define signext i32 @sbclr_i32(i32 signext %a, i32 signext %b) nounwind {
10 ; RV64I-LABEL: sbclr_i32:
12 ; RV64I-NEXT: addi a2, zero, 1
13 ; RV64I-NEXT: sllw a1, a2, a1
14 ; RV64I-NEXT: not a1, a1
15 ; RV64I-NEXT: and a0, a1, a0
18 ; RV64B-LABEL: sbclr_i32:
20 ; RV64B-NEXT: addi a2, zero, 1
21 ; RV64B-NEXT: sllw a1, a2, a1
22 ; RV64B-NEXT: andn a0, a0, a1
25 ; RV64ZBS-LABEL: sbclr_i32:
27 ; RV64ZBS-NEXT: addi a2, zero, 1
28 ; RV64ZBS-NEXT: sllw a1, a2, a1
29 ; RV64ZBS-NEXT: not a1, a1
30 ; RV64ZBS-NEXT: and a0, a1, a0
33 %shl = shl nuw i32 1, %and
34 %neg = xor i32 %shl, -1
35 %and1 = and i32 %neg, %a
39 define signext i32 @sbclr_i32_no_mask(i32 signext %a, i32 signext %b) nounwind {
40 ; RV64I-LABEL: sbclr_i32_no_mask:
42 ; RV64I-NEXT: addi a2, zero, 1
43 ; RV64I-NEXT: sllw a1, a2, a1
44 ; RV64I-NEXT: not a1, a1
45 ; RV64I-NEXT: and a0, a1, a0
48 ; RV64B-LABEL: sbclr_i32_no_mask:
50 ; RV64B-NEXT: addi a2, zero, 1
51 ; RV64B-NEXT: sllw a1, a2, a1
52 ; RV64B-NEXT: andn a0, a0, a1
55 ; RV64ZBS-LABEL: sbclr_i32_no_mask:
57 ; RV64ZBS-NEXT: addi a2, zero, 1
58 ; RV64ZBS-NEXT: sllw a1, a2, a1
59 ; RV64ZBS-NEXT: not a1, a1
60 ; RV64ZBS-NEXT: and a0, a1, a0
63 %neg = xor i32 %shl, -1
64 %and1 = and i32 %neg, %a
68 define signext i32 @sbclr_i32_load(i32* %p, i32 signext %b) nounwind {
69 ; RV64I-LABEL: sbclr_i32_load:
71 ; RV64I-NEXT: lw a0, 0(a0)
72 ; RV64I-NEXT: addi a2, zero, 1
73 ; RV64I-NEXT: sllw a1, a2, a1
74 ; RV64I-NEXT: not a1, a1
75 ; RV64I-NEXT: and a0, a1, a0
76 ; RV64I-NEXT: sext.w a0, a0
79 ; RV64B-LABEL: sbclr_i32_load:
81 ; RV64B-NEXT: lw a0, 0(a0)
82 ; RV64B-NEXT: addi a2, zero, 1
83 ; RV64B-NEXT: sllw a1, a2, a1
84 ; RV64B-NEXT: andn a0, a0, a1
85 ; RV64B-NEXT: sext.w a0, a0
88 ; RV64ZBS-LABEL: sbclr_i32_load:
90 ; RV64ZBS-NEXT: lw a0, 0(a0)
91 ; RV64ZBS-NEXT: addi a2, zero, 1
92 ; RV64ZBS-NEXT: sllw a1, a2, a1
93 ; RV64ZBS-NEXT: not a1, a1
94 ; RV64ZBS-NEXT: and a0, a1, a0
95 ; RV64ZBS-NEXT: sext.w a0, a0
97 %a = load i32, i32* %p
99 %neg = xor i32 %shl, -1
100 %and1 = and i32 %neg, %a
104 define i64 @sbclr_i64(i64 %a, i64 %b) nounwind {
105 ; RV64I-LABEL: sbclr_i64:
107 ; RV64I-NEXT: addi a2, zero, 1
108 ; RV64I-NEXT: sll a1, a2, a1
109 ; RV64I-NEXT: not a1, a1
110 ; RV64I-NEXT: and a0, a1, a0
113 ; RV64B-LABEL: sbclr_i64:
115 ; RV64B-NEXT: bclr a0, a0, a1
118 ; RV64ZBS-LABEL: sbclr_i64:
120 ; RV64ZBS-NEXT: bclr a0, a0, a1
122 %and = and i64 %b, 63
123 %shl = shl nuw i64 1, %and
124 %neg = xor i64 %shl, -1
125 %and1 = and i64 %neg, %a
129 define i64 @sbclr_i64_no_mask(i64 %a, i64 %b) nounwind {
130 ; RV64I-LABEL: sbclr_i64_no_mask:
132 ; RV64I-NEXT: addi a2, zero, 1
133 ; RV64I-NEXT: sll a1, a2, a1
134 ; RV64I-NEXT: not a1, a1
135 ; RV64I-NEXT: and a0, a1, a0
138 ; RV64B-LABEL: sbclr_i64_no_mask:
140 ; RV64B-NEXT: bclr a0, a0, a1
143 ; RV64ZBS-LABEL: sbclr_i64_no_mask:
145 ; RV64ZBS-NEXT: bclr a0, a0, a1
148 %neg = xor i64 %shl, -1
149 %and1 = and i64 %neg, %a
153 define signext i32 @sbset_i32(i32 signext %a, i32 signext %b) nounwind {
154 ; RV64I-LABEL: sbset_i32:
156 ; RV64I-NEXT: addi a2, zero, 1
157 ; RV64I-NEXT: sllw a1, a2, a1
158 ; RV64I-NEXT: or a0, a1, a0
161 ; RV64B-LABEL: sbset_i32:
163 ; RV64B-NEXT: addi a2, zero, 1
164 ; RV64B-NEXT: sllw a1, a2, a1
165 ; RV64B-NEXT: or a0, a1, a0
168 ; RV64ZBS-LABEL: sbset_i32:
170 ; RV64ZBS-NEXT: addi a2, zero, 1
171 ; RV64ZBS-NEXT: sllw a1, a2, a1
172 ; RV64ZBS-NEXT: or a0, a1, a0
174 %and = and i32 %b, 31
175 %shl = shl nuw i32 1, %and
176 %or = or i32 %shl, %a
180 define signext i32 @sbset_i32_no_mask(i32 signext %a, i32 signext %b) nounwind {
181 ; RV64I-LABEL: sbset_i32_no_mask:
183 ; RV64I-NEXT: addi a2, zero, 1
184 ; RV64I-NEXT: sllw a1, a2, a1
185 ; RV64I-NEXT: or a0, a1, a0
188 ; RV64B-LABEL: sbset_i32_no_mask:
190 ; RV64B-NEXT: addi a2, zero, 1
191 ; RV64B-NEXT: sllw a1, a2, a1
192 ; RV64B-NEXT: or a0, a1, a0
195 ; RV64ZBS-LABEL: sbset_i32_no_mask:
197 ; RV64ZBS-NEXT: addi a2, zero, 1
198 ; RV64ZBS-NEXT: sllw a1, a2, a1
199 ; RV64ZBS-NEXT: or a0, a1, a0
202 %or = or i32 %shl, %a
206 define signext i32 @sbset_i32_load(i32* %p, i32 signext %b) nounwind {
207 ; RV64I-LABEL: sbset_i32_load:
209 ; RV64I-NEXT: lw a0, 0(a0)
210 ; RV64I-NEXT: addi a2, zero, 1
211 ; RV64I-NEXT: sllw a1, a2, a1
212 ; RV64I-NEXT: or a0, a1, a0
213 ; RV64I-NEXT: sext.w a0, a0
216 ; RV64B-LABEL: sbset_i32_load:
218 ; RV64B-NEXT: lw a0, 0(a0)
219 ; RV64B-NEXT: addi a2, zero, 1
220 ; RV64B-NEXT: sllw a1, a2, a1
221 ; RV64B-NEXT: or a0, a1, a0
222 ; RV64B-NEXT: sext.w a0, a0
225 ; RV64ZBS-LABEL: sbset_i32_load:
227 ; RV64ZBS-NEXT: lw a0, 0(a0)
228 ; RV64ZBS-NEXT: addi a2, zero, 1
229 ; RV64ZBS-NEXT: sllw a1, a2, a1
230 ; RV64ZBS-NEXT: or a0, a1, a0
231 ; RV64ZBS-NEXT: sext.w a0, a0
233 %a = load i32, i32* %p
235 %or = or i32 %shl, %a
239 ; We can use sbsetw for 1 << x by setting the first source to zero.
240 define signext i32 @sbset_i32_zero(i32 signext %a) nounwind {
241 ; RV64I-LABEL: sbset_i32_zero:
243 ; RV64I-NEXT: addi a1, zero, 1
244 ; RV64I-NEXT: sllw a0, a1, a0
247 ; RV64B-LABEL: sbset_i32_zero:
249 ; RV64B-NEXT: addi a1, zero, 1
250 ; RV64B-NEXT: sllw a0, a1, a0
253 ; RV64ZBS-LABEL: sbset_i32_zero:
255 ; RV64ZBS-NEXT: addi a1, zero, 1
256 ; RV64ZBS-NEXT: sllw a0, a1, a0
262 define i64 @sbset_i64(i64 %a, i64 %b) nounwind {
263 ; RV64I-LABEL: sbset_i64:
265 ; RV64I-NEXT: addi a2, zero, 1
266 ; RV64I-NEXT: sll a1, a2, a1
267 ; RV64I-NEXT: or a0, a1, a0
270 ; RV64B-LABEL: sbset_i64:
272 ; RV64B-NEXT: bset a0, a0, a1
275 ; RV64ZBS-LABEL: sbset_i64:
277 ; RV64ZBS-NEXT: bset a0, a0, a1
279 %conv = and i64 %b, 63
280 %shl = shl nuw i64 1, %conv
281 %or = or i64 %shl, %a
285 define i64 @sbset_i64_no_mask(i64 %a, i64 %b) nounwind {
286 ; RV64I-LABEL: sbset_i64_no_mask:
288 ; RV64I-NEXT: addi a2, zero, 1
289 ; RV64I-NEXT: sll a1, a2, a1
290 ; RV64I-NEXT: or a0, a1, a0
293 ; RV64B-LABEL: sbset_i64_no_mask:
295 ; RV64B-NEXT: bset a0, a0, a1
298 ; RV64ZBS-LABEL: sbset_i64_no_mask:
300 ; RV64ZBS-NEXT: bset a0, a0, a1
303 %or = or i64 %shl, %a
307 ; We can use sbsetw for 1 << x by setting the first source to zero.
308 define signext i64 @sbset_i64_zero(i64 signext %a) nounwind {
309 ; RV64I-LABEL: sbset_i64_zero:
311 ; RV64I-NEXT: addi a1, zero, 1
312 ; RV64I-NEXT: sll a0, a1, a0
315 ; RV64B-LABEL: sbset_i64_zero:
317 ; RV64B-NEXT: bset a0, zero, a0
320 ; RV64ZBS-LABEL: sbset_i64_zero:
322 ; RV64ZBS-NEXT: bset a0, zero, a0
328 define signext i32 @sbinv_i32(i32 signext %a, i32 signext %b) nounwind {
329 ; RV64I-LABEL: sbinv_i32:
331 ; RV64I-NEXT: addi a2, zero, 1
332 ; RV64I-NEXT: sllw a1, a2, a1
333 ; RV64I-NEXT: xor a0, a1, a0
336 ; RV64B-LABEL: sbinv_i32:
338 ; RV64B-NEXT: addi a2, zero, 1
339 ; RV64B-NEXT: sllw a1, a2, a1
340 ; RV64B-NEXT: xor a0, a1, a0
343 ; RV64ZBS-LABEL: sbinv_i32:
345 ; RV64ZBS-NEXT: addi a2, zero, 1
346 ; RV64ZBS-NEXT: sllw a1, a2, a1
347 ; RV64ZBS-NEXT: xor a0, a1, a0
349 %and = and i32 %b, 31
350 %shl = shl nuw i32 1, %and
351 %xor = xor i32 %shl, %a
355 define signext i32 @sbinv_i32_no_mask(i32 signext %a, i32 signext %b) nounwind {
356 ; RV64I-LABEL: sbinv_i32_no_mask:
358 ; RV64I-NEXT: addi a2, zero, 1
359 ; RV64I-NEXT: sllw a1, a2, a1
360 ; RV64I-NEXT: xor a0, a1, a0
363 ; RV64B-LABEL: sbinv_i32_no_mask:
365 ; RV64B-NEXT: addi a2, zero, 1
366 ; RV64B-NEXT: sllw a1, a2, a1
367 ; RV64B-NEXT: xor a0, a1, a0
370 ; RV64ZBS-LABEL: sbinv_i32_no_mask:
372 ; RV64ZBS-NEXT: addi a2, zero, 1
373 ; RV64ZBS-NEXT: sllw a1, a2, a1
374 ; RV64ZBS-NEXT: xor a0, a1, a0
377 %xor = xor i32 %shl, %a
381 define signext i32 @sbinv_i32_load(i32* %p, i32 signext %b) nounwind {
382 ; RV64I-LABEL: sbinv_i32_load:
384 ; RV64I-NEXT: lw a0, 0(a0)
385 ; RV64I-NEXT: addi a2, zero, 1
386 ; RV64I-NEXT: sllw a1, a2, a1
387 ; RV64I-NEXT: xor a0, a1, a0
388 ; RV64I-NEXT: sext.w a0, a0
391 ; RV64B-LABEL: sbinv_i32_load:
393 ; RV64B-NEXT: lw a0, 0(a0)
394 ; RV64B-NEXT: addi a2, zero, 1
395 ; RV64B-NEXT: sllw a1, a2, a1
396 ; RV64B-NEXT: xor a0, a1, a0
397 ; RV64B-NEXT: sext.w a0, a0
400 ; RV64ZBS-LABEL: sbinv_i32_load:
402 ; RV64ZBS-NEXT: lw a0, 0(a0)
403 ; RV64ZBS-NEXT: addi a2, zero, 1
404 ; RV64ZBS-NEXT: sllw a1, a2, a1
405 ; RV64ZBS-NEXT: xor a0, a1, a0
406 ; RV64ZBS-NEXT: sext.w a0, a0
408 %a = load i32, i32* %p
410 %xor = xor i32 %shl, %a
414 define i64 @sbinv_i64(i64 %a, i64 %b) nounwind {
415 ; RV64I-LABEL: sbinv_i64:
417 ; RV64I-NEXT: addi a2, zero, 1
418 ; RV64I-NEXT: sll a1, a2, a1
419 ; RV64I-NEXT: xor a0, a1, a0
422 ; RV64B-LABEL: sbinv_i64:
424 ; RV64B-NEXT: binv a0, a0, a1
427 ; RV64ZBS-LABEL: sbinv_i64:
429 ; RV64ZBS-NEXT: binv a0, a0, a1
431 %conv = and i64 %b, 63
432 %shl = shl nuw i64 1, %conv
433 %xor = xor i64 %shl, %a
437 define i64 @sbinv_i64_no_mask(i64 %a, i64 %b) nounwind {
438 ; RV64I-LABEL: sbinv_i64_no_mask:
440 ; RV64I-NEXT: addi a2, zero, 1
441 ; RV64I-NEXT: sll a1, a2, a1
442 ; RV64I-NEXT: xor a0, a1, a0
445 ; RV64B-LABEL: sbinv_i64_no_mask:
447 ; RV64B-NEXT: binv a0, a0, a1
450 ; RV64ZBS-LABEL: sbinv_i64_no_mask:
452 ; RV64ZBS-NEXT: binv a0, a0, a1
454 %shl = shl nuw i64 1, %b
455 %xor = xor i64 %shl, %a
459 define signext i32 @sbext_i32(i32 signext %a, i32 signext %b) nounwind {
460 ; RV64I-LABEL: sbext_i32:
462 ; RV64I-NEXT: srlw a0, a0, a1
463 ; RV64I-NEXT: andi a0, a0, 1
466 ; RV64B-LABEL: sbext_i32:
468 ; RV64B-NEXT: srlw a0, a0, a1
469 ; RV64B-NEXT: andi a0, a0, 1
472 ; RV64ZBS-LABEL: sbext_i32:
474 ; RV64ZBS-NEXT: srlw a0, a0, a1
475 ; RV64ZBS-NEXT: andi a0, a0, 1
477 %and = and i32 %b, 31
478 %shr = lshr i32 %a, %and
479 %and1 = and i32 %shr, 1
483 define signext i32 @sbext_i32_no_mask(i32 signext %a, i32 signext %b) nounwind {
484 ; RV64I-LABEL: sbext_i32_no_mask:
486 ; RV64I-NEXT: srlw a0, a0, a1
487 ; RV64I-NEXT: andi a0, a0, 1
490 ; RV64B-LABEL: sbext_i32_no_mask:
492 ; RV64B-NEXT: srlw a0, a0, a1
493 ; RV64B-NEXT: andi a0, a0, 1
496 ; RV64ZBS-LABEL: sbext_i32_no_mask:
498 ; RV64ZBS-NEXT: srlw a0, a0, a1
499 ; RV64ZBS-NEXT: andi a0, a0, 1
501 %shr = lshr i32 %a, %b
502 %and1 = and i32 %shr, 1
506 define i64 @sbext_i64(i64 %a, i64 %b) nounwind {
507 ; RV64I-LABEL: sbext_i64:
509 ; RV64I-NEXT: srl a0, a0, a1
510 ; RV64I-NEXT: andi a0, a0, 1
513 ; RV64B-LABEL: sbext_i64:
515 ; RV64B-NEXT: bext a0, a0, a1
518 ; RV64ZBS-LABEL: sbext_i64:
520 ; RV64ZBS-NEXT: bext a0, a0, a1
522 %conv = and i64 %b, 63
523 %shr = lshr i64 %a, %conv
524 %and1 = and i64 %shr, 1
528 define i64 @sbext_i64_no_mask(i64 %a, i64 %b) nounwind {
529 ; RV64I-LABEL: sbext_i64_no_mask:
531 ; RV64I-NEXT: srl a0, a0, a1
532 ; RV64I-NEXT: andi a0, a0, 1
535 ; RV64B-LABEL: sbext_i64_no_mask:
537 ; RV64B-NEXT: bext a0, a0, a1
540 ; RV64ZBS-LABEL: sbext_i64_no_mask:
542 ; RV64ZBS-NEXT: bext a0, a0, a1
544 %shr = lshr i64 %a, %b
545 %and1 = and i64 %shr, 1
549 define signext i32 @sbexti_i32(i32 signext %a) nounwind {
550 ; RV64I-LABEL: sbexti_i32:
552 ; RV64I-NEXT: srli a0, a0, 5
553 ; RV64I-NEXT: andi a0, a0, 1
556 ; RV64B-LABEL: sbexti_i32:
558 ; RV64B-NEXT: bexti a0, a0, 5
561 ; RV64ZBS-LABEL: sbexti_i32:
563 ; RV64ZBS-NEXT: bexti a0, a0, 5
565 %shr = lshr i32 %a, 5
566 %and = and i32 %shr, 1
570 define i64 @sbexti_i64(i64 %a) nounwind {
571 ; RV64I-LABEL: sbexti_i64:
573 ; RV64I-NEXT: srli a0, a0, 5
574 ; RV64I-NEXT: andi a0, a0, 1
577 ; RV64B-LABEL: sbexti_i64:
579 ; RV64B-NEXT: bexti a0, a0, 5
582 ; RV64ZBS-LABEL: sbexti_i64:
584 ; RV64ZBS-NEXT: bexti a0, a0, 5
586 %shr = lshr i64 %a, 5
587 %and = and i64 %shr, 1
591 define signext i32 @sbclri_i32_10(i32 signext %a) nounwind {
592 ; RV64I-LABEL: sbclri_i32_10:
594 ; RV64I-NEXT: andi a0, a0, -1025
597 ; RV64B-LABEL: sbclri_i32_10:
599 ; RV64B-NEXT: andi a0, a0, -1025
602 ; RV64ZBS-LABEL: sbclri_i32_10:
604 ; RV64ZBS-NEXT: andi a0, a0, -1025
606 %and = and i32 %a, -1025
610 define signext i32 @sbclri_i32_11(i32 signext %a) nounwind {
611 ; RV64I-LABEL: sbclri_i32_11:
613 ; RV64I-NEXT: lui a1, 1048575
614 ; RV64I-NEXT: addiw a1, a1, 2047
615 ; RV64I-NEXT: and a0, a0, a1
618 ; RV64B-LABEL: sbclri_i32_11:
620 ; RV64B-NEXT: bclri a0, a0, 11
623 ; RV64ZBS-LABEL: sbclri_i32_11:
625 ; RV64ZBS-NEXT: bclri a0, a0, 11
627 %and = and i32 %a, -2049
631 define signext i32 @sbclri_i32_30(i32 signext %a) nounwind {
632 ; RV64I-LABEL: sbclri_i32_30:
634 ; RV64I-NEXT: lui a1, 786432
635 ; RV64I-NEXT: addiw a1, a1, -1
636 ; RV64I-NEXT: and a0, a0, a1
639 ; RV64B-LABEL: sbclri_i32_30:
641 ; RV64B-NEXT: bclri a0, a0, 30
644 ; RV64ZBS-LABEL: sbclri_i32_30:
646 ; RV64ZBS-NEXT: bclri a0, a0, 30
648 %and = and i32 %a, -1073741825
652 define signext i32 @sbclri_i32_31(i32 signext %a) nounwind {
653 ; RV64I-LABEL: sbclri_i32_31:
655 ; RV64I-NEXT: lui a1, 524288
656 ; RV64I-NEXT: addiw a1, a1, -1
657 ; RV64I-NEXT: and a0, a0, a1
660 ; RV64B-LABEL: sbclri_i32_31:
662 ; RV64B-NEXT: lui a1, 524288
663 ; RV64B-NEXT: addiw a1, a1, -1
664 ; RV64B-NEXT: and a0, a0, a1
667 ; RV64ZBS-LABEL: sbclri_i32_31:
669 ; RV64ZBS-NEXT: lui a1, 524288
670 ; RV64ZBS-NEXT: addiw a1, a1, -1
671 ; RV64ZBS-NEXT: and a0, a0, a1
673 %and = and i32 %a, -2147483649
677 define i64 @sbclri_i64_10(i64 %a) nounwind {
678 ; RV64I-LABEL: sbclri_i64_10:
680 ; RV64I-NEXT: andi a0, a0, -1025
683 ; RV64B-LABEL: sbclri_i64_10:
685 ; RV64B-NEXT: andi a0, a0, -1025
688 ; RV64ZBS-LABEL: sbclri_i64_10:
690 ; RV64ZBS-NEXT: andi a0, a0, -1025
692 %and = and i64 %a, -1025
696 define i64 @sbclri_i64_11(i64 %a) nounwind {
697 ; RV64I-LABEL: sbclri_i64_11:
699 ; RV64I-NEXT: lui a1, 1048575
700 ; RV64I-NEXT: addiw a1, a1, 2047
701 ; RV64I-NEXT: and a0, a0, a1
704 ; RV64B-LABEL: sbclri_i64_11:
706 ; RV64B-NEXT: bclri a0, a0, 11
709 ; RV64ZBS-LABEL: sbclri_i64_11:
711 ; RV64ZBS-NEXT: bclri a0, a0, 11
713 %and = and i64 %a, -2049
717 define i64 @sbclri_i64_30(i64 %a) nounwind {
718 ; RV64I-LABEL: sbclri_i64_30:
720 ; RV64I-NEXT: lui a1, 786432
721 ; RV64I-NEXT: addiw a1, a1, -1
722 ; RV64I-NEXT: and a0, a0, a1
725 ; RV64B-LABEL: sbclri_i64_30:
727 ; RV64B-NEXT: bclri a0, a0, 30
730 ; RV64ZBS-LABEL: sbclri_i64_30:
732 ; RV64ZBS-NEXT: bclri a0, a0, 30
734 %and = and i64 %a, -1073741825
738 define i64 @sbclri_i64_31(i64 %a) nounwind {
739 ; RV64I-LABEL: sbclri_i64_31:
741 ; RV64I-NEXT: addi a1, zero, -1
742 ; RV64I-NEXT: slli a1, a1, 31
743 ; RV64I-NEXT: addi a1, a1, -1
744 ; RV64I-NEXT: and a0, a0, a1
747 ; RV64B-LABEL: sbclri_i64_31:
749 ; RV64B-NEXT: bclri a0, a0, 31
752 ; RV64ZBS-LABEL: sbclri_i64_31:
754 ; RV64ZBS-NEXT: bclri a0, a0, 31
756 %and = and i64 %a, -2147483649
760 define i64 @sbclri_i64_62(i64 %a) nounwind {
761 ; RV64I-LABEL: sbclri_i64_62:
763 ; RV64I-NEXT: addi a1, zero, -1
764 ; RV64I-NEXT: slli a1, a1, 62
765 ; RV64I-NEXT: addi a1, a1, -1
766 ; RV64I-NEXT: and a0, a0, a1
769 ; RV64B-LABEL: sbclri_i64_62:
771 ; RV64B-NEXT: bclri a0, a0, 62
774 ; RV64ZBS-LABEL: sbclri_i64_62:
776 ; RV64ZBS-NEXT: bclri a0, a0, 62
778 %and = and i64 %a, -4611686018427387905
782 define i64 @sbclri_i64_63(i64 %a) nounwind {
783 ; RV64I-LABEL: sbclri_i64_63:
785 ; RV64I-NEXT: addi a1, zero, -1
786 ; RV64I-NEXT: srli a1, a1, 1
787 ; RV64I-NEXT: and a0, a0, a1
790 ; RV64B-LABEL: sbclri_i64_63:
792 ; RV64B-NEXT: bclri a0, a0, 63
795 ; RV64ZBS-LABEL: sbclri_i64_63:
797 ; RV64ZBS-NEXT: bclri a0, a0, 63
799 %and = and i64 %a, -9223372036854775809
803 define i64 @sbclri_i64_large0(i64 %a) nounwind {
804 ; RV64I-LABEL: sbclri_i64_large0:
806 ; RV64I-NEXT: lui a1, 1044480
807 ; RV64I-NEXT: addiw a1, a1, -256
808 ; RV64I-NEXT: and a0, a0, a1
811 ; RV64B-LABEL: sbclri_i64_large0:
813 ; RV64B-NEXT: andi a0, a0, -256
814 ; RV64B-NEXT: bclri a0, a0, 24
817 ; RV64ZBS-LABEL: sbclri_i64_large0:
819 ; RV64ZBS-NEXT: andi a0, a0, -256
820 ; RV64ZBS-NEXT: bclri a0, a0, 24
822 %and = and i64 %a, -16777472
826 define i64 @sbclri_i64_large1(i64 %a) nounwind {
827 ; RV64I-LABEL: sbclri_i64_large1:
829 ; RV64I-NEXT: lui a1, 1044464
830 ; RV64I-NEXT: addiw a1, a1, -1
831 ; RV64I-NEXT: and a0, a0, a1
834 ; RV64B-LABEL: sbclri_i64_large1:
836 ; RV64B-NEXT: bclri a0, a0, 16
837 ; RV64B-NEXT: bclri a0, a0, 24
840 ; RV64ZBS-LABEL: sbclri_i64_large1:
842 ; RV64ZBS-NEXT: bclri a0, a0, 16
843 ; RV64ZBS-NEXT: bclri a0, a0, 24
845 %and = and i64 %a, -16842753
849 define signext i32 @sbseti_i32_10(i32 signext %a) nounwind {
850 ; RV64I-LABEL: sbseti_i32_10:
852 ; RV64I-NEXT: ori a0, a0, 1024
855 ; RV64B-LABEL: sbseti_i32_10:
857 ; RV64B-NEXT: ori a0, a0, 1024
860 ; RV64ZBS-LABEL: sbseti_i32_10:
862 ; RV64ZBS-NEXT: ori a0, a0, 1024
864 %or = or i32 %a, 1024
868 define signext i32 @sbseti_i32_11(i32 signext %a) nounwind {
869 ; RV64I-LABEL: sbseti_i32_11:
871 ; RV64I-NEXT: lui a1, 1
872 ; RV64I-NEXT: addiw a1, a1, -2048
873 ; RV64I-NEXT: or a0, a0, a1
876 ; RV64B-LABEL: sbseti_i32_11:
878 ; RV64B-NEXT: bseti a0, a0, 11
881 ; RV64ZBS-LABEL: sbseti_i32_11:
883 ; RV64ZBS-NEXT: bseti a0, a0, 11
885 %or = or i32 %a, 2048
889 define signext i32 @sbseti_i32_30(i32 signext %a) nounwind {
890 ; RV64I-LABEL: sbseti_i32_30:
892 ; RV64I-NEXT: lui a1, 262144
893 ; RV64I-NEXT: or a0, a0, a1
896 ; RV64B-LABEL: sbseti_i32_30:
898 ; RV64B-NEXT: bseti a0, a0, 30
901 ; RV64ZBS-LABEL: sbseti_i32_30:
903 ; RV64ZBS-NEXT: bseti a0, a0, 30
905 %or = or i32 %a, 1073741824
909 define signext i32 @sbseti_i32_31(i32 signext %a) nounwind {
910 ; RV64I-LABEL: sbseti_i32_31:
912 ; RV64I-NEXT: lui a1, 524288
913 ; RV64I-NEXT: or a0, a0, a1
916 ; RV64B-LABEL: sbseti_i32_31:
918 ; RV64B-NEXT: lui a1, 524288
919 ; RV64B-NEXT: or a0, a0, a1
922 ; RV64ZBS-LABEL: sbseti_i32_31:
924 ; RV64ZBS-NEXT: lui a1, 524288
925 ; RV64ZBS-NEXT: or a0, a0, a1
927 %or = or i32 %a, 2147483648
931 define i64 @sbseti_i64_10(i64 %a) nounwind {
932 ; RV64I-LABEL: sbseti_i64_10:
934 ; RV64I-NEXT: ori a0, a0, 1024
937 ; RV64B-LABEL: sbseti_i64_10:
939 ; RV64B-NEXT: ori a0, a0, 1024
942 ; RV64ZBS-LABEL: sbseti_i64_10:
944 ; RV64ZBS-NEXT: ori a0, a0, 1024
946 %or = or i64 %a, 1024
950 define i64 @sbseti_i64_11(i64 %a) nounwind {
951 ; RV64I-LABEL: sbseti_i64_11:
953 ; RV64I-NEXT: lui a1, 1
954 ; RV64I-NEXT: addiw a1, a1, -2048
955 ; RV64I-NEXT: or a0, a0, a1
958 ; RV64B-LABEL: sbseti_i64_11:
960 ; RV64B-NEXT: bseti a0, a0, 11
963 ; RV64ZBS-LABEL: sbseti_i64_11:
965 ; RV64ZBS-NEXT: bseti a0, a0, 11
967 %or = or i64 %a, 2048
971 define i64 @sbseti_i64_30(i64 %a) nounwind {
972 ; RV64I-LABEL: sbseti_i64_30:
974 ; RV64I-NEXT: lui a1, 262144
975 ; RV64I-NEXT: or a0, a0, a1
978 ; RV64B-LABEL: sbseti_i64_30:
980 ; RV64B-NEXT: bseti a0, a0, 30
983 ; RV64ZBS-LABEL: sbseti_i64_30:
985 ; RV64ZBS-NEXT: bseti a0, a0, 30
987 %or = or i64 %a, 1073741824
991 define i64 @sbseti_i64_31(i64 %a) nounwind {
992 ; RV64I-LABEL: sbseti_i64_31:
994 ; RV64I-NEXT: addi a1, zero, 1
995 ; RV64I-NEXT: slli a1, a1, 31
996 ; RV64I-NEXT: or a0, a0, a1
999 ; RV64B-LABEL: sbseti_i64_31:
1001 ; RV64B-NEXT: bseti a0, a0, 31
1004 ; RV64ZBS-LABEL: sbseti_i64_31:
1006 ; RV64ZBS-NEXT: bseti a0, a0, 31
1008 %or = or i64 %a, 2147483648
1012 define i64 @sbseti_i64_62(i64 %a) nounwind {
1013 ; RV64I-LABEL: sbseti_i64_62:
1015 ; RV64I-NEXT: addi a1, zero, 1
1016 ; RV64I-NEXT: slli a1, a1, 62
1017 ; RV64I-NEXT: or a0, a0, a1
1020 ; RV64B-LABEL: sbseti_i64_62:
1022 ; RV64B-NEXT: bseti a0, a0, 62
1025 ; RV64ZBS-LABEL: sbseti_i64_62:
1027 ; RV64ZBS-NEXT: bseti a0, a0, 62
1029 %or = or i64 %a, 4611686018427387904
1033 define i64 @sbseti_i64_63(i64 %a) nounwind {
1034 ; RV64I-LABEL: sbseti_i64_63:
1036 ; RV64I-NEXT: addi a1, zero, -1
1037 ; RV64I-NEXT: slli a1, a1, 63
1038 ; RV64I-NEXT: or a0, a0, a1
1041 ; RV64B-LABEL: sbseti_i64_63:
1043 ; RV64B-NEXT: bseti a0, a0, 63
1046 ; RV64ZBS-LABEL: sbseti_i64_63:
1048 ; RV64ZBS-NEXT: bseti a0, a0, 63
1050 %or = or i64 %a, 9223372036854775808
1054 define signext i32 @sbinvi_i32_10(i32 signext %a) nounwind {
1055 ; RV64I-LABEL: sbinvi_i32_10:
1057 ; RV64I-NEXT: xori a0, a0, 1024
1060 ; RV64B-LABEL: sbinvi_i32_10:
1062 ; RV64B-NEXT: xori a0, a0, 1024
1065 ; RV64ZBS-LABEL: sbinvi_i32_10:
1067 ; RV64ZBS-NEXT: xori a0, a0, 1024
1069 %xor = xor i32 %a, 1024
1073 define signext i32 @sbinvi_i32_11(i32 signext %a) nounwind {
1074 ; RV64I-LABEL: sbinvi_i32_11:
1076 ; RV64I-NEXT: lui a1, 1
1077 ; RV64I-NEXT: addiw a1, a1, -2048
1078 ; RV64I-NEXT: xor a0, a0, a1
1081 ; RV64B-LABEL: sbinvi_i32_11:
1083 ; RV64B-NEXT: binvi a0, a0, 11
1086 ; RV64ZBS-LABEL: sbinvi_i32_11:
1088 ; RV64ZBS-NEXT: binvi a0, a0, 11
1090 %xor = xor i32 %a, 2048
1094 define signext i32 @sbinvi_i32_30(i32 signext %a) nounwind {
1095 ; RV64I-LABEL: sbinvi_i32_30:
1097 ; RV64I-NEXT: lui a1, 262144
1098 ; RV64I-NEXT: xor a0, a0, a1
1101 ; RV64B-LABEL: sbinvi_i32_30:
1103 ; RV64B-NEXT: binvi a0, a0, 30
1106 ; RV64ZBS-LABEL: sbinvi_i32_30:
1108 ; RV64ZBS-NEXT: binvi a0, a0, 30
1110 %xor = xor i32 %a, 1073741824
1114 define signext i32 @sbinvi_i32_31(i32 signext %a) nounwind {
1115 ; RV64I-LABEL: sbinvi_i32_31:
1117 ; RV64I-NEXT: lui a1, 524288
1118 ; RV64I-NEXT: xor a0, a0, a1
1121 ; RV64B-LABEL: sbinvi_i32_31:
1123 ; RV64B-NEXT: lui a1, 524288
1124 ; RV64B-NEXT: xor a0, a0, a1
1127 ; RV64ZBS-LABEL: sbinvi_i32_31:
1129 ; RV64ZBS-NEXT: lui a1, 524288
1130 ; RV64ZBS-NEXT: xor a0, a0, a1
1132 %xor = xor i32 %a, 2147483648
1136 define i64 @sbinvi_i64_10(i64 %a) nounwind {
1137 ; RV64I-LABEL: sbinvi_i64_10:
1139 ; RV64I-NEXT: xori a0, a0, 1024
1142 ; RV64B-LABEL: sbinvi_i64_10:
1144 ; RV64B-NEXT: xori a0, a0, 1024
1147 ; RV64ZBS-LABEL: sbinvi_i64_10:
1149 ; RV64ZBS-NEXT: xori a0, a0, 1024
1151 %xor = xor i64 %a, 1024
1155 define i64 @sbinvi_i64_11(i64 %a) nounwind {
1156 ; RV64I-LABEL: sbinvi_i64_11:
1158 ; RV64I-NEXT: lui a1, 1
1159 ; RV64I-NEXT: addiw a1, a1, -2048
1160 ; RV64I-NEXT: xor a0, a0, a1
1163 ; RV64B-LABEL: sbinvi_i64_11:
1165 ; RV64B-NEXT: binvi a0, a0, 11
1168 ; RV64ZBS-LABEL: sbinvi_i64_11:
1170 ; RV64ZBS-NEXT: binvi a0, a0, 11
1172 %xor = xor i64 %a, 2048
1176 define i64 @sbinvi_i64_30(i64 %a) nounwind {
1177 ; RV64I-LABEL: sbinvi_i64_30:
1179 ; RV64I-NEXT: lui a1, 262144
1180 ; RV64I-NEXT: xor a0, a0, a1
1183 ; RV64B-LABEL: sbinvi_i64_30:
1185 ; RV64B-NEXT: binvi a0, a0, 30
1188 ; RV64ZBS-LABEL: sbinvi_i64_30:
1190 ; RV64ZBS-NEXT: binvi a0, a0, 30
1192 %xor = xor i64 %a, 1073741824
1196 define i64 @sbinvi_i64_31(i64 %a) nounwind {
1197 ; RV64I-LABEL: sbinvi_i64_31:
1199 ; RV64I-NEXT: addi a1, zero, 1
1200 ; RV64I-NEXT: slli a1, a1, 31
1201 ; RV64I-NEXT: xor a0, a0, a1
1204 ; RV64B-LABEL: sbinvi_i64_31:
1206 ; RV64B-NEXT: binvi a0, a0, 31
1209 ; RV64ZBS-LABEL: sbinvi_i64_31:
1211 ; RV64ZBS-NEXT: binvi a0, a0, 31
1213 %xor = xor i64 %a, 2147483648
1217 define i64 @sbinvi_i64_62(i64 %a) nounwind {
1218 ; RV64I-LABEL: sbinvi_i64_62:
1220 ; RV64I-NEXT: addi a1, zero, 1
1221 ; RV64I-NEXT: slli a1, a1, 62
1222 ; RV64I-NEXT: xor a0, a0, a1
1225 ; RV64B-LABEL: sbinvi_i64_62:
1227 ; RV64B-NEXT: binvi a0, a0, 62
1230 ; RV64ZBS-LABEL: sbinvi_i64_62:
1232 ; RV64ZBS-NEXT: binvi a0, a0, 62
1234 %xor = xor i64 %a, 4611686018427387904
1238 define i64 @sbinvi_i64_63(i64 %a) nounwind {
1239 ; RV64I-LABEL: sbinvi_i64_63:
1241 ; RV64I-NEXT: addi a1, zero, -1
1242 ; RV64I-NEXT: slli a1, a1, 63
1243 ; RV64I-NEXT: xor a0, a0, a1
1246 ; RV64B-LABEL: sbinvi_i64_63:
1248 ; RV64B-NEXT: binvi a0, a0, 63
1251 ; RV64ZBS-LABEL: sbinvi_i64_63:
1253 ; RV64ZBS-NEXT: binvi a0, a0, 63
1255 %xor = xor i64 %a, 9223372036854775808
1259 define i64 @xor_i64_large(i64 %a) nounwind {
1260 ; RV64I-LABEL: xor_i64_large:
1262 ; RV64I-NEXT: addi a1, zero, 1
1263 ; RV64I-NEXT: slli a1, a1, 32
1264 ; RV64I-NEXT: addi a1, a1, 1
1265 ; RV64I-NEXT: xor a0, a0, a1
1268 ; RV64B-LABEL: xor_i64_large:
1270 ; RV64B-NEXT: binvi a0, a0, 0
1271 ; RV64B-NEXT: binvi a0, a0, 32
1274 ; RV64ZBS-LABEL: xor_i64_large:
1276 ; RV64ZBS-NEXT: binvi a0, a0, 0
1277 ; RV64ZBS-NEXT: binvi a0, a0, 32
1279 %xor = xor i64 %a, 4294967297
1283 define i64 @xor_i64_4099(i64 %a) nounwind {
1284 ; RV64I-LABEL: xor_i64_4099:
1286 ; RV64I-NEXT: lui a1, 1
1287 ; RV64I-NEXT: addiw a1, a1, 3
1288 ; RV64I-NEXT: xor a0, a0, a1
1291 ; RV64B-LABEL: xor_i64_4099:
1293 ; RV64B-NEXT: xori a0, a0, 3
1294 ; RV64B-NEXT: binvi a0, a0, 12
1297 ; RV64ZBS-LABEL: xor_i64_4099:
1299 ; RV64ZBS-NEXT: xori a0, a0, 3
1300 ; RV64ZBS-NEXT: binvi a0, a0, 12
1302 %xor = xor i64 %a, 4099
1306 define i64 @xor_i64_96(i64 %a) nounwind {
1307 ; RV64I-LABEL: xor_i64_96:
1309 ; RV64I-NEXT: xori a0, a0, 96
1312 ; RV64B-LABEL: xor_i64_96:
1314 ; RV64B-NEXT: xori a0, a0, 96
1317 ; RV64ZBS-LABEL: xor_i64_96:
1319 ; RV64ZBS-NEXT: xori a0, a0, 96
1321 %xor = xor i64 %a, 96
1325 define i64 @or_i64_large(i64 %a) nounwind {
1326 ; RV64I-LABEL: or_i64_large:
1328 ; RV64I-NEXT: addi a1, zero, 1
1329 ; RV64I-NEXT: slli a1, a1, 32
1330 ; RV64I-NEXT: addi a1, a1, 1
1331 ; RV64I-NEXT: or a0, a0, a1
1334 ; RV64B-LABEL: or_i64_large:
1336 ; RV64B-NEXT: bseti a0, a0, 0
1337 ; RV64B-NEXT: bseti a0, a0, 32
1340 ; RV64ZBS-LABEL: or_i64_large:
1342 ; RV64ZBS-NEXT: bseti a0, a0, 0
1343 ; RV64ZBS-NEXT: bseti a0, a0, 32
1345 %or = or i64 %a, 4294967297
1349 define i64 @xor_i64_66901(i64 %a) nounwind {
1350 ; RV64I-LABEL: xor_i64_66901:
1352 ; RV64I-NEXT: lui a1, 16
1353 ; RV64I-NEXT: addiw a1, a1, 1365
1354 ; RV64I-NEXT: xor a0, a0, a1
1357 ; RV64B-LABEL: xor_i64_66901:
1359 ; RV64B-NEXT: xori a0, a0, 1365
1360 ; RV64B-NEXT: binvi a0, a0, 16
1363 ; RV64ZBS-LABEL: xor_i64_66901:
1365 ; RV64ZBS-NEXT: xori a0, a0, 1365
1366 ; RV64ZBS-NEXT: binvi a0, a0, 16
1368 %xor = xor i64 %a, 66901
1372 define i64 @or_i64_4099(i64 %a) nounwind {
1373 ; RV64I-LABEL: or_i64_4099:
1375 ; RV64I-NEXT: lui a1, 1
1376 ; RV64I-NEXT: addiw a1, a1, 3
1377 ; RV64I-NEXT: or a0, a0, a1
1380 ; RV64B-LABEL: or_i64_4099:
1382 ; RV64B-NEXT: ori a0, a0, 3
1383 ; RV64B-NEXT: bseti a0, a0, 12
1386 ; RV64ZBS-LABEL: or_i64_4099:
1388 ; RV64ZBS-NEXT: ori a0, a0, 3
1389 ; RV64ZBS-NEXT: bseti a0, a0, 12
1391 %or = or i64 %a, 4099
1395 define i64 @or_i64_96(i64 %a) nounwind {
1396 ; RV64I-LABEL: or_i64_96:
1398 ; RV64I-NEXT: ori a0, a0, 96
1401 ; RV64B-LABEL: or_i64_96:
1403 ; RV64B-NEXT: ori a0, a0, 96
1406 ; RV64ZBS-LABEL: or_i64_96:
1408 ; RV64ZBS-NEXT: ori a0, a0, 96
1414 define i64 @or_i64_66901(i64 %a) nounwind {
1415 ; RV64I-LABEL: or_i64_66901:
1417 ; RV64I-NEXT: lui a1, 16
1418 ; RV64I-NEXT: addiw a1, a1, 1365
1419 ; RV64I-NEXT: or a0, a0, a1
1422 ; RV64B-LABEL: or_i64_66901:
1424 ; RV64B-NEXT: ori a0, a0, 1365
1425 ; RV64B-NEXT: bseti a0, a0, 16
1428 ; RV64ZBS-LABEL: or_i64_66901:
1430 ; RV64ZBS-NEXT: ori a0, a0, 1365
1431 ; RV64ZBS-NEXT: bseti a0, a0, 16
1433 %or = or i64 %a, 66901