1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --extra_scrub
2 ; RUN: llc -mtriple=riscv64 -mattr=+m -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefixes=RV64I
4 ; RUN: llc -mtriple=riscv64 -mattr=+m,+xtheadba -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefixes=RV64XTHEADBA
7 define signext i16 @th_addsl_1(i64 %0, ptr %1) {
8 ; RV64I-LABEL: th_addsl_1:
10 ; RV64I-NEXT: slli a0, a0, 1
11 ; RV64I-NEXT: add a0, a1, a0
12 ; RV64I-NEXT: lh a0, 0(a0)
15 ; RV64XTHEADBA-LABEL: th_addsl_1:
16 ; RV64XTHEADBA: # %bb.0:
17 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 1
18 ; RV64XTHEADBA-NEXT: lh a0, 0(a0)
19 ; RV64XTHEADBA-NEXT: ret
20 %3 = getelementptr inbounds i16, ptr %1, i64 %0
25 define signext i32 @th_addsl_2(i64 %0, ptr %1) {
26 ; RV64I-LABEL: th_addsl_2:
28 ; RV64I-NEXT: slli a0, a0, 2
29 ; RV64I-NEXT: add a0, a1, a0
30 ; RV64I-NEXT: lw a0, 0(a0)
33 ; RV64XTHEADBA-LABEL: th_addsl_2:
34 ; RV64XTHEADBA: # %bb.0:
35 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 2
36 ; RV64XTHEADBA-NEXT: lw a0, 0(a0)
37 ; RV64XTHEADBA-NEXT: ret
38 %3 = getelementptr inbounds i32, ptr %1, i64 %0
43 define i64 @th_addsl_3(i64 %0, ptr %1) {
44 ; RV64I-LABEL: th_addsl_3:
46 ; RV64I-NEXT: slli a0, a0, 3
47 ; RV64I-NEXT: add a0, a1, a0
48 ; RV64I-NEXT: ld a0, 0(a0)
51 ; RV64XTHEADBA-LABEL: th_addsl_3:
52 ; RV64XTHEADBA: # %bb.0:
53 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 3
54 ; RV64XTHEADBA-NEXT: ld a0, 0(a0)
55 ; RV64XTHEADBA-NEXT: ret
56 %3 = getelementptr inbounds i64, ptr %1, i64 %0
61 ; Type legalization inserts a sext_inreg after the first add. That add will be
62 ; selected as th.addsl which does not sign extend. SimplifyDemandedBits is unable
63 ; to remove the sext_inreg because it has multiple uses. The ashr will use the
64 ; sext_inreg to become sraiw. This leaves the sext_inreg only used by the shl.
65 ; If the shl is selected as sllw, we don't need the sext_inreg.
66 define i64 @th_addsl_2_extra_sext(i32 %x, i32 %y, i32 %z) {
67 ; RV64I-LABEL: th_addsl_2_extra_sext:
69 ; RV64I-NEXT: slli a0, a0, 2
70 ; RV64I-NEXT: add a0, a0, a1
71 ; RV64I-NEXT: sllw a1, a2, a0
72 ; RV64I-NEXT: sraiw a0, a0, 2
73 ; RV64I-NEXT: mul a0, a1, a0
76 ; RV64XTHEADBA-LABEL: th_addsl_2_extra_sext:
77 ; RV64XTHEADBA: # %bb.0:
78 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 2
79 ; RV64XTHEADBA-NEXT: sllw a1, a2, a0
80 ; RV64XTHEADBA-NEXT: sraiw a0, a0, 2
81 ; RV64XTHEADBA-NEXT: mul a0, a1, a0
82 ; RV64XTHEADBA-NEXT: ret
87 %e = sext i32 %c to i64
88 %f = sext i32 %d to i64
93 define i64 @addmul6(i64 %a, i64 %b) {
94 ; RV64I-LABEL: addmul6:
96 ; RV64I-NEXT: li a2, 6
97 ; RV64I-NEXT: mul a0, a0, a2
98 ; RV64I-NEXT: add a0, a0, a1
101 ; RV64XTHEADBA-LABEL: addmul6:
102 ; RV64XTHEADBA: # %bb.0:
103 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 1
104 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 1
105 ; RV64XTHEADBA-NEXT: ret
111 define i64 @addmul10(i64 %a, i64 %b) {
112 ; RV64I-LABEL: addmul10:
114 ; RV64I-NEXT: li a2, 10
115 ; RV64I-NEXT: mul a0, a0, a2
116 ; RV64I-NEXT: add a0, a0, a1
119 ; RV64XTHEADBA-LABEL: addmul10:
120 ; RV64XTHEADBA: # %bb.0:
121 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 2
122 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 1
123 ; RV64XTHEADBA-NEXT: ret
129 define i64 @addmul12(i64 %a, i64 %b) {
130 ; RV64I-LABEL: addmul12:
132 ; RV64I-NEXT: li a2, 12
133 ; RV64I-NEXT: mul a0, a0, a2
134 ; RV64I-NEXT: add a0, a0, a1
137 ; RV64XTHEADBA-LABEL: addmul12:
138 ; RV64XTHEADBA: # %bb.0:
139 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 1
140 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 2
141 ; RV64XTHEADBA-NEXT: ret
147 define i64 @addmul18(i64 %a, i64 %b) {
148 ; RV64I-LABEL: addmul18:
150 ; RV64I-NEXT: li a2, 18
151 ; RV64I-NEXT: mul a0, a0, a2
152 ; RV64I-NEXT: add a0, a0, a1
155 ; RV64XTHEADBA-LABEL: addmul18:
156 ; RV64XTHEADBA: # %bb.0:
157 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 3
158 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 1
159 ; RV64XTHEADBA-NEXT: ret
165 define i64 @addmul20(i64 %a, i64 %b) {
166 ; RV64I-LABEL: addmul20:
168 ; RV64I-NEXT: li a2, 20
169 ; RV64I-NEXT: mul a0, a0, a2
170 ; RV64I-NEXT: add a0, a0, a1
173 ; RV64XTHEADBA-LABEL: addmul20:
174 ; RV64XTHEADBA: # %bb.0:
175 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 2
176 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 2
177 ; RV64XTHEADBA-NEXT: ret
183 define i64 @addmul24(i64 %a, i64 %b) {
184 ; RV64I-LABEL: addmul24:
186 ; RV64I-NEXT: li a2, 24
187 ; RV64I-NEXT: mul a0, a0, a2
188 ; RV64I-NEXT: add a0, a0, a1
191 ; RV64XTHEADBA-LABEL: addmul24:
192 ; RV64XTHEADBA: # %bb.0:
193 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 1
194 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 3
195 ; RV64XTHEADBA-NEXT: ret
201 define i64 @addmul36(i64 %a, i64 %b) {
202 ; RV64I-LABEL: addmul36:
204 ; RV64I-NEXT: li a2, 36
205 ; RV64I-NEXT: mul a0, a0, a2
206 ; RV64I-NEXT: add a0, a0, a1
209 ; RV64XTHEADBA-LABEL: addmul36:
210 ; RV64XTHEADBA: # %bb.0:
211 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 3
212 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 2
213 ; RV64XTHEADBA-NEXT: ret
219 define i64 @addmul40(i64 %a, i64 %b) {
220 ; RV64I-LABEL: addmul40:
222 ; RV64I-NEXT: li a2, 40
223 ; RV64I-NEXT: mul a0, a0, a2
224 ; RV64I-NEXT: add a0, a0, a1
227 ; RV64XTHEADBA-LABEL: addmul40:
228 ; RV64XTHEADBA: # %bb.0:
229 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 2
230 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 3
231 ; RV64XTHEADBA-NEXT: ret
237 define i64 @addmul72(i64 %a, i64 %b) {
238 ; RV64I-LABEL: addmul72:
240 ; RV64I-NEXT: li a2, 72
241 ; RV64I-NEXT: mul a0, a0, a2
242 ; RV64I-NEXT: add a0, a0, a1
245 ; RV64XTHEADBA-LABEL: addmul72:
246 ; RV64XTHEADBA: # %bb.0:
247 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 3
248 ; RV64XTHEADBA-NEXT: th.addsl a0, a1, a0, 3
249 ; RV64XTHEADBA-NEXT: ret
255 define i64 @mul96(i64 %a) {
256 ; RV64I-LABEL: mul96:
258 ; RV64I-NEXT: li a1, 96
259 ; RV64I-NEXT: mul a0, a0, a1
262 ; RV64XTHEADBA-LABEL: mul96:
263 ; RV64XTHEADBA: # %bb.0:
264 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 1
265 ; RV64XTHEADBA-NEXT: slli a0, a0, 5
266 ; RV64XTHEADBA-NEXT: ret
271 define i64 @mul160(i64 %a) {
272 ; RV64I-LABEL: mul160:
274 ; RV64I-NEXT: li a1, 160
275 ; RV64I-NEXT: mul a0, a0, a1
278 ; RV64XTHEADBA-LABEL: mul160:
279 ; RV64XTHEADBA: # %bb.0:
280 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 2
281 ; RV64XTHEADBA-NEXT: slli a0, a0, 5
282 ; RV64XTHEADBA-NEXT: ret
287 define i64 @mul200(i64 %a) {
288 ; RV64I-LABEL: mul200:
290 ; RV64I-NEXT: li a1, 200
291 ; RV64I-NEXT: mul a0, a0, a1
294 ; RV64XTHEADBA-LABEL: mul200:
295 ; RV64XTHEADBA: # %bb.0:
296 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 2
297 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 2
298 ; RV64XTHEADBA-NEXT: slli a0, a0, 3
299 ; RV64XTHEADBA-NEXT: ret
304 define i64 @mul288(i64 %a) {
305 ; RV64I-LABEL: mul288:
307 ; RV64I-NEXT: li a1, 288
308 ; RV64I-NEXT: mul a0, a0, a1
311 ; RV64XTHEADBA-LABEL: mul288:
312 ; RV64XTHEADBA: # %bb.0:
313 ; RV64XTHEADBA-NEXT: th.addsl a0, a0, a0, 3
314 ; RV64XTHEADBA-NEXT: slli a0, a0, 5
315 ; RV64XTHEADBA-NEXT: ret