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-prefixes=CHECK,RV32I
4 ; RUN: llc -mtriple=riscv32 -mattr=+m,+zba -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefixes=CHECK,RV32ZBA
7 define signext i16 @sh1add(i64 %0, ptr %1) {
10 ; RV32I-NEXT: slli a0, a0, 1
11 ; RV32I-NEXT: add a0, a2, a0
12 ; RV32I-NEXT: lh a0, 0(a0)
15 ; RV32ZBA-LABEL: sh1add:
17 ; RV32ZBA-NEXT: sh1add a0, a0, a2
18 ; RV32ZBA-NEXT: lh a0, 0(a0)
20 %3 = getelementptr inbounds i16, ptr %1, i64 %0
25 define i32 @sh2add(i64 %0, ptr %1) {
26 ; RV32I-LABEL: sh2add:
28 ; RV32I-NEXT: slli a0, a0, 2
29 ; RV32I-NEXT: add a0, a2, a0
30 ; RV32I-NEXT: lw a0, 0(a0)
33 ; RV32ZBA-LABEL: sh2add:
35 ; RV32ZBA-NEXT: sh2add a0, a0, a2
36 ; RV32ZBA-NEXT: lw a0, 0(a0)
38 %3 = getelementptr inbounds i32, ptr %1, i64 %0
43 define i64 @sh3add(i64 %0, ptr %1) {
44 ; RV32I-LABEL: sh3add:
46 ; RV32I-NEXT: slli a0, a0, 3
47 ; RV32I-NEXT: add a2, a2, a0
48 ; RV32I-NEXT: lw a0, 0(a2)
49 ; RV32I-NEXT: lw a1, 4(a2)
52 ; RV32ZBA-LABEL: sh3add:
54 ; RV32ZBA-NEXT: sh3add a1, a0, a2
55 ; RV32ZBA-NEXT: lw a0, 0(a1)
56 ; RV32ZBA-NEXT: lw a1, 4(a1)
58 %3 = getelementptr inbounds i64, ptr %1, i64 %0
63 define i32 @addmul6(i32 %a, i32 %b) {
64 ; RV32I-LABEL: addmul6:
66 ; RV32I-NEXT: li a2, 6
67 ; RV32I-NEXT: mul a0, a0, a2
68 ; RV32I-NEXT: add a0, a0, a1
71 ; RV32ZBA-LABEL: addmul6:
73 ; RV32ZBA-NEXT: sh1add a0, a0, a0
74 ; RV32ZBA-NEXT: sh1add a0, a0, a1
81 define i32 @addmul10(i32 %a, i32 %b) {
82 ; RV32I-LABEL: addmul10:
84 ; RV32I-NEXT: li a2, 10
85 ; RV32I-NEXT: mul a0, a0, a2
86 ; RV32I-NEXT: add a0, a0, a1
89 ; RV32ZBA-LABEL: addmul10:
91 ; RV32ZBA-NEXT: sh2add a0, a0, a0
92 ; RV32ZBA-NEXT: sh1add a0, a0, a1
99 define i32 @addmul12(i32 %a, i32 %b) {
100 ; RV32I-LABEL: addmul12:
102 ; RV32I-NEXT: li a2, 12
103 ; RV32I-NEXT: mul a0, a0, a2
104 ; RV32I-NEXT: add a0, a0, a1
107 ; RV32ZBA-LABEL: addmul12:
109 ; RV32ZBA-NEXT: sh1add a0, a0, a0
110 ; RV32ZBA-NEXT: sh2add a0, a0, a1
117 define i32 @addmul18(i32 %a, i32 %b) {
118 ; RV32I-LABEL: addmul18:
120 ; RV32I-NEXT: li a2, 18
121 ; RV32I-NEXT: mul a0, a0, a2
122 ; RV32I-NEXT: add a0, a0, a1
125 ; RV32ZBA-LABEL: addmul18:
127 ; RV32ZBA-NEXT: sh3add a0, a0, a0
128 ; RV32ZBA-NEXT: sh1add a0, a0, a1
135 define i32 @addmul20(i32 %a, i32 %b) {
136 ; RV32I-LABEL: addmul20:
138 ; RV32I-NEXT: li a2, 20
139 ; RV32I-NEXT: mul a0, a0, a2
140 ; RV32I-NEXT: add a0, a0, a1
143 ; RV32ZBA-LABEL: addmul20:
145 ; RV32ZBA-NEXT: sh2add a0, a0, a0
146 ; RV32ZBA-NEXT: sh2add a0, a0, a1
153 define i32 @addmul24(i32 %a, i32 %b) {
154 ; RV32I-LABEL: addmul24:
156 ; RV32I-NEXT: li a2, 24
157 ; RV32I-NEXT: mul a0, a0, a2
158 ; RV32I-NEXT: add a0, a0, a1
161 ; RV32ZBA-LABEL: addmul24:
163 ; RV32ZBA-NEXT: sh1add a0, a0, a0
164 ; RV32ZBA-NEXT: sh3add a0, a0, a1
171 define i32 @addmul36(i32 %a, i32 %b) {
172 ; RV32I-LABEL: addmul36:
174 ; RV32I-NEXT: li a2, 36
175 ; RV32I-NEXT: mul a0, a0, a2
176 ; RV32I-NEXT: add a0, a0, a1
179 ; RV32ZBA-LABEL: addmul36:
181 ; RV32ZBA-NEXT: sh3add a0, a0, a0
182 ; RV32ZBA-NEXT: sh2add a0, a0, a1
189 define i32 @addmul40(i32 %a, i32 %b) {
190 ; RV32I-LABEL: addmul40:
192 ; RV32I-NEXT: li a2, 40
193 ; RV32I-NEXT: mul a0, a0, a2
194 ; RV32I-NEXT: add a0, a0, a1
197 ; RV32ZBA-LABEL: addmul40:
199 ; RV32ZBA-NEXT: sh2add a0, a0, a0
200 ; RV32ZBA-NEXT: sh3add a0, a0, a1
207 define i32 @addmul72(i32 %a, i32 %b) {
208 ; RV32I-LABEL: addmul72:
210 ; RV32I-NEXT: li a2, 72
211 ; RV32I-NEXT: mul a0, a0, a2
212 ; RV32I-NEXT: add a0, a0, a1
215 ; RV32ZBA-LABEL: addmul72:
217 ; RV32ZBA-NEXT: sh3add a0, a0, a0
218 ; RV32ZBA-NEXT: sh3add a0, a0, a1
225 define i32 @mul96(i32 %a) {
226 ; RV32I-LABEL: mul96:
228 ; RV32I-NEXT: li a1, 96
229 ; RV32I-NEXT: mul a0, a0, a1
232 ; RV32ZBA-LABEL: mul96:
234 ; RV32ZBA-NEXT: sh1add a0, a0, a0
235 ; RV32ZBA-NEXT: slli a0, a0, 5
241 define i32 @mul160(i32 %a) {
242 ; RV32I-LABEL: mul160:
244 ; RV32I-NEXT: li a1, 160
245 ; RV32I-NEXT: mul a0, a0, a1
248 ; RV32ZBA-LABEL: mul160:
250 ; RV32ZBA-NEXT: sh2add a0, a0, a0
251 ; RV32ZBA-NEXT: slli a0, a0, 5
257 define i32 @mul288(i32 %a) {
258 ; RV32I-LABEL: mul288:
260 ; RV32I-NEXT: li a1, 288
261 ; RV32I-NEXT: mul a0, a0, a1
264 ; RV32ZBA-LABEL: mul288:
266 ; RV32ZBA-NEXT: sh3add a0, a0, a0
267 ; RV32ZBA-NEXT: slli a0, a0, 5
273 define i32 @mul258(i32 %a) {
274 ; CHECK-LABEL: mul258:
276 ; CHECK-NEXT: li a1, 258
277 ; CHECK-NEXT: mul a0, a0, a1
283 define i32 @mul260(i32 %a) {
284 ; CHECK-LABEL: mul260:
286 ; CHECK-NEXT: li a1, 260
287 ; CHECK-NEXT: mul a0, a0, a1
293 define i32 @mul264(i32 %a) {
294 ; CHECK-LABEL: mul264:
296 ; CHECK-NEXT: li a1, 264
297 ; CHECK-NEXT: mul a0, a0, a1
303 define i32 @mul11(i32 %a) {
304 ; RV32I-LABEL: mul11:
306 ; RV32I-NEXT: li a1, 11
307 ; RV32I-NEXT: mul a0, a0, a1
310 ; RV32ZBA-LABEL: mul11:
312 ; RV32ZBA-NEXT: sh2add a1, a0, a0
313 ; RV32ZBA-NEXT: sh1add a0, a1, a0
319 define i32 @mul19(i32 %a) {
320 ; RV32I-LABEL: mul19:
322 ; RV32I-NEXT: li a1, 19
323 ; RV32I-NEXT: mul a0, a0, a1
326 ; RV32ZBA-LABEL: mul19:
328 ; RV32ZBA-NEXT: sh3add a1, a0, a0
329 ; RV32ZBA-NEXT: sh1add a0, a1, a0
335 define i32 @mul13(i32 %a) {
336 ; RV32I-LABEL: mul13:
338 ; RV32I-NEXT: li a1, 13
339 ; RV32I-NEXT: mul a0, a0, a1
342 ; RV32ZBA-LABEL: mul13:
344 ; RV32ZBA-NEXT: sh1add a1, a0, a0
345 ; RV32ZBA-NEXT: sh2add a0, a1, a0
351 define i32 @mul21(i32 %a) {
352 ; RV32I-LABEL: mul21:
354 ; RV32I-NEXT: li a1, 21
355 ; RV32I-NEXT: mul a0, a0, a1
358 ; RV32ZBA-LABEL: mul21:
360 ; RV32ZBA-NEXT: sh2add a1, a0, a0
361 ; RV32ZBA-NEXT: sh2add a0, a1, a0
367 define i32 @mul37(i32 %a) {
368 ; RV32I-LABEL: mul37:
370 ; RV32I-NEXT: li a1, 37
371 ; RV32I-NEXT: mul a0, a0, a1
374 ; RV32ZBA-LABEL: mul37:
376 ; RV32ZBA-NEXT: sh3add a1, a0, a0
377 ; RV32ZBA-NEXT: sh2add a0, a1, a0
383 define i32 @mul25(i32 %a) {
384 ; RV32I-LABEL: mul25:
386 ; RV32I-NEXT: li a1, 25
387 ; RV32I-NEXT: mul a0, a0, a1
390 ; RV32ZBA-LABEL: mul25:
392 ; RV32ZBA-NEXT: sh1add a1, a0, a0
393 ; RV32ZBA-NEXT: sh3add a0, a1, a0
399 define i32 @mul41(i32 %a) {
400 ; RV32I-LABEL: mul41:
402 ; RV32I-NEXT: li a1, 41
403 ; RV32I-NEXT: mul a0, a0, a1
406 ; RV32ZBA-LABEL: mul41:
408 ; RV32ZBA-NEXT: sh2add a1, a0, a0
409 ; RV32ZBA-NEXT: sh3add a0, a1, a0
415 define i32 @mul73(i32 %a) {
416 ; RV32I-LABEL: mul73:
418 ; RV32I-NEXT: li a1, 73
419 ; RV32I-NEXT: mul a0, a0, a1
422 ; RV32ZBA-LABEL: mul73:
424 ; RV32ZBA-NEXT: sh3add a1, a0, a0
425 ; RV32ZBA-NEXT: sh3add a0, a1, a0
431 define i32 @mul27(i32 %a) {
432 ; RV32I-LABEL: mul27:
434 ; RV32I-NEXT: li a1, 27
435 ; RV32I-NEXT: mul a0, a0, a1
438 ; RV32ZBA-LABEL: mul27:
440 ; RV32ZBA-NEXT: sh3add a0, a0, a0
441 ; RV32ZBA-NEXT: sh1add a0, a0, a0
447 define i32 @mul45(i32 %a) {
448 ; RV32I-LABEL: mul45:
450 ; RV32I-NEXT: li a1, 45
451 ; RV32I-NEXT: mul a0, a0, a1
454 ; RV32ZBA-LABEL: mul45:
456 ; RV32ZBA-NEXT: sh3add a0, a0, a0
457 ; RV32ZBA-NEXT: sh2add a0, a0, a0
463 define i32 @mul81(i32 %a) {
464 ; RV32I-LABEL: mul81:
466 ; RV32I-NEXT: li a1, 81
467 ; RV32I-NEXT: mul a0, a0, a1
470 ; RV32ZBA-LABEL: mul81:
472 ; RV32ZBA-NEXT: sh3add a0, a0, a0
473 ; RV32ZBA-NEXT: sh3add a0, a0, a0
479 define i32 @mul4098(i32 %a) {
480 ; RV32I-LABEL: mul4098:
482 ; RV32I-NEXT: slli a1, a0, 1
483 ; RV32I-NEXT: slli a0, a0, 12
484 ; RV32I-NEXT: add a0, a0, a1
487 ; RV32ZBA-LABEL: mul4098:
489 ; RV32ZBA-NEXT: slli a1, a0, 12
490 ; RV32ZBA-NEXT: sh1add a0, a0, a1
492 %c = mul i32 %a, 4098
496 define i32 @mul4100(i32 %a) {
497 ; RV32I-LABEL: mul4100:
499 ; RV32I-NEXT: slli a1, a0, 2
500 ; RV32I-NEXT: slli a0, a0, 12
501 ; RV32I-NEXT: add a0, a0, a1
504 ; RV32ZBA-LABEL: mul4100:
506 ; RV32ZBA-NEXT: slli a1, a0, 12
507 ; RV32ZBA-NEXT: sh2add a0, a0, a1
509 %c = mul i32 %a, 4100
513 define i32 @mul4104(i32 %a) {
514 ; RV32I-LABEL: mul4104:
516 ; RV32I-NEXT: slli a1, a0, 3
517 ; RV32I-NEXT: slli a0, a0, 12
518 ; RV32I-NEXT: add a0, a0, a1
521 ; RV32ZBA-LABEL: mul4104:
523 ; RV32ZBA-NEXT: slli a1, a0, 12
524 ; RV32ZBA-NEXT: sh3add a0, a0, a1
526 %c = mul i32 %a, 4104
530 define i32 @add4104(i32 %a) {
531 ; RV32I-LABEL: add4104:
533 ; RV32I-NEXT: lui a1, 1
534 ; RV32I-NEXT: addi a1, a1, 8
535 ; RV32I-NEXT: add a0, a0, a1
538 ; RV32ZBA-LABEL: add4104:
540 ; RV32ZBA-NEXT: li a1, 1026
541 ; RV32ZBA-NEXT: sh2add a0, a1, a0
543 %c = add i32 %a, 4104
547 define i32 @add8208(i32 %a) {
548 ; RV32I-LABEL: add8208:
550 ; RV32I-NEXT: lui a1, 2
551 ; RV32I-NEXT: addi a1, a1, 16
552 ; RV32I-NEXT: add a0, a0, a1
555 ; RV32ZBA-LABEL: add8208:
557 ; RV32ZBA-NEXT: li a1, 1026
558 ; RV32ZBA-NEXT: sh3add a0, a1, a0
560 %c = add i32 %a, 8208
564 define i32 @add8192(i32 %a) {
565 ; CHECK-LABEL: add8192:
567 ; CHECK-NEXT: lui a1, 2
568 ; CHECK-NEXT: add a0, a0, a1
570 %c = add i32 %a, 8192
574 define i32 @addshl_5_6(i32 %a, i32 %b) {
575 ; RV32I-LABEL: addshl_5_6:
577 ; RV32I-NEXT: slli a0, a0, 5
578 ; RV32I-NEXT: slli a1, a1, 6
579 ; RV32I-NEXT: add a0, a0, a1
582 ; RV32ZBA-LABEL: addshl_5_6:
584 ; RV32ZBA-NEXT: sh1add a0, a1, a0
585 ; RV32ZBA-NEXT: slli a0, a0, 5
593 define i32 @addshl_5_7(i32 %a, i32 %b) {
594 ; RV32I-LABEL: addshl_5_7:
596 ; RV32I-NEXT: slli a0, a0, 5
597 ; RV32I-NEXT: slli a1, a1, 7
598 ; RV32I-NEXT: add a0, a0, a1
601 ; RV32ZBA-LABEL: addshl_5_7:
603 ; RV32ZBA-NEXT: sh2add a0, a1, a0
604 ; RV32ZBA-NEXT: slli a0, a0, 5
612 define i32 @addshl_5_8(i32 %a, i32 %b) {
613 ; RV32I-LABEL: addshl_5_8:
615 ; RV32I-NEXT: slli a0, a0, 5
616 ; RV32I-NEXT: slli a1, a1, 8
617 ; RV32I-NEXT: add a0, a0, a1
620 ; RV32ZBA-LABEL: addshl_5_8:
622 ; RV32ZBA-NEXT: sh3add a0, a1, a0
623 ; RV32ZBA-NEXT: slli a0, a0, 5