1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+m -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32I
4 ; RUN: llc -mtriple=riscv32 -mattr=+m,+experimental-b -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV32B
6 ; RUN: llc -mtriple=riscv32 -mattr=+m,+experimental-zba -verify-machineinstrs < %s \
7 ; RUN: | FileCheck %s -check-prefix=RV32ZBA
9 define signext i16 @sh1add(i64 %0, i16* %1) {
10 ; RV32I-LABEL: sh1add:
12 ; RV32I-NEXT: slli a0, a0, 1
13 ; RV32I-NEXT: add a0, a2, a0
14 ; RV32I-NEXT: lh a0, 0(a0)
17 ; RV32B-LABEL: sh1add:
19 ; RV32B-NEXT: sh1add a0, a0, a2
20 ; RV32B-NEXT: lh a0, 0(a0)
23 ; RV32ZBA-LABEL: sh1add:
25 ; RV32ZBA-NEXT: sh1add a0, a0, a2
26 ; RV32ZBA-NEXT: lh a0, 0(a0)
28 %3 = getelementptr inbounds i16, i16* %1, i64 %0
29 %4 = load i16, i16* %3
33 define i32 @sh2add(i64 %0, i32* %1) {
34 ; RV32I-LABEL: sh2add:
36 ; RV32I-NEXT: slli a0, a0, 2
37 ; RV32I-NEXT: add a0, a2, a0
38 ; RV32I-NEXT: lw a0, 0(a0)
41 ; RV32B-LABEL: sh2add:
43 ; RV32B-NEXT: sh2add a0, a0, a2
44 ; RV32B-NEXT: lw a0, 0(a0)
47 ; RV32ZBA-LABEL: sh2add:
49 ; RV32ZBA-NEXT: sh2add a0, a0, a2
50 ; RV32ZBA-NEXT: lw a0, 0(a0)
52 %3 = getelementptr inbounds i32, i32* %1, i64 %0
53 %4 = load i32, i32* %3
57 define i64 @sh3add(i64 %0, i64* %1) {
58 ; RV32I-LABEL: sh3add:
60 ; RV32I-NEXT: slli a0, a0, 3
61 ; RV32I-NEXT: add a1, a2, a0
62 ; RV32I-NEXT: lw a0, 0(a1)
63 ; RV32I-NEXT: lw a1, 4(a1)
66 ; RV32B-LABEL: sh3add:
68 ; RV32B-NEXT: sh3add a1, a0, a2
69 ; RV32B-NEXT: lw a0, 0(a1)
70 ; RV32B-NEXT: lw a1, 4(a1)
73 ; RV32ZBA-LABEL: sh3add:
75 ; RV32ZBA-NEXT: sh3add a1, a0, a2
76 ; RV32ZBA-NEXT: lw a0, 0(a1)
77 ; RV32ZBA-NEXT: lw a1, 4(a1)
79 %3 = getelementptr inbounds i64, i64* %1, i64 %0
80 %4 = load i64, i64* %3
84 define i32 @addmul6(i32 %a, i32 %b) {
85 ; RV32I-LABEL: addmul6:
87 ; RV32I-NEXT: addi a2, zero, 6
88 ; RV32I-NEXT: mul a0, a0, a2
89 ; RV32I-NEXT: add a0, a0, a1
92 ; RV32B-LABEL: addmul6:
94 ; RV32B-NEXT: sh1add a0, a0, a0
95 ; RV32B-NEXT: sh1add a0, a0, a1
98 ; RV32ZBA-LABEL: addmul6:
100 ; RV32ZBA-NEXT: sh1add a0, a0, a0
101 ; RV32ZBA-NEXT: sh1add a0, a0, a1
108 define i32 @addmul10(i32 %a, i32 %b) {
109 ; RV32I-LABEL: addmul10:
111 ; RV32I-NEXT: addi a2, zero, 10
112 ; RV32I-NEXT: mul a0, a0, a2
113 ; RV32I-NEXT: add a0, a0, a1
116 ; RV32B-LABEL: addmul10:
118 ; RV32B-NEXT: sh2add a0, a0, a0
119 ; RV32B-NEXT: sh1add a0, a0, a1
122 ; RV32ZBA-LABEL: addmul10:
124 ; RV32ZBA-NEXT: sh2add a0, a0, a0
125 ; RV32ZBA-NEXT: sh1add a0, a0, a1
132 define i32 @addmul12(i32 %a, i32 %b) {
133 ; RV32I-LABEL: addmul12:
135 ; RV32I-NEXT: addi a2, zero, 12
136 ; RV32I-NEXT: mul a0, a0, a2
137 ; RV32I-NEXT: add a0, a0, a1
140 ; RV32B-LABEL: addmul12:
142 ; RV32B-NEXT: sh1add a0, a0, a0
143 ; RV32B-NEXT: sh2add a0, a0, a1
146 ; RV32ZBA-LABEL: addmul12:
148 ; RV32ZBA-NEXT: sh1add a0, a0, a0
149 ; RV32ZBA-NEXT: sh2add a0, a0, a1
156 define i32 @addmul18(i32 %a, i32 %b) {
157 ; RV32I-LABEL: addmul18:
159 ; RV32I-NEXT: addi a2, zero, 18
160 ; RV32I-NEXT: mul a0, a0, a2
161 ; RV32I-NEXT: add a0, a0, a1
164 ; RV32B-LABEL: addmul18:
166 ; RV32B-NEXT: sh3add a0, a0, a0
167 ; RV32B-NEXT: sh1add a0, a0, a1
170 ; RV32ZBA-LABEL: addmul18:
172 ; RV32ZBA-NEXT: sh3add a0, a0, a0
173 ; RV32ZBA-NEXT: sh1add a0, a0, a1
180 define i32 @addmul20(i32 %a, i32 %b) {
181 ; RV32I-LABEL: addmul20:
183 ; RV32I-NEXT: addi a2, zero, 20
184 ; RV32I-NEXT: mul a0, a0, a2
185 ; RV32I-NEXT: add a0, a0, a1
188 ; RV32B-LABEL: addmul20:
190 ; RV32B-NEXT: sh2add a0, a0, a0
191 ; RV32B-NEXT: sh2add a0, a0, a1
194 ; RV32ZBA-LABEL: addmul20:
196 ; RV32ZBA-NEXT: sh2add a0, a0, a0
197 ; RV32ZBA-NEXT: sh2add a0, a0, a1
204 define i32 @addmul24(i32 %a, i32 %b) {
205 ; RV32I-LABEL: addmul24:
207 ; RV32I-NEXT: addi a2, zero, 24
208 ; RV32I-NEXT: mul a0, a0, a2
209 ; RV32I-NEXT: add a0, a0, a1
212 ; RV32B-LABEL: addmul24:
214 ; RV32B-NEXT: sh1add a0, a0, a0
215 ; RV32B-NEXT: sh3add a0, a0, a1
218 ; RV32ZBA-LABEL: addmul24:
220 ; RV32ZBA-NEXT: sh1add a0, a0, a0
221 ; RV32ZBA-NEXT: sh3add a0, a0, a1
228 define i32 @addmul36(i32 %a, i32 %b) {
229 ; RV32I-LABEL: addmul36:
231 ; RV32I-NEXT: addi a2, zero, 36
232 ; RV32I-NEXT: mul a0, a0, a2
233 ; RV32I-NEXT: add a0, a0, a1
236 ; RV32B-LABEL: addmul36:
238 ; RV32B-NEXT: sh3add a0, a0, a0
239 ; RV32B-NEXT: sh2add a0, a0, a1
242 ; RV32ZBA-LABEL: addmul36:
244 ; RV32ZBA-NEXT: sh3add a0, a0, a0
245 ; RV32ZBA-NEXT: sh2add a0, a0, a1
252 define i32 @addmul40(i32 %a, i32 %b) {
253 ; RV32I-LABEL: addmul40:
255 ; RV32I-NEXT: addi a2, zero, 40
256 ; RV32I-NEXT: mul a0, a0, a2
257 ; RV32I-NEXT: add a0, a0, a1
260 ; RV32B-LABEL: addmul40:
262 ; RV32B-NEXT: sh2add a0, a0, a0
263 ; RV32B-NEXT: sh3add a0, a0, a1
266 ; RV32ZBA-LABEL: addmul40:
268 ; RV32ZBA-NEXT: sh2add a0, a0, a0
269 ; RV32ZBA-NEXT: sh3add a0, a0, a1
276 define i32 @addmul72(i32 %a, i32 %b) {
277 ; RV32I-LABEL: addmul72:
279 ; RV32I-NEXT: addi a2, zero, 72
280 ; RV32I-NEXT: mul a0, a0, a2
281 ; RV32I-NEXT: add a0, a0, a1
284 ; RV32B-LABEL: addmul72:
286 ; RV32B-NEXT: sh3add a0, a0, a0
287 ; RV32B-NEXT: sh3add a0, a0, a1
290 ; RV32ZBA-LABEL: addmul72:
292 ; RV32ZBA-NEXT: sh3add a0, a0, a0
293 ; RV32ZBA-NEXT: sh3add a0, a0, a1
300 define i32 @mul96(i32 %a) {
301 ; RV32I-LABEL: mul96:
303 ; RV32I-NEXT: addi a1, zero, 96
304 ; RV32I-NEXT: mul a0, a0, a1
307 ; RV32B-LABEL: mul96:
309 ; RV32B-NEXT: sh1add a0, a0, a0
310 ; RV32B-NEXT: slli a0, a0, 5
313 ; RV32ZBA-LABEL: mul96:
315 ; RV32ZBA-NEXT: sh1add a0, a0, a0
316 ; RV32ZBA-NEXT: slli a0, a0, 5
322 define i32 @mul160(i32 %a) {
323 ; RV32I-LABEL: mul160:
325 ; RV32I-NEXT: addi a1, zero, 160
326 ; RV32I-NEXT: mul a0, a0, a1
329 ; RV32B-LABEL: mul160:
331 ; RV32B-NEXT: sh2add a0, a0, a0
332 ; RV32B-NEXT: slli a0, a0, 5
335 ; RV32ZBA-LABEL: mul160:
337 ; RV32ZBA-NEXT: sh2add a0, a0, a0
338 ; RV32ZBA-NEXT: slli a0, a0, 5
344 define i32 @mul288(i32 %a) {
345 ; RV32I-LABEL: mul288:
347 ; RV32I-NEXT: addi a1, zero, 288
348 ; RV32I-NEXT: mul a0, a0, a1
351 ; RV32B-LABEL: mul288:
353 ; RV32B-NEXT: sh3add a0, a0, a0
354 ; RV32B-NEXT: slli a0, a0, 5
357 ; RV32ZBA-LABEL: mul288:
359 ; RV32ZBA-NEXT: sh3add a0, a0, a0
360 ; RV32ZBA-NEXT: slli a0, a0, 5
366 define i32 @mul258(i32 %a) {
367 ; RV32I-LABEL: mul258:
369 ; RV32I-NEXT: addi a1, zero, 258
370 ; RV32I-NEXT: mul a0, a0, a1
373 ; RV32B-LABEL: mul258:
375 ; RV32B-NEXT: addi a1, zero, 258
376 ; RV32B-NEXT: mul a0, a0, a1
379 ; RV32ZBA-LABEL: mul258:
381 ; RV32ZBA-NEXT: addi a1, zero, 258
382 ; RV32ZBA-NEXT: mul a0, a0, a1
388 define i32 @mul260(i32 %a) {
389 ; RV32I-LABEL: mul260:
391 ; RV32I-NEXT: addi a1, zero, 260
392 ; RV32I-NEXT: mul a0, a0, a1
395 ; RV32B-LABEL: mul260:
397 ; RV32B-NEXT: addi a1, zero, 260
398 ; RV32B-NEXT: mul a0, a0, a1
401 ; RV32ZBA-LABEL: mul260:
403 ; RV32ZBA-NEXT: addi a1, zero, 260
404 ; RV32ZBA-NEXT: mul a0, a0, a1
410 define i32 @mul264(i32 %a) {
411 ; RV32I-LABEL: mul264:
413 ; RV32I-NEXT: addi a1, zero, 264
414 ; RV32I-NEXT: mul a0, a0, a1
417 ; RV32B-LABEL: mul264:
419 ; RV32B-NEXT: addi a1, zero, 264
420 ; RV32B-NEXT: mul a0, a0, a1
423 ; RV32ZBA-LABEL: mul264:
425 ; RV32ZBA-NEXT: addi a1, zero, 264
426 ; RV32ZBA-NEXT: mul a0, a0, a1
432 define i32 @mul11(i32 %a) {
433 ; RV32I-LABEL: mul11:
435 ; RV32I-NEXT: addi a1, zero, 11
436 ; RV32I-NEXT: mul a0, a0, a1
439 ; RV32B-LABEL: mul11:
441 ; RV32B-NEXT: sh2add a1, a0, a0
442 ; RV32B-NEXT: sh1add a0, a1, a0
445 ; RV32ZBA-LABEL: mul11:
447 ; RV32ZBA-NEXT: sh2add a1, a0, a0
448 ; RV32ZBA-NEXT: sh1add a0, a1, a0
454 define i32 @mul19(i32 %a) {
455 ; RV32I-LABEL: mul19:
457 ; RV32I-NEXT: addi a1, zero, 19
458 ; RV32I-NEXT: mul a0, a0, a1
461 ; RV32B-LABEL: mul19:
463 ; RV32B-NEXT: sh3add a1, a0, a0
464 ; RV32B-NEXT: sh1add a0, a1, a0
467 ; RV32ZBA-LABEL: mul19:
469 ; RV32ZBA-NEXT: sh3add a1, a0, a0
470 ; RV32ZBA-NEXT: sh1add a0, a1, a0
476 define i32 @mul13(i32 %a) {
477 ; RV32I-LABEL: mul13:
479 ; RV32I-NEXT: addi a1, zero, 13
480 ; RV32I-NEXT: mul a0, a0, a1
483 ; RV32B-LABEL: mul13:
485 ; RV32B-NEXT: sh1add a1, a0, a0
486 ; RV32B-NEXT: sh2add a0, a1, a0
489 ; RV32ZBA-LABEL: mul13:
491 ; RV32ZBA-NEXT: sh1add a1, a0, a0
492 ; RV32ZBA-NEXT: sh2add a0, a1, a0
498 define i32 @mul21(i32 %a) {
499 ; RV32I-LABEL: mul21:
501 ; RV32I-NEXT: addi a1, zero, 21
502 ; RV32I-NEXT: mul a0, a0, a1
505 ; RV32B-LABEL: mul21:
507 ; RV32B-NEXT: sh2add a1, a0, a0
508 ; RV32B-NEXT: sh2add a0, a1, a0
511 ; RV32ZBA-LABEL: mul21:
513 ; RV32ZBA-NEXT: sh2add a1, a0, a0
514 ; RV32ZBA-NEXT: sh2add a0, a1, a0
520 define i32 @mul37(i32 %a) {
521 ; RV32I-LABEL: mul37:
523 ; RV32I-NEXT: addi a1, zero, 37
524 ; RV32I-NEXT: mul a0, a0, a1
527 ; RV32B-LABEL: mul37:
529 ; RV32B-NEXT: sh3add a1, a0, a0
530 ; RV32B-NEXT: sh2add a0, a1, a0
533 ; RV32ZBA-LABEL: mul37:
535 ; RV32ZBA-NEXT: sh3add a1, a0, a0
536 ; RV32ZBA-NEXT: sh2add a0, a1, a0
542 define i32 @mul25(i32 %a) {
543 ; RV32I-LABEL: mul25:
545 ; RV32I-NEXT: addi a1, zero, 25
546 ; RV32I-NEXT: mul a0, a0, a1
549 ; RV32B-LABEL: mul25:
551 ; RV32B-NEXT: sh1add a1, a0, a0
552 ; RV32B-NEXT: sh3add a0, a1, a0
555 ; RV32ZBA-LABEL: mul25:
557 ; RV32ZBA-NEXT: sh1add a1, a0, a0
558 ; RV32ZBA-NEXT: sh3add a0, a1, a0
564 define i32 @mul41(i32 %a) {
565 ; RV32I-LABEL: mul41:
567 ; RV32I-NEXT: addi a1, zero, 41
568 ; RV32I-NEXT: mul a0, a0, a1
571 ; RV32B-LABEL: mul41:
573 ; RV32B-NEXT: sh2add a1, a0, a0
574 ; RV32B-NEXT: sh3add a0, a1, a0
577 ; RV32ZBA-LABEL: mul41:
579 ; RV32ZBA-NEXT: sh2add a1, a0, a0
580 ; RV32ZBA-NEXT: sh3add a0, a1, a0
586 define i32 @mul73(i32 %a) {
587 ; RV32I-LABEL: mul73:
589 ; RV32I-NEXT: addi a1, zero, 73
590 ; RV32I-NEXT: mul a0, a0, a1
593 ; RV32B-LABEL: mul73:
595 ; RV32B-NEXT: sh3add a1, a0, a0
596 ; RV32B-NEXT: sh3add a0, a1, a0
599 ; RV32ZBA-LABEL: mul73:
601 ; RV32ZBA-NEXT: sh3add a1, a0, a0
602 ; RV32ZBA-NEXT: sh3add a0, a1, a0
608 define i32 @mul27(i32 %a) {
609 ; RV32I-LABEL: mul27:
611 ; RV32I-NEXT: addi a1, zero, 27
612 ; RV32I-NEXT: mul a0, a0, a1
615 ; RV32B-LABEL: mul27:
617 ; RV32B-NEXT: sh3add a0, a0, a0
618 ; RV32B-NEXT: sh1add a0, a0, a0
621 ; RV32ZBA-LABEL: mul27:
623 ; RV32ZBA-NEXT: sh3add a0, a0, a0
624 ; RV32ZBA-NEXT: sh1add a0, a0, a0
630 define i32 @mul45(i32 %a) {
631 ; RV32I-LABEL: mul45:
633 ; RV32I-NEXT: addi a1, zero, 45
634 ; RV32I-NEXT: mul a0, a0, a1
637 ; RV32B-LABEL: mul45:
639 ; RV32B-NEXT: sh3add a0, a0, a0
640 ; RV32B-NEXT: sh2add a0, a0, a0
643 ; RV32ZBA-LABEL: mul45:
645 ; RV32ZBA-NEXT: sh3add a0, a0, a0
646 ; RV32ZBA-NEXT: sh2add a0, a0, a0
652 define i32 @mul81(i32 %a) {
653 ; RV32I-LABEL: mul81:
655 ; RV32I-NEXT: addi a1, zero, 81
656 ; RV32I-NEXT: mul a0, a0, a1
659 ; RV32B-LABEL: mul81:
661 ; RV32B-NEXT: sh3add a0, a0, a0
662 ; RV32B-NEXT: sh3add a0, a0, a0
665 ; RV32ZBA-LABEL: mul81:
667 ; RV32ZBA-NEXT: sh3add a0, a0, a0
668 ; RV32ZBA-NEXT: sh3add a0, a0, a0
674 define i32 @mul4098(i32 %a) {
675 ; RV32I-LABEL: mul4098:
677 ; RV32I-NEXT: lui a1, 1
678 ; RV32I-NEXT: addi a1, a1, 2
679 ; RV32I-NEXT: mul a0, a0, a1
682 ; RV32B-LABEL: mul4098:
684 ; RV32B-NEXT: slli a1, a0, 12
685 ; RV32B-NEXT: sh1add a0, a0, a1
688 ; RV32ZBA-LABEL: mul4098:
690 ; RV32ZBA-NEXT: slli a1, a0, 12
691 ; RV32ZBA-NEXT: sh1add a0, a0, a1
693 %c = mul i32 %a, 4098
697 define i32 @mul4100(i32 %a) {
698 ; RV32I-LABEL: mul4100:
700 ; RV32I-NEXT: lui a1, 1
701 ; RV32I-NEXT: addi a1, a1, 4
702 ; RV32I-NEXT: mul a0, a0, a1
705 ; RV32B-LABEL: mul4100:
707 ; RV32B-NEXT: slli a1, a0, 12
708 ; RV32B-NEXT: sh2add a0, a0, a1
711 ; RV32ZBA-LABEL: mul4100:
713 ; RV32ZBA-NEXT: slli a1, a0, 12
714 ; RV32ZBA-NEXT: sh2add a0, a0, a1
716 %c = mul i32 %a, 4100
720 define i32 @mul4104(i32 %a) {
721 ; RV32I-LABEL: mul4104:
723 ; RV32I-NEXT: lui a1, 1
724 ; RV32I-NEXT: addi a1, a1, 8
725 ; RV32I-NEXT: mul a0, a0, a1
728 ; RV32B-LABEL: mul4104:
730 ; RV32B-NEXT: slli a1, a0, 12
731 ; RV32B-NEXT: sh3add a0, a0, a1
734 ; RV32ZBA-LABEL: mul4104:
736 ; RV32ZBA-NEXT: slli a1, a0, 12
737 ; RV32ZBA-NEXT: sh3add a0, a0, a1
739 %c = mul i32 %a, 4104
743 define i32 @add4104(i32 %a) {
744 ; RV32I-LABEL: add4104:
746 ; RV32I-NEXT: lui a1, 1
747 ; RV32I-NEXT: addi a1, a1, 8
748 ; RV32I-NEXT: add a0, a0, a1
751 ; RV32B-LABEL: add4104:
753 ; RV32B-NEXT: addi a1, zero, 1026
754 ; RV32B-NEXT: sh2add a0, a1, a0
757 ; RV32ZBA-LABEL: add4104:
759 ; RV32ZBA-NEXT: addi a1, zero, 1026
760 ; RV32ZBA-NEXT: sh2add a0, a1, a0
762 %c = add i32 %a, 4104
766 define i32 @add8208(i32 %a) {
767 ; RV32I-LABEL: add8208:
769 ; RV32I-NEXT: lui a1, 2
770 ; RV32I-NEXT: addi a1, a1, 16
771 ; RV32I-NEXT: add a0, a0, a1
774 ; RV32B-LABEL: add8208:
776 ; RV32B-NEXT: addi a1, zero, 1026
777 ; RV32B-NEXT: sh3add a0, a1, a0
780 ; RV32ZBA-LABEL: add8208:
782 ; RV32ZBA-NEXT: addi a1, zero, 1026
783 ; RV32ZBA-NEXT: sh3add a0, a1, a0
785 %c = add i32 %a, 8208