1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ;; Test that (mul (add x, c1), c2) can be transformed to
3 ;; (add (mul x, c2), c1*c2) if profitable.
5 ; RUN: llc -mtriple=riscv32 -mattr=+m,+zba -verify-machineinstrs < %s \
6 ; RUN: | FileCheck -check-prefix=RV32IMB %s
7 ; RUN: llc -mtriple=riscv64 -mattr=+m,+zba -verify-machineinstrs < %s \
8 ; RUN: | FileCheck -check-prefix=RV64IMB %s
10 define i32 @add_mul_combine_accept_a1(i32 %x) {
11 ; RV32IMB-LABEL: add_mul_combine_accept_a1:
13 ; RV32IMB-NEXT: li a1, 29
14 ; RV32IMB-NEXT: mul a0, a0, a1
15 ; RV32IMB-NEXT: addi a0, a0, 1073
18 ; RV64IMB-LABEL: add_mul_combine_accept_a1:
20 ; RV64IMB-NEXT: li a1, 29
21 ; RV64IMB-NEXT: mulw a0, a0, a1
22 ; RV64IMB-NEXT: addiw a0, a0, 1073
24 %tmp0 = add i32 %x, 37
25 %tmp1 = mul i32 %tmp0, 29
29 define signext i32 @add_mul_combine_accept_a2(i32 signext %x) {
30 ; RV32IMB-LABEL: add_mul_combine_accept_a2:
32 ; RV32IMB-NEXT: li a1, 29
33 ; RV32IMB-NEXT: mul a0, a0, a1
34 ; RV32IMB-NEXT: addi a0, a0, 1073
37 ; RV64IMB-LABEL: add_mul_combine_accept_a2:
39 ; RV64IMB-NEXT: li a1, 29
40 ; RV64IMB-NEXT: mulw a0, a0, a1
41 ; RV64IMB-NEXT: addiw a0, a0, 1073
43 %tmp0 = add i32 %x, 37
44 %tmp1 = mul i32 %tmp0, 29
48 define i64 @add_mul_combine_accept_a3(i64 %x) {
49 ; RV32IMB-LABEL: add_mul_combine_accept_a3:
51 ; RV32IMB-NEXT: li a2, 29
52 ; RV32IMB-NEXT: mul a1, a1, a2
53 ; RV32IMB-NEXT: mulhu a3, a0, a2
54 ; RV32IMB-NEXT: add a1, a3, a1
55 ; RV32IMB-NEXT: mul a2, a0, a2
56 ; RV32IMB-NEXT: addi a0, a2, 1073
57 ; RV32IMB-NEXT: sltu a2, a0, a2
58 ; RV32IMB-NEXT: add a1, a1, a2
61 ; RV64IMB-LABEL: add_mul_combine_accept_a3:
63 ; RV64IMB-NEXT: li a1, 29
64 ; RV64IMB-NEXT: mul a0, a0, a1
65 ; RV64IMB-NEXT: addi a0, a0, 1073
67 %tmp0 = add i64 %x, 37
68 %tmp1 = mul i64 %tmp0, 29
72 define i32 @add_mul_combine_accept_b1(i32 %x) {
73 ; RV32IMB-LABEL: add_mul_combine_accept_b1:
75 ; RV32IMB-NEXT: li a1, 23
76 ; RV32IMB-NEXT: mul a0, a0, a1
77 ; RV32IMB-NEXT: lui a1, 50
78 ; RV32IMB-NEXT: addi a1, a1, 1119
79 ; RV32IMB-NEXT: add a0, a0, a1
82 ; RV64IMB-LABEL: add_mul_combine_accept_b1:
84 ; RV64IMB-NEXT: li a1, 23
85 ; RV64IMB-NEXT: mulw a0, a0, a1
86 ; RV64IMB-NEXT: lui a1, 50
87 ; RV64IMB-NEXT: addiw a1, a1, 1119
88 ; RV64IMB-NEXT: addw a0, a0, a1
90 %tmp0 = add i32 %x, 8953
91 %tmp1 = mul i32 %tmp0, 23
95 define signext i32 @add_mul_combine_accept_b2(i32 signext %x) {
96 ; RV32IMB-LABEL: add_mul_combine_accept_b2:
98 ; RV32IMB-NEXT: li a1, 23
99 ; RV32IMB-NEXT: mul a0, a0, a1
100 ; RV32IMB-NEXT: lui a1, 50
101 ; RV32IMB-NEXT: addi a1, a1, 1119
102 ; RV32IMB-NEXT: add a0, a0, a1
105 ; RV64IMB-LABEL: add_mul_combine_accept_b2:
107 ; RV64IMB-NEXT: li a1, 23
108 ; RV64IMB-NEXT: mulw a0, a0, a1
109 ; RV64IMB-NEXT: lui a1, 50
110 ; RV64IMB-NEXT: addiw a1, a1, 1119
111 ; RV64IMB-NEXT: addw a0, a0, a1
113 %tmp0 = add i32 %x, 8953
114 %tmp1 = mul i32 %tmp0, 23
118 define i64 @add_mul_combine_accept_b3(i64 %x) {
119 ; RV32IMB-LABEL: add_mul_combine_accept_b3:
121 ; RV32IMB-NEXT: li a2, 23
122 ; RV32IMB-NEXT: mul a1, a1, a2
123 ; RV32IMB-NEXT: mulhu a3, a0, a2
124 ; RV32IMB-NEXT: add a1, a3, a1
125 ; RV32IMB-NEXT: mul a2, a0, a2
126 ; RV32IMB-NEXT: lui a0, 50
127 ; RV32IMB-NEXT: addi a0, a0, 1119
128 ; RV32IMB-NEXT: add a0, a2, a0
129 ; RV32IMB-NEXT: sltu a2, a0, a2
130 ; RV32IMB-NEXT: add a1, a1, a2
133 ; RV64IMB-LABEL: add_mul_combine_accept_b3:
135 ; RV64IMB-NEXT: li a1, 23
136 ; RV64IMB-NEXT: mul a0, a0, a1
137 ; RV64IMB-NEXT: lui a1, 50
138 ; RV64IMB-NEXT: addiw a1, a1, 1119
139 ; RV64IMB-NEXT: add a0, a0, a1
141 %tmp0 = add i64 %x, 8953
142 %tmp1 = mul i64 %tmp0, 23
146 define i32 @add_mul_combine_reject_a1(i32 %x) {
147 ; RV32IMB-LABEL: add_mul_combine_reject_a1:
149 ; RV32IMB-NEXT: addi a0, a0, 1971
150 ; RV32IMB-NEXT: li a1, 29
151 ; RV32IMB-NEXT: mul a0, a0, a1
154 ; RV64IMB-LABEL: add_mul_combine_reject_a1:
156 ; RV64IMB-NEXT: addiw a0, a0, 1971
157 ; RV64IMB-NEXT: li a1, 29
158 ; RV64IMB-NEXT: mulw a0, a0, a1
160 %tmp0 = add i32 %x, 1971
161 %tmp1 = mul i32 %tmp0, 29
165 define signext i32 @add_mul_combine_reject_a2(i32 signext %x) {
166 ; RV32IMB-LABEL: add_mul_combine_reject_a2:
168 ; RV32IMB-NEXT: addi a0, a0, 1971
169 ; RV32IMB-NEXT: li a1, 29
170 ; RV32IMB-NEXT: mul a0, a0, a1
173 ; RV64IMB-LABEL: add_mul_combine_reject_a2:
175 ; RV64IMB-NEXT: addiw a0, a0, 1971
176 ; RV64IMB-NEXT: li a1, 29
177 ; RV64IMB-NEXT: mulw a0, a0, a1
179 %tmp0 = add i32 %x, 1971
180 %tmp1 = mul i32 %tmp0, 29
184 define i64 @add_mul_combine_reject_a3(i64 %x) {
185 ; RV32IMB-LABEL: add_mul_combine_reject_a3:
187 ; RV32IMB-NEXT: li a2, 29
188 ; RV32IMB-NEXT: mul a1, a1, a2
189 ; RV32IMB-NEXT: mulhu a3, a0, a2
190 ; RV32IMB-NEXT: add a1, a3, a1
191 ; RV32IMB-NEXT: mul a2, a0, a2
192 ; RV32IMB-NEXT: lui a0, 14
193 ; RV32IMB-NEXT: addi a0, a0, -185
194 ; RV32IMB-NEXT: add a0, a2, a0
195 ; RV32IMB-NEXT: sltu a2, a0, a2
196 ; RV32IMB-NEXT: add a1, a1, a2
199 ; RV64IMB-LABEL: add_mul_combine_reject_a3:
201 ; RV64IMB-NEXT: addi a0, a0, 1971
202 ; RV64IMB-NEXT: li a1, 29
203 ; RV64IMB-NEXT: mul a0, a0, a1
205 %tmp0 = add i64 %x, 1971
206 %tmp1 = mul i64 %tmp0, 29
210 define i32 @add_mul_combine_reject_c1(i32 %x) {
211 ; RV32IMB-LABEL: add_mul_combine_reject_c1:
213 ; RV32IMB-NEXT: addi a0, a0, 1000
214 ; RV32IMB-NEXT: sh3add a1, a0, a0
215 ; RV32IMB-NEXT: sh3add a0, a1, a0
218 ; RV64IMB-LABEL: add_mul_combine_reject_c1:
220 ; RV64IMB-NEXT: addi a0, a0, 1000
221 ; RV64IMB-NEXT: sh3add a1, a0, a0
222 ; RV64IMB-NEXT: sh3add a0, a1, a0
223 ; RV64IMB-NEXT: sext.w a0, a0
225 %tmp0 = add i32 %x, 1000
226 %tmp1 = mul i32 %tmp0, 73
230 define signext i32 @add_mul_combine_reject_c2(i32 signext %x) {
231 ; RV32IMB-LABEL: add_mul_combine_reject_c2:
233 ; RV32IMB-NEXT: addi a0, a0, 1000
234 ; RV32IMB-NEXT: sh3add a1, a0, a0
235 ; RV32IMB-NEXT: sh3add a0, a1, a0
238 ; RV64IMB-LABEL: add_mul_combine_reject_c2:
240 ; RV64IMB-NEXT: addi a0, a0, 1000
241 ; RV64IMB-NEXT: sh3add a1, a0, a0
242 ; RV64IMB-NEXT: sh3add a0, a1, a0
243 ; RV64IMB-NEXT: sext.w a0, a0
245 %tmp0 = add i32 %x, 1000
246 %tmp1 = mul i32 %tmp0, 73
250 define i64 @add_mul_combine_reject_c3(i64 %x) {
251 ; RV32IMB-LABEL: add_mul_combine_reject_c3:
253 ; RV32IMB-NEXT: li a2, 73
254 ; RV32IMB-NEXT: mul a1, a1, a2
255 ; RV32IMB-NEXT: mulhu a3, a0, a2
256 ; RV32IMB-NEXT: add a1, a3, a1
257 ; RV32IMB-NEXT: mul a2, a0, a2
258 ; RV32IMB-NEXT: lui a0, 18
259 ; RV32IMB-NEXT: addi a0, a0, -728
260 ; RV32IMB-NEXT: add a0, a2, a0
261 ; RV32IMB-NEXT: sltu a2, a0, a2
262 ; RV32IMB-NEXT: add a1, a1, a2
265 ; RV64IMB-LABEL: add_mul_combine_reject_c3:
267 ; RV64IMB-NEXT: addi a0, a0, 1000
268 ; RV64IMB-NEXT: sh3add a1, a0, a0
269 ; RV64IMB-NEXT: sh3add a0, a1, a0
271 %tmp0 = add i64 %x, 1000
272 %tmp1 = mul i64 %tmp0, 73
276 define i32 @add_mul_combine_reject_d1(i32 %x) {
277 ; RV32IMB-LABEL: add_mul_combine_reject_d1:
279 ; RV32IMB-NEXT: addi a0, a0, 1000
280 ; RV32IMB-NEXT: sh1add a0, a0, a0
281 ; RV32IMB-NEXT: slli a0, a0, 6
284 ; RV64IMB-LABEL: add_mul_combine_reject_d1:
286 ; RV64IMB-NEXT: addi a0, a0, 1000
287 ; RV64IMB-NEXT: sh1add a0, a0, a0
288 ; RV64IMB-NEXT: slliw a0, a0, 6
290 %tmp0 = add i32 %x, 1000
291 %tmp1 = mul i32 %tmp0, 192
295 define signext i32 @add_mul_combine_reject_d2(i32 signext %x) {
296 ; RV32IMB-LABEL: add_mul_combine_reject_d2:
298 ; RV32IMB-NEXT: addi a0, a0, 1000
299 ; RV32IMB-NEXT: sh1add a0, a0, a0
300 ; RV32IMB-NEXT: slli a0, a0, 6
303 ; RV64IMB-LABEL: add_mul_combine_reject_d2:
305 ; RV64IMB-NEXT: addi a0, a0, 1000
306 ; RV64IMB-NEXT: sh1add a0, a0, a0
307 ; RV64IMB-NEXT: slliw a0, a0, 6
309 %tmp0 = add i32 %x, 1000
310 %tmp1 = mul i32 %tmp0, 192
314 define i64 @add_mul_combine_reject_d3(i64 %x) {
315 ; RV32IMB-LABEL: add_mul_combine_reject_d3:
317 ; RV32IMB-NEXT: li a2, 192
318 ; RV32IMB-NEXT: mulhu a2, a0, a2
319 ; RV32IMB-NEXT: sh1add a1, a1, a1
320 ; RV32IMB-NEXT: slli a1, a1, 6
321 ; RV32IMB-NEXT: add a1, a2, a1
322 ; RV32IMB-NEXT: sh1add a0, a0, a0
323 ; RV32IMB-NEXT: slli a2, a0, 6
324 ; RV32IMB-NEXT: lui a0, 47
325 ; RV32IMB-NEXT: addi a0, a0, -512
326 ; RV32IMB-NEXT: add a0, a2, a0
327 ; RV32IMB-NEXT: sltu a2, a0, a2
328 ; RV32IMB-NEXT: add a1, a1, a2
331 ; RV64IMB-LABEL: add_mul_combine_reject_d3:
333 ; RV64IMB-NEXT: addi a0, a0, 1000
334 ; RV64IMB-NEXT: sh1add a0, a0, a0
335 ; RV64IMB-NEXT: slli a0, a0, 6
337 %tmp0 = add i64 %x, 1000
338 %tmp1 = mul i64 %tmp0, 192
342 define i32 @add_mul_combine_reject_e1(i32 %x) {
343 ; RV32IMB-LABEL: add_mul_combine_reject_e1:
345 ; RV32IMB-NEXT: addi a0, a0, 1971
346 ; RV32IMB-NEXT: li a1, 29
347 ; RV32IMB-NEXT: mul a0, a0, a1
350 ; RV64IMB-LABEL: add_mul_combine_reject_e1:
352 ; RV64IMB-NEXT: addiw a0, a0, 1971
353 ; RV64IMB-NEXT: li a1, 29
354 ; RV64IMB-NEXT: mulw a0, a0, a1
356 %tmp0 = mul i32 %x, 29
357 %tmp1 = add i32 %tmp0, 57159
361 define signext i32 @add_mul_combine_reject_e2(i32 signext %x) {
362 ; RV32IMB-LABEL: add_mul_combine_reject_e2:
364 ; RV32IMB-NEXT: addi a0, a0, 1971
365 ; RV32IMB-NEXT: li a1, 29
366 ; RV32IMB-NEXT: mul a0, a0, a1
369 ; RV64IMB-LABEL: add_mul_combine_reject_e2:
371 ; RV64IMB-NEXT: addiw a0, a0, 1971
372 ; RV64IMB-NEXT: li a1, 29
373 ; RV64IMB-NEXT: mulw a0, a0, a1
375 %tmp0 = mul i32 %x, 29
376 %tmp1 = add i32 %tmp0, 57159
380 define i64 @add_mul_combine_reject_e3(i64 %x) {
381 ; RV32IMB-LABEL: add_mul_combine_reject_e3:
383 ; RV32IMB-NEXT: li a2, 29
384 ; RV32IMB-NEXT: mul a1, a1, a2
385 ; RV32IMB-NEXT: mulhu a3, a0, a2
386 ; RV32IMB-NEXT: add a1, a3, a1
387 ; RV32IMB-NEXT: mul a2, a0, a2
388 ; RV32IMB-NEXT: lui a0, 14
389 ; RV32IMB-NEXT: addi a0, a0, -185
390 ; RV32IMB-NEXT: add a0, a2, a0
391 ; RV32IMB-NEXT: sltu a2, a0, a2
392 ; RV32IMB-NEXT: add a1, a1, a2
395 ; RV64IMB-LABEL: add_mul_combine_reject_e3:
397 ; RV64IMB-NEXT: addi a0, a0, 1971
398 ; RV64IMB-NEXT: li a1, 29
399 ; RV64IMB-NEXT: mul a0, a0, a1
401 %tmp0 = mul i64 %x, 29
402 %tmp1 = add i64 %tmp0, 57159
406 define i32 @add_mul_combine_reject_f1(i32 %x) {
407 ; RV32IMB-LABEL: add_mul_combine_reject_f1:
409 ; RV32IMB-NEXT: addi a0, a0, 1972
410 ; RV32IMB-NEXT: li a1, 29
411 ; RV32IMB-NEXT: mul a0, a0, a1
412 ; RV32IMB-NEXT: addi a0, a0, 11
415 ; RV64IMB-LABEL: add_mul_combine_reject_f1:
417 ; RV64IMB-NEXT: addiw a0, a0, 1972
418 ; RV64IMB-NEXT: li a1, 29
419 ; RV64IMB-NEXT: mulw a0, a0, a1
420 ; RV64IMB-NEXT: addiw a0, a0, 11
422 %tmp0 = mul i32 %x, 29
423 %tmp1 = add i32 %tmp0, 57199
427 define signext i32 @add_mul_combine_reject_f2(i32 signext %x) {
428 ; RV32IMB-LABEL: add_mul_combine_reject_f2:
430 ; RV32IMB-NEXT: addi a0, a0, 1972
431 ; RV32IMB-NEXT: li a1, 29
432 ; RV32IMB-NEXT: mul a0, a0, a1
433 ; RV32IMB-NEXT: addi a0, a0, 11
436 ; RV64IMB-LABEL: add_mul_combine_reject_f2:
438 ; RV64IMB-NEXT: addiw a0, a0, 1972
439 ; RV64IMB-NEXT: li a1, 29
440 ; RV64IMB-NEXT: mulw a0, a0, a1
441 ; RV64IMB-NEXT: addiw a0, a0, 11
443 %tmp0 = mul i32 %x, 29
444 %tmp1 = add i32 %tmp0, 57199
448 define i64 @add_mul_combine_reject_f3(i64 %x) {
449 ; RV32IMB-LABEL: add_mul_combine_reject_f3:
451 ; RV32IMB-NEXT: li a2, 29
452 ; RV32IMB-NEXT: mul a1, a1, a2
453 ; RV32IMB-NEXT: mulhu a3, a0, a2
454 ; RV32IMB-NEXT: add a1, a3, a1
455 ; RV32IMB-NEXT: mul a2, a0, a2
456 ; RV32IMB-NEXT: lui a0, 14
457 ; RV32IMB-NEXT: addi a0, a0, -145
458 ; RV32IMB-NEXT: add a0, a2, a0
459 ; RV32IMB-NEXT: sltu a2, a0, a2
460 ; RV32IMB-NEXT: add a1, a1, a2
463 ; RV64IMB-LABEL: add_mul_combine_reject_f3:
465 ; RV64IMB-NEXT: addi a0, a0, 1972
466 ; RV64IMB-NEXT: li a1, 29
467 ; RV64IMB-NEXT: mul a0, a0, a1
468 ; RV64IMB-NEXT: addi a0, a0, 11
470 %tmp0 = mul i64 %x, 29
471 %tmp1 = add i64 %tmp0, 57199
475 define i32 @add_mul_combine_reject_g1(i32 %x) {
476 ; RV32IMB-LABEL: add_mul_combine_reject_g1:
478 ; RV32IMB-NEXT: addi a0, a0, 100
479 ; RV32IMB-NEXT: sh3add a1, a0, a0
480 ; RV32IMB-NEXT: sh3add a0, a1, a0
481 ; RV32IMB-NEXT: addi a0, a0, 10
484 ; RV64IMB-LABEL: add_mul_combine_reject_g1:
486 ; RV64IMB-NEXT: addi a0, a0, 100
487 ; RV64IMB-NEXT: sh3add a1, a0, a0
488 ; RV64IMB-NEXT: sh3add a0, a1, a0
489 ; RV64IMB-NEXT: addiw a0, a0, 10
491 %tmp0 = mul i32 %x, 73
492 %tmp1 = add i32 %tmp0, 7310
496 define signext i32 @add_mul_combine_reject_g2(i32 signext %x) {
497 ; RV32IMB-LABEL: add_mul_combine_reject_g2:
499 ; RV32IMB-NEXT: addi a0, a0, 100
500 ; RV32IMB-NEXT: sh3add a1, a0, a0
501 ; RV32IMB-NEXT: sh3add a0, a1, a0
502 ; RV32IMB-NEXT: addi a0, a0, 10
505 ; RV64IMB-LABEL: add_mul_combine_reject_g2:
507 ; RV64IMB-NEXT: addi a0, a0, 100
508 ; RV64IMB-NEXT: sh3add a1, a0, a0
509 ; RV64IMB-NEXT: sh3add a0, a1, a0
510 ; RV64IMB-NEXT: addiw a0, a0, 10
512 %tmp0 = mul i32 %x, 73
513 %tmp1 = add i32 %tmp0, 7310
517 define i64 @add_mul_combine_reject_g3(i64 %x) {
518 ; RV32IMB-LABEL: add_mul_combine_reject_g3:
520 ; RV32IMB-NEXT: li a2, 73
521 ; RV32IMB-NEXT: mul a1, a1, a2
522 ; RV32IMB-NEXT: mulhu a3, a0, a2
523 ; RV32IMB-NEXT: add a1, a3, a1
524 ; RV32IMB-NEXT: mul a2, a0, a2
525 ; RV32IMB-NEXT: lui a0, 2
526 ; RV32IMB-NEXT: addi a0, a0, -882
527 ; RV32IMB-NEXT: add a0, a2, a0
528 ; RV32IMB-NEXT: sltu a2, a0, a2
529 ; RV32IMB-NEXT: add a1, a1, a2
532 ; RV64IMB-LABEL: add_mul_combine_reject_g3:
534 ; RV64IMB-NEXT: addi a0, a0, 100
535 ; RV64IMB-NEXT: sh3add a1, a0, a0
536 ; RV64IMB-NEXT: sh3add a0, a1, a0
537 ; RV64IMB-NEXT: addi a0, a0, 10
539 %tmp0 = mul i64 %x, 73
540 %tmp1 = add i64 %tmp0, 7310
544 ; This test previously infinite looped in DAG combine.
545 define i64 @add_mul_combine_infinite_loop(i64 %x) {
546 ; RV32IMB-LABEL: add_mul_combine_infinite_loop:
548 ; RV32IMB-NEXT: li a2, 24
549 ; RV32IMB-NEXT: mulhu a2, a0, a2
550 ; RV32IMB-NEXT: sh1add a1, a1, a1
551 ; RV32IMB-NEXT: sh3add a1, a1, a2
552 ; RV32IMB-NEXT: sh1add a0, a0, a0
553 ; RV32IMB-NEXT: slli a2, a0, 3
554 ; RV32IMB-NEXT: addi a0, a2, 2047
555 ; RV32IMB-NEXT: addi a0, a0, 1
556 ; RV32IMB-NEXT: sltu a2, a0, a2
557 ; RV32IMB-NEXT: add a1, a1, a2
560 ; RV64IMB-LABEL: add_mul_combine_infinite_loop:
562 ; RV64IMB-NEXT: addi a0, a0, 86
563 ; RV64IMB-NEXT: sh1add a0, a0, a0
564 ; RV64IMB-NEXT: li a1, -16
565 ; RV64IMB-NEXT: sh3add a0, a0, a1
567 %tmp0 = mul i64 %x, 24
568 %tmp1 = add i64 %tmp0, 2048
572 define i32 @mul3000_add8990_a(i32 %x) {
573 ; RV32IMB-LABEL: mul3000_add8990_a:
575 ; RV32IMB-NEXT: addi a0, a0, 3
576 ; RV32IMB-NEXT: lui a1, 1
577 ; RV32IMB-NEXT: addi a1, a1, -1096
578 ; RV32IMB-NEXT: mul a0, a0, a1
579 ; RV32IMB-NEXT: addi a0, a0, -10
582 ; RV64IMB-LABEL: mul3000_add8990_a:
584 ; RV64IMB-NEXT: addiw a0, a0, 3
585 ; RV64IMB-NEXT: lui a1, 1
586 ; RV64IMB-NEXT: addiw a1, a1, -1096
587 ; RV64IMB-NEXT: mulw a0, a0, a1
588 ; RV64IMB-NEXT: addiw a0, a0, -10
590 %tmp0 = mul i32 %x, 3000
591 %tmp1 = add i32 %tmp0, 8990
595 define signext i32 @mul3000_add8990_b(i32 signext %x) {
596 ; RV32IMB-LABEL: mul3000_add8990_b:
598 ; RV32IMB-NEXT: addi a0, a0, 3
599 ; RV32IMB-NEXT: lui a1, 1
600 ; RV32IMB-NEXT: addi a1, a1, -1096
601 ; RV32IMB-NEXT: mul a0, a0, a1
602 ; RV32IMB-NEXT: addi a0, a0, -10
605 ; RV64IMB-LABEL: mul3000_add8990_b:
607 ; RV64IMB-NEXT: addiw a0, a0, 3
608 ; RV64IMB-NEXT: lui a1, 1
609 ; RV64IMB-NEXT: addiw a1, a1, -1096
610 ; RV64IMB-NEXT: mulw a0, a0, a1
611 ; RV64IMB-NEXT: addiw a0, a0, -10
613 %tmp0 = mul i32 %x, 3000
614 %tmp1 = add i32 %tmp0, 8990
618 define i64 @mul3000_add8990_c(i64 %x) {
619 ; RV32IMB-LABEL: mul3000_add8990_c:
621 ; RV32IMB-NEXT: lui a2, 1
622 ; RV32IMB-NEXT: addi a2, a2, -1096
623 ; RV32IMB-NEXT: mul a1, a1, a2
624 ; RV32IMB-NEXT: mulhu a3, a0, a2
625 ; RV32IMB-NEXT: add a1, a3, a1
626 ; RV32IMB-NEXT: mul a2, a0, a2
627 ; RV32IMB-NEXT: lui a0, 2
628 ; RV32IMB-NEXT: addi a0, a0, 798
629 ; RV32IMB-NEXT: add a0, a2, a0
630 ; RV32IMB-NEXT: sltu a2, a0, a2
631 ; RV32IMB-NEXT: add a1, a1, a2
634 ; RV64IMB-LABEL: mul3000_add8990_c:
636 ; RV64IMB-NEXT: addi a0, a0, 3
637 ; RV64IMB-NEXT: lui a1, 1
638 ; RV64IMB-NEXT: addiw a1, a1, -1096
639 ; RV64IMB-NEXT: mul a0, a0, a1
640 ; RV64IMB-NEXT: addi a0, a0, -10
642 %tmp0 = mul i64 %x, 3000
643 %tmp1 = add i64 %tmp0, 8990
647 define i32 @mul3000_sub8990_a(i32 %x) {
648 ; RV32IMB-LABEL: mul3000_sub8990_a:
650 ; RV32IMB-NEXT: addi a0, a0, -3
651 ; RV32IMB-NEXT: lui a1, 1
652 ; RV32IMB-NEXT: addi a1, a1, -1096
653 ; RV32IMB-NEXT: mul a0, a0, a1
654 ; RV32IMB-NEXT: addi a0, a0, 10
657 ; RV64IMB-LABEL: mul3000_sub8990_a:
659 ; RV64IMB-NEXT: addiw a0, a0, -3
660 ; RV64IMB-NEXT: lui a1, 1
661 ; RV64IMB-NEXT: addiw a1, a1, -1096
662 ; RV64IMB-NEXT: mulw a0, a0, a1
663 ; RV64IMB-NEXT: addiw a0, a0, 10
665 %tmp0 = mul i32 %x, 3000
666 %tmp1 = add i32 %tmp0, -8990
670 define signext i32 @mul3000_sub8990_b(i32 signext %x) {
671 ; RV32IMB-LABEL: mul3000_sub8990_b:
673 ; RV32IMB-NEXT: addi a0, a0, -3
674 ; RV32IMB-NEXT: lui a1, 1
675 ; RV32IMB-NEXT: addi a1, a1, -1096
676 ; RV32IMB-NEXT: mul a0, a0, a1
677 ; RV32IMB-NEXT: addi a0, a0, 10
680 ; RV64IMB-LABEL: mul3000_sub8990_b:
682 ; RV64IMB-NEXT: addiw a0, a0, -3
683 ; RV64IMB-NEXT: lui a1, 1
684 ; RV64IMB-NEXT: addiw a1, a1, -1096
685 ; RV64IMB-NEXT: mulw a0, a0, a1
686 ; RV64IMB-NEXT: addiw a0, a0, 10
688 %tmp0 = mul i32 %x, 3000
689 %tmp1 = add i32 %tmp0, -8990
693 define i64 @mul3000_sub8990_c(i64 %x) {
694 ; RV32IMB-LABEL: mul3000_sub8990_c:
696 ; RV32IMB-NEXT: lui a2, 1
697 ; RV32IMB-NEXT: addi a2, a2, -1096
698 ; RV32IMB-NEXT: mul a1, a1, a2
699 ; RV32IMB-NEXT: mulhu a3, a0, a2
700 ; RV32IMB-NEXT: add a1, a3, a1
701 ; RV32IMB-NEXT: mul a2, a0, a2
702 ; RV32IMB-NEXT: lui a0, 1048574
703 ; RV32IMB-NEXT: addi a0, a0, -798
704 ; RV32IMB-NEXT: add a0, a2, a0
705 ; RV32IMB-NEXT: sltu a2, a0, a2
706 ; RV32IMB-NEXT: add a1, a1, a2
707 ; RV32IMB-NEXT: addi a1, a1, -1
710 ; RV64IMB-LABEL: mul3000_sub8990_c:
712 ; RV64IMB-NEXT: addi a0, a0, -3
713 ; RV64IMB-NEXT: lui a1, 1
714 ; RV64IMB-NEXT: addiw a1, a1, -1096
715 ; RV64IMB-NEXT: mul a0, a0, a1
716 ; RV64IMB-NEXT: addi a0, a0, 10
718 %tmp0 = mul i64 %x, 3000
719 %tmp1 = add i64 %tmp0, -8990
723 define i32 @mulneg3000_add8990_a(i32 %x) {
724 ; RV32IMB-LABEL: mulneg3000_add8990_a:
726 ; RV32IMB-NEXT: addi a0, a0, -3
727 ; RV32IMB-NEXT: lui a1, 1048575
728 ; RV32IMB-NEXT: addi a1, a1, 1096
729 ; RV32IMB-NEXT: mul a0, a0, a1
730 ; RV32IMB-NEXT: addi a0, a0, -10
733 ; RV64IMB-LABEL: mulneg3000_add8990_a:
735 ; RV64IMB-NEXT: addiw a0, a0, -3
736 ; RV64IMB-NEXT: lui a1, 1048575
737 ; RV64IMB-NEXT: addiw a1, a1, 1096
738 ; RV64IMB-NEXT: mulw a0, a0, a1
739 ; RV64IMB-NEXT: addiw a0, a0, -10
741 %tmp0 = mul i32 %x, -3000
742 %tmp1 = add i32 %tmp0, 8990
746 define signext i32 @mulneg3000_add8990_b(i32 signext %x) {
747 ; RV32IMB-LABEL: mulneg3000_add8990_b:
749 ; RV32IMB-NEXT: addi a0, a0, -3
750 ; RV32IMB-NEXT: lui a1, 1048575
751 ; RV32IMB-NEXT: addi a1, a1, 1096
752 ; RV32IMB-NEXT: mul a0, a0, a1
753 ; RV32IMB-NEXT: addi a0, a0, -10
756 ; RV64IMB-LABEL: mulneg3000_add8990_b:
758 ; RV64IMB-NEXT: addiw a0, a0, -3
759 ; RV64IMB-NEXT: lui a1, 1048575
760 ; RV64IMB-NEXT: addiw a1, a1, 1096
761 ; RV64IMB-NEXT: mulw a0, a0, a1
762 ; RV64IMB-NEXT: addiw a0, a0, -10
764 %tmp0 = mul i32 %x, -3000
765 %tmp1 = add i32 %tmp0, 8990
769 define i64 @mulneg3000_add8990_c(i64 %x) {
770 ; RV32IMB-LABEL: mulneg3000_add8990_c:
772 ; RV32IMB-NEXT: lui a2, 1048575
773 ; RV32IMB-NEXT: addi a2, a2, 1096
774 ; RV32IMB-NEXT: mul a1, a1, a2
775 ; RV32IMB-NEXT: mulhu a3, a0, a2
776 ; RV32IMB-NEXT: sub a3, a3, a0
777 ; RV32IMB-NEXT: add a1, a3, a1
778 ; RV32IMB-NEXT: mul a2, a0, a2
779 ; RV32IMB-NEXT: lui a0, 2
780 ; RV32IMB-NEXT: addi a0, a0, 798
781 ; RV32IMB-NEXT: add a0, a2, a0
782 ; RV32IMB-NEXT: sltu a2, a0, a2
783 ; RV32IMB-NEXT: add a1, a1, a2
786 ; RV64IMB-LABEL: mulneg3000_add8990_c:
788 ; RV64IMB-NEXT: addi a0, a0, -3
789 ; RV64IMB-NEXT: lui a1, 1048575
790 ; RV64IMB-NEXT: addiw a1, a1, 1096
791 ; RV64IMB-NEXT: mul a0, a0, a1
792 ; RV64IMB-NEXT: addi a0, a0, -10
794 %tmp0 = mul i64 %x, -3000
795 %tmp1 = add i64 %tmp0, 8990
799 define i32 @mulneg3000_sub8990_a(i32 %x) {
800 ; RV32IMB-LABEL: mulneg3000_sub8990_a:
802 ; RV32IMB-NEXT: addi a0, a0, 3
803 ; RV32IMB-NEXT: lui a1, 1048575
804 ; RV32IMB-NEXT: addi a1, a1, 1096
805 ; RV32IMB-NEXT: mul a0, a0, a1
806 ; RV32IMB-NEXT: addi a0, a0, 10
809 ; RV64IMB-LABEL: mulneg3000_sub8990_a:
811 ; RV64IMB-NEXT: addiw a0, a0, 3
812 ; RV64IMB-NEXT: lui a1, 1048575
813 ; RV64IMB-NEXT: addiw a1, a1, 1096
814 ; RV64IMB-NEXT: mulw a0, a0, a1
815 ; RV64IMB-NEXT: addiw a0, a0, 10
817 %tmp0 = mul i32 %x, -3000
818 %tmp1 = add i32 %tmp0, -8990
822 define signext i32 @mulneg3000_sub8990_b(i32 signext %x) {
823 ; RV32IMB-LABEL: mulneg3000_sub8990_b:
825 ; RV32IMB-NEXT: addi a0, a0, 3
826 ; RV32IMB-NEXT: lui a1, 1048575
827 ; RV32IMB-NEXT: addi a1, a1, 1096
828 ; RV32IMB-NEXT: mul a0, a0, a1
829 ; RV32IMB-NEXT: addi a0, a0, 10
832 ; RV64IMB-LABEL: mulneg3000_sub8990_b:
834 ; RV64IMB-NEXT: addiw a0, a0, 3
835 ; RV64IMB-NEXT: lui a1, 1048575
836 ; RV64IMB-NEXT: addiw a1, a1, 1096
837 ; RV64IMB-NEXT: mulw a0, a0, a1
838 ; RV64IMB-NEXT: addiw a0, a0, 10
840 %tmp0 = mul i32 %x, -3000
841 %tmp1 = add i32 %tmp0, -8990
845 define i64 @mulneg3000_sub8990_c(i64 %x) {
846 ; RV32IMB-LABEL: mulneg3000_sub8990_c:
848 ; RV32IMB-NEXT: lui a2, 1048575
849 ; RV32IMB-NEXT: addi a2, a2, 1096
850 ; RV32IMB-NEXT: mul a1, a1, a2
851 ; RV32IMB-NEXT: mulhu a3, a0, a2
852 ; RV32IMB-NEXT: sub a3, a3, a0
853 ; RV32IMB-NEXT: add a1, a3, a1
854 ; RV32IMB-NEXT: mul a2, a0, a2
855 ; RV32IMB-NEXT: lui a0, 1048574
856 ; RV32IMB-NEXT: addi a0, a0, -798
857 ; RV32IMB-NEXT: add a0, a2, a0
858 ; RV32IMB-NEXT: sltu a2, a0, a2
859 ; RV32IMB-NEXT: add a1, a1, a2
860 ; RV32IMB-NEXT: addi a1, a1, -1
863 ; RV64IMB-LABEL: mulneg3000_sub8990_c:
865 ; RV64IMB-NEXT: addi a0, a0, 3
866 ; RV64IMB-NEXT: lui a1, 1048575
867 ; RV64IMB-NEXT: addiw a1, a1, 1096
868 ; RV64IMB-NEXT: mul a0, a0, a1
869 ; RV64IMB-NEXT: addi a0, a0, 10
871 %tmp0 = mul i64 %x, -3000
872 %tmp1 = add i64 %tmp0, -8990
876 ; This test case previously caused an infinite loop between transformations
877 ; performed in RISCVISelLowering;:transformAddImmMulImm and
878 ; DAGCombiner::visitMUL.
879 define i1 @pr53831(i32 %x) {
880 ; RV32IMB-LABEL: pr53831:
882 ; RV32IMB-NEXT: li a0, 0
885 ; RV64IMB-LABEL: pr53831:
887 ; RV64IMB-NEXT: li a0, 0
889 %tmp0 = add i32 %x, 1
890 %tmp1 = mul i32 %tmp0, 24
891 %tmp2 = add i32 %tmp1, 1
892 %tmp3 = mul i32 %x, 24
893 %tmp4 = add i32 %tmp3, 2048
894 %tmp5 = icmp eq i32 %tmp4, %tmp2