1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
3 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs < %s \
4 ; RUN: | FileCheck -check-prefix=RV32I %s
5 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
6 ; RUN: | FileCheck -check-prefix=RV64I %s
8 ;; Test that (add (shl x, c0), c1) can be transformed to
9 ;; (add (shl (add x, c1>>c0), c0), c1-(c1>>c0<<c0)) or
10 ;; (shl (add x, c1>>c0), c0) if profitable.
12 define i32 @shl5_add1184_a(i32 %x) {
13 ; RV32I-LABEL: shl5_add1184_a:
15 ; RV32I-NEXT: slli a0, a0, 5
16 ; RV32I-NEXT: addi a0, a0, 1184
19 ; RV64I-LABEL: shl5_add1184_a:
21 ; RV64I-NEXT: slli a0, a0, 5
22 ; RV64I-NEXT: addiw a0, a0, 1184
25 %tmp1 = add i32 %tmp0, 1184
29 define signext i32 @shl5_add1184_b(i32 signext %x) {
30 ; RV32I-LABEL: shl5_add1184_b:
32 ; RV32I-NEXT: slli a0, a0, 5
33 ; RV32I-NEXT: addi a0, a0, 1184
36 ; RV64I-LABEL: shl5_add1184_b:
38 ; RV64I-NEXT: slli a0, a0, 5
39 ; RV64I-NEXT: addiw a0, a0, 1184
42 %tmp1 = add i32 %tmp0, 1184
46 define i64 @shl5_add1184_c(i64 %x) {
47 ; RV32I-LABEL: shl5_add1184_c:
49 ; RV32I-NEXT: srli a2, a0, 27
50 ; RV32I-NEXT: slli a1, a1, 5
51 ; RV32I-NEXT: or a1, a1, a2
52 ; RV32I-NEXT: slli a2, a0, 5
53 ; RV32I-NEXT: addi a0, a2, 1184
54 ; RV32I-NEXT: sltu a2, a0, a2
55 ; RV32I-NEXT: add a1, a1, a2
58 ; RV64I-LABEL: shl5_add1184_c:
60 ; RV64I-NEXT: slli a0, a0, 5
61 ; RV64I-NEXT: addi a0, a0, 1184
64 %tmp1 = add i64 %tmp0, 1184
68 define i32 @shl5_add101024_a(i32 %x) {
69 ; RV32I-LABEL: shl5_add101024_a:
71 ; RV32I-NEXT: slli a0, a0, 5
72 ; RV32I-NEXT: lui a1, 25
73 ; RV32I-NEXT: addi a1, a1, -1376
74 ; RV32I-NEXT: add a0, a0, a1
77 ; RV64I-LABEL: shl5_add101024_a:
79 ; RV64I-NEXT: slli a0, a0, 5
80 ; RV64I-NEXT: lui a1, 25
81 ; RV64I-NEXT: addi a1, a1, -1376
82 ; RV64I-NEXT: addw a0, a0, a1
85 %tmp1 = add i32 %tmp0, 101024
89 define signext i32 @shl5_add101024_b(i32 signext %x) {
90 ; RV32I-LABEL: shl5_add101024_b:
92 ; RV32I-NEXT: slli a0, a0, 5
93 ; RV32I-NEXT: lui a1, 25
94 ; RV32I-NEXT: addi a1, a1, -1376
95 ; RV32I-NEXT: add a0, a0, a1
98 ; RV64I-LABEL: shl5_add101024_b:
100 ; RV64I-NEXT: slli a0, a0, 5
101 ; RV64I-NEXT: lui a1, 25
102 ; RV64I-NEXT: addi a1, a1, -1376
103 ; RV64I-NEXT: addw a0, a0, a1
105 %tmp0 = shl i32 %x, 5
106 %tmp1 = add i32 %tmp0, 101024
110 define i64 @shl5_add101024_c(i64 %x) {
111 ; RV32I-LABEL: shl5_add101024_c:
113 ; RV32I-NEXT: srli a2, a0, 27
114 ; RV32I-NEXT: slli a1, a1, 5
115 ; RV32I-NEXT: or a1, a1, a2
116 ; RV32I-NEXT: slli a2, a0, 5
117 ; RV32I-NEXT: lui a0, 25
118 ; RV32I-NEXT: addi a0, a0, -1376
119 ; RV32I-NEXT: add a0, a2, a0
120 ; RV32I-NEXT: sltu a2, a0, a2
121 ; RV32I-NEXT: add a1, a1, a2
124 ; RV64I-LABEL: shl5_add101024_c:
126 ; RV64I-NEXT: slli a0, a0, 5
127 ; RV64I-NEXT: lui a1, 25
128 ; RV64I-NEXT: addiw a1, a1, -1376
129 ; RV64I-NEXT: add a0, a0, a1
131 %tmp0 = shl i64 %x, 5
132 %tmp1 = add i64 %tmp0, 101024
136 define i32 @shl5_add47968_a(i32 %x) {
137 ; RV32I-LABEL: shl5_add47968_a:
139 ; RV32I-NEXT: slli a0, a0, 5
140 ; RV32I-NEXT: lui a1, 12
141 ; RV32I-NEXT: addi a1, a1, -1184
142 ; RV32I-NEXT: add a0, a0, a1
145 ; RV64I-LABEL: shl5_add47968_a:
147 ; RV64I-NEXT: slli a0, a0, 5
148 ; RV64I-NEXT: lui a1, 12
149 ; RV64I-NEXT: addi a1, a1, -1184
150 ; RV64I-NEXT: addw a0, a0, a1
152 %tmp0 = shl i32 %x, 5
153 %tmp1 = add i32 %tmp0, 47968
157 define signext i32 @shl5_add47968_b(i32 signext %x) {
158 ; RV32I-LABEL: shl5_add47968_b:
160 ; RV32I-NEXT: slli a0, a0, 5
161 ; RV32I-NEXT: lui a1, 12
162 ; RV32I-NEXT: addi a1, a1, -1184
163 ; RV32I-NEXT: add a0, a0, a1
166 ; RV64I-LABEL: shl5_add47968_b:
168 ; RV64I-NEXT: slli a0, a0, 5
169 ; RV64I-NEXT: lui a1, 12
170 ; RV64I-NEXT: addi a1, a1, -1184
171 ; RV64I-NEXT: addw a0, a0, a1
173 %tmp0 = shl i32 %x, 5
174 %tmp1 = add i32 %tmp0, 47968
178 define i64 @shl5_add47968_c(i64 %x) {
179 ; RV32I-LABEL: shl5_add47968_c:
181 ; RV32I-NEXT: srli a2, a0, 27
182 ; RV32I-NEXT: slli a1, a1, 5
183 ; RV32I-NEXT: or a1, a1, a2
184 ; RV32I-NEXT: slli a2, a0, 5
185 ; RV32I-NEXT: lui a0, 12
186 ; RV32I-NEXT: addi a0, a0, -1184
187 ; RV32I-NEXT: add a0, a2, a0
188 ; RV32I-NEXT: sltu a2, a0, a2
189 ; RV32I-NEXT: add a1, a1, a2
192 ; RV64I-LABEL: shl5_add47968_c:
194 ; RV64I-NEXT: slli a0, a0, 5
195 ; RV64I-NEXT: lui a1, 12
196 ; RV64I-NEXT: addiw a1, a1, -1184
197 ; RV64I-NEXT: add a0, a0, a1
199 %tmp0 = shl i64 %x, 5
200 %tmp1 = add i64 %tmp0, 47968
204 define i32 @shl5_add47969_a(i32 %x) {
205 ; RV32I-LABEL: shl5_add47969_a:
207 ; RV32I-NEXT: slli a0, a0, 5
208 ; RV32I-NEXT: lui a1, 12
209 ; RV32I-NEXT: addi a1, a1, -1183
210 ; RV32I-NEXT: add a0, a0, a1
213 ; RV64I-LABEL: shl5_add47969_a:
215 ; RV64I-NEXT: slli a0, a0, 5
216 ; RV64I-NEXT: lui a1, 12
217 ; RV64I-NEXT: addi a1, a1, -1183
218 ; RV64I-NEXT: addw a0, a0, a1
220 %tmp0 = shl i32 %x, 5
221 %tmp1 = add i32 %tmp0, 47969
225 define signext i32 @shl5_add47969_b(i32 signext %x) {
226 ; RV32I-LABEL: shl5_add47969_b:
228 ; RV32I-NEXT: slli a0, a0, 5
229 ; RV32I-NEXT: lui a1, 12
230 ; RV32I-NEXT: addi a1, a1, -1183
231 ; RV32I-NEXT: add a0, a0, a1
234 ; RV64I-LABEL: shl5_add47969_b:
236 ; RV64I-NEXT: slli a0, a0, 5
237 ; RV64I-NEXT: lui a1, 12
238 ; RV64I-NEXT: addi a1, a1, -1183
239 ; RV64I-NEXT: addw a0, a0, a1
241 %tmp0 = shl i32 %x, 5
242 %tmp1 = add i32 %tmp0, 47969
246 define i64 @shl5_add47969_c(i64 %x) {
247 ; RV32I-LABEL: shl5_add47969_c:
249 ; RV32I-NEXT: srli a2, a0, 27
250 ; RV32I-NEXT: slli a1, a1, 5
251 ; RV32I-NEXT: or a1, a1, a2
252 ; RV32I-NEXT: slli a2, a0, 5
253 ; RV32I-NEXT: lui a0, 12
254 ; RV32I-NEXT: addi a0, a0, -1183
255 ; RV32I-NEXT: add a0, a2, a0
256 ; RV32I-NEXT: sltu a2, a0, a2
257 ; RV32I-NEXT: add a1, a1, a2
260 ; RV64I-LABEL: shl5_add47969_c:
262 ; RV64I-NEXT: slli a0, a0, 5
263 ; RV64I-NEXT: lui a1, 12
264 ; RV64I-NEXT: addiw a1, a1, -1183
265 ; RV64I-NEXT: add a0, a0, a1
267 %tmp0 = shl i64 %x, 5
268 %tmp1 = add i64 %tmp0, 47969
272 define i32 @shl5_sub47968_a(i32 %x) {
273 ; RV32I-LABEL: shl5_sub47968_a:
275 ; RV32I-NEXT: slli a0, a0, 5
276 ; RV32I-NEXT: lui a1, 1048564
277 ; RV32I-NEXT: addi a1, a1, 1184
278 ; RV32I-NEXT: add a0, a0, a1
281 ; RV64I-LABEL: shl5_sub47968_a:
283 ; RV64I-NEXT: slli a0, a0, 5
284 ; RV64I-NEXT: lui a1, 1048564
285 ; RV64I-NEXT: addi a1, a1, 1184
286 ; RV64I-NEXT: addw a0, a0, a1
288 %tmp0 = shl i32 %x, 5
289 %tmp1 = add i32 %tmp0, -47968
293 define signext i32 @shl5_sub47968_b(i32 signext %x) {
294 ; RV32I-LABEL: shl5_sub47968_b:
296 ; RV32I-NEXT: slli a0, a0, 5
297 ; RV32I-NEXT: lui a1, 1048564
298 ; RV32I-NEXT: addi a1, a1, 1184
299 ; RV32I-NEXT: add a0, a0, a1
302 ; RV64I-LABEL: shl5_sub47968_b:
304 ; RV64I-NEXT: slli a0, a0, 5
305 ; RV64I-NEXT: lui a1, 1048564
306 ; RV64I-NEXT: addi a1, a1, 1184
307 ; RV64I-NEXT: addw a0, a0, a1
309 %tmp0 = shl i32 %x, 5
310 %tmp1 = add i32 %tmp0, -47968
314 define i64 @shl5_sub47968_c(i64 %x) {
315 ; RV32I-LABEL: shl5_sub47968_c:
317 ; RV32I-NEXT: srli a2, a0, 27
318 ; RV32I-NEXT: slli a1, a1, 5
319 ; RV32I-NEXT: or a1, a1, a2
320 ; RV32I-NEXT: slli a2, a0, 5
321 ; RV32I-NEXT: lui a0, 1048564
322 ; RV32I-NEXT: addi a0, a0, 1184
323 ; RV32I-NEXT: add a0, a2, a0
324 ; RV32I-NEXT: sltu a2, a0, a2
325 ; RV32I-NEXT: add a1, a1, a2
326 ; RV32I-NEXT: addi a1, a1, -1
329 ; RV64I-LABEL: shl5_sub47968_c:
331 ; RV64I-NEXT: slli a0, a0, 5
332 ; RV64I-NEXT: lui a1, 1048564
333 ; RV64I-NEXT: addiw a1, a1, 1184
334 ; RV64I-NEXT: add a0, a0, a1
336 %tmp0 = shl i64 %x, 5
337 %tmp1 = add i64 %tmp0, -47968
341 define i32 @shl5_sub47969_a(i32 %x) {
342 ; RV32I-LABEL: shl5_sub47969_a:
344 ; RV32I-NEXT: slli a0, a0, 5
345 ; RV32I-NEXT: lui a1, 1048564
346 ; RV32I-NEXT: addi a1, a1, 1183
347 ; RV32I-NEXT: add a0, a0, a1
350 ; RV64I-LABEL: shl5_sub47969_a:
352 ; RV64I-NEXT: slli a0, a0, 5
353 ; RV64I-NEXT: lui a1, 1048564
354 ; RV64I-NEXT: addi a1, a1, 1183
355 ; RV64I-NEXT: addw a0, a0, a1
357 %tmp0 = shl i32 %x, 5
358 %tmp1 = add i32 %tmp0, -47969
362 define signext i32 @shl5_sub47969_b(i32 signext %x) {
363 ; RV32I-LABEL: shl5_sub47969_b:
365 ; RV32I-NEXT: slli a0, a0, 5
366 ; RV32I-NEXT: lui a1, 1048564
367 ; RV32I-NEXT: addi a1, a1, 1183
368 ; RV32I-NEXT: add a0, a0, a1
371 ; RV64I-LABEL: shl5_sub47969_b:
373 ; RV64I-NEXT: slli a0, a0, 5
374 ; RV64I-NEXT: lui a1, 1048564
375 ; RV64I-NEXT: addi a1, a1, 1183
376 ; RV64I-NEXT: addw a0, a0, a1
378 %tmp0 = shl i32 %x, 5
379 %tmp1 = add i32 %tmp0, -47969
383 define i64 @shl5_sub47969_c(i64 %x) {
384 ; RV32I-LABEL: shl5_sub47969_c:
386 ; RV32I-NEXT: srli a2, a0, 27
387 ; RV32I-NEXT: slli a1, a1, 5
388 ; RV32I-NEXT: or a1, a1, a2
389 ; RV32I-NEXT: slli a2, a0, 5
390 ; RV32I-NEXT: lui a0, 1048564
391 ; RV32I-NEXT: addi a0, a0, 1183
392 ; RV32I-NEXT: add a0, a2, a0
393 ; RV32I-NEXT: sltu a2, a0, a2
394 ; RV32I-NEXT: add a1, a1, a2
395 ; RV32I-NEXT: addi a1, a1, -1
398 ; RV64I-LABEL: shl5_sub47969_c:
400 ; RV64I-NEXT: slli a0, a0, 5
401 ; RV64I-NEXT: lui a1, 1048564
402 ; RV64I-NEXT: addiw a1, a1, 1183
403 ; RV64I-NEXT: add a0, a0, a1
405 %tmp0 = shl i64 %x, 5
406 %tmp1 = add i64 %tmp0, -47969