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,+experimental-zba -verify-machineinstrs < %s \
6 ; RUN: | FileCheck -check-prefix=RV32IMB %s
7 ; RUN: llc -mtriple=riscv64 -mattr=+m,+experimental-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: addi a1, zero, 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: addi a1, zero, 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: addi a1, zero, 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: addi a1, zero, 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: addi a2, zero, 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: addi a1, zero, 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: addi a1, zero, 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: addi a1, zero, 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: addi a1, zero, 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: addi a1, zero, 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: addi a2, zero, 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: addi a1, zero, 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 a1, zero, 29
150 ; RV32IMB-NEXT: mul a0, a0, a1
151 ; RV32IMB-NEXT: lui a1, 14
152 ; RV32IMB-NEXT: addi a1, a1, -185
153 ; RV32IMB-NEXT: add a0, a0, a1
156 ; RV64IMB-LABEL: add_mul_combine_reject_a1:
158 ; RV64IMB-NEXT: addi a1, zero, 29
159 ; RV64IMB-NEXT: mulw a0, a0, a1
160 ; RV64IMB-NEXT: lui a1, 14
161 ; RV64IMB-NEXT: addiw a1, a1, -185
162 ; RV64IMB-NEXT: addw a0, a0, a1
164 %tmp0 = add i32 %x, 1971
165 %tmp1 = mul i32 %tmp0, 29
169 define signext i32 @add_mul_combine_reject_a2(i32 signext %x) {
170 ; RV32IMB-LABEL: add_mul_combine_reject_a2:
172 ; RV32IMB-NEXT: addi a1, zero, 29
173 ; RV32IMB-NEXT: mul a0, a0, a1
174 ; RV32IMB-NEXT: lui a1, 14
175 ; RV32IMB-NEXT: addi a1, a1, -185
176 ; RV32IMB-NEXT: add a0, a0, a1
179 ; RV64IMB-LABEL: add_mul_combine_reject_a2:
181 ; RV64IMB-NEXT: addi a1, zero, 29
182 ; RV64IMB-NEXT: mulw a0, a0, a1
183 ; RV64IMB-NEXT: lui a1, 14
184 ; RV64IMB-NEXT: addiw a1, a1, -185
185 ; RV64IMB-NEXT: addw a0, a0, a1
187 %tmp0 = add i32 %x, 1971
188 %tmp1 = mul i32 %tmp0, 29
192 define i64 @add_mul_combine_reject_a3(i64 %x) {
193 ; RV32IMB-LABEL: add_mul_combine_reject_a3:
195 ; RV32IMB-NEXT: addi a2, zero, 29
196 ; RV32IMB-NEXT: mul a1, a1, a2
197 ; RV32IMB-NEXT: mulhu a3, a0, a2
198 ; RV32IMB-NEXT: add a1, a3, a1
199 ; RV32IMB-NEXT: mul a2, a0, a2
200 ; RV32IMB-NEXT: lui a0, 14
201 ; RV32IMB-NEXT: addi a0, a0, -185
202 ; RV32IMB-NEXT: add a0, a2, a0
203 ; RV32IMB-NEXT: sltu a2, a0, a2
204 ; RV32IMB-NEXT: add a1, a1, a2
207 ; RV64IMB-LABEL: add_mul_combine_reject_a3:
209 ; RV64IMB-NEXT: addi a1, zero, 29
210 ; RV64IMB-NEXT: mul a0, a0, a1
211 ; RV64IMB-NEXT: lui a1, 14
212 ; RV64IMB-NEXT: addiw a1, a1, -185
213 ; RV64IMB-NEXT: add a0, a0, a1
215 %tmp0 = add i64 %x, 1971
216 %tmp1 = mul i64 %tmp0, 29
220 define i32 @add_mul_combine_reject_c1(i32 %x) {
221 ; RV32IMB-LABEL: add_mul_combine_reject_c1:
223 ; RV32IMB-NEXT: sh3add a1, a0, a0
224 ; RV32IMB-NEXT: sh3add a0, a1, a0
225 ; RV32IMB-NEXT: lui a1, 18
226 ; RV32IMB-NEXT: addi a1, a1, -728
227 ; RV32IMB-NEXT: add a0, a0, a1
230 ; RV64IMB-LABEL: add_mul_combine_reject_c1:
232 ; RV64IMB-NEXT: sh3add a1, a0, a0
233 ; RV64IMB-NEXT: sh3add a0, a1, a0
234 ; RV64IMB-NEXT: lui a1, 18
235 ; RV64IMB-NEXT: addiw a1, a1, -728
236 ; RV64IMB-NEXT: addw a0, a0, a1
238 %tmp0 = add i32 %x, 1000
239 %tmp1 = mul i32 %tmp0, 73
243 define signext i32 @add_mul_combine_reject_c2(i32 signext %x) {
244 ; RV32IMB-LABEL: add_mul_combine_reject_c2:
246 ; RV32IMB-NEXT: sh3add a1, a0, a0
247 ; RV32IMB-NEXT: sh3add a0, a1, a0
248 ; RV32IMB-NEXT: lui a1, 18
249 ; RV32IMB-NEXT: addi a1, a1, -728
250 ; RV32IMB-NEXT: add a0, a0, a1
253 ; RV64IMB-LABEL: add_mul_combine_reject_c2:
255 ; RV64IMB-NEXT: sh3add a1, a0, a0
256 ; RV64IMB-NEXT: sh3add a0, a1, a0
257 ; RV64IMB-NEXT: lui a1, 18
258 ; RV64IMB-NEXT: addiw a1, a1, -728
259 ; RV64IMB-NEXT: addw a0, a0, a1
261 %tmp0 = add i32 %x, 1000
262 %tmp1 = mul i32 %tmp0, 73
266 define i64 @add_mul_combine_reject_c3(i64 %x) {
267 ; RV32IMB-LABEL: add_mul_combine_reject_c3:
269 ; RV32IMB-NEXT: addi a2, zero, 73
270 ; RV32IMB-NEXT: mul a1, a1, a2
271 ; RV32IMB-NEXT: mulhu a3, a0, a2
272 ; RV32IMB-NEXT: add a1, a3, a1
273 ; RV32IMB-NEXT: mul a2, a0, a2
274 ; RV32IMB-NEXT: lui a0, 18
275 ; RV32IMB-NEXT: addi a0, a0, -728
276 ; RV32IMB-NEXT: add a0, a2, a0
277 ; RV32IMB-NEXT: sltu a2, a0, a2
278 ; RV32IMB-NEXT: add a1, a1, a2
281 ; RV64IMB-LABEL: add_mul_combine_reject_c3:
283 ; RV64IMB-NEXT: sh3add a1, a0, a0
284 ; RV64IMB-NEXT: sh3add a0, a1, a0
285 ; RV64IMB-NEXT: lui a1, 18
286 ; RV64IMB-NEXT: addiw a1, a1, -728
287 ; RV64IMB-NEXT: add a0, a0, a1
289 %tmp0 = add i64 %x, 1000
290 %tmp1 = mul i64 %tmp0, 73
294 define i32 @add_mul_combine_reject_d1(i32 %x) {
295 ; RV32IMB-LABEL: add_mul_combine_reject_d1:
297 ; RV32IMB-NEXT: sh1add a0, a0, a0
298 ; RV32IMB-NEXT: slli a0, a0, 6
299 ; RV32IMB-NEXT: lui a1, 47
300 ; RV32IMB-NEXT: addi a1, a1, -512
301 ; RV32IMB-NEXT: add a0, a0, a1
304 ; RV64IMB-LABEL: add_mul_combine_reject_d1:
306 ; RV64IMB-NEXT: sh1add a0, a0, a0
307 ; RV64IMB-NEXT: slli a0, a0, 6
308 ; RV64IMB-NEXT: lui a1, 47
309 ; RV64IMB-NEXT: addiw a1, a1, -512
310 ; RV64IMB-NEXT: addw a0, a0, a1
312 %tmp0 = add i32 %x, 1000
313 %tmp1 = mul i32 %tmp0, 192
317 define signext i32 @add_mul_combine_reject_d2(i32 signext %x) {
318 ; RV32IMB-LABEL: add_mul_combine_reject_d2:
320 ; RV32IMB-NEXT: sh1add a0, a0, a0
321 ; RV32IMB-NEXT: slli a0, a0, 6
322 ; RV32IMB-NEXT: lui a1, 47
323 ; RV32IMB-NEXT: addi a1, a1, -512
324 ; RV32IMB-NEXT: add a0, a0, a1
327 ; RV64IMB-LABEL: add_mul_combine_reject_d2:
329 ; RV64IMB-NEXT: sh1add a0, a0, a0
330 ; RV64IMB-NEXT: slli a0, a0, 6
331 ; RV64IMB-NEXT: lui a1, 47
332 ; RV64IMB-NEXT: addiw a1, a1, -512
333 ; RV64IMB-NEXT: addw a0, a0, a1
335 %tmp0 = add i32 %x, 1000
336 %tmp1 = mul i32 %tmp0, 192
340 define i64 @add_mul_combine_reject_d3(i64 %x) {
341 ; RV32IMB-LABEL: add_mul_combine_reject_d3:
343 ; RV32IMB-NEXT: addi a2, zero, 192
344 ; RV32IMB-NEXT: mulhu a2, a0, a2
345 ; RV32IMB-NEXT: sh1add a1, a1, a1
346 ; RV32IMB-NEXT: slli a1, a1, 6
347 ; RV32IMB-NEXT: add a1, a2, a1
348 ; RV32IMB-NEXT: sh1add a0, a0, a0
349 ; RV32IMB-NEXT: slli a2, a0, 6
350 ; RV32IMB-NEXT: lui a0, 47
351 ; RV32IMB-NEXT: addi a0, a0, -512
352 ; RV32IMB-NEXT: add a0, a2, a0
353 ; RV32IMB-NEXT: sltu a2, a0, a2
354 ; RV32IMB-NEXT: add a1, a1, a2
357 ; RV64IMB-LABEL: add_mul_combine_reject_d3:
359 ; RV64IMB-NEXT: sh1add a0, a0, a0
360 ; RV64IMB-NEXT: slli a0, a0, 6
361 ; RV64IMB-NEXT: lui a1, 47
362 ; RV64IMB-NEXT: addiw a1, a1, -512
363 ; RV64IMB-NEXT: add a0, a0, a1
365 %tmp0 = add i64 %x, 1000
366 %tmp1 = mul i64 %tmp0, 192