1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs < %s \
3 ; RUN: -riscv-experimental-rv64-legal-i32 | FileCheck -check-prefix=RV64I %s
4 ; RUN: llc -mtriple=riscv64 -mattr=+m -verify-machineinstrs < %s \
5 ; RUN: -riscv-experimental-rv64-legal-i32 | FileCheck -check-prefix=RV64IM %s
7 define i32 @urem(i32 %a, i32 %b) nounwind {
10 ; RV64I-NEXT: addi sp, sp, -16
11 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
12 ; RV64I-NEXT: slli a0, a0, 32
13 ; RV64I-NEXT: srli a0, a0, 32
14 ; RV64I-NEXT: slli a1, a1, 32
15 ; RV64I-NEXT: srli a1, a1, 32
16 ; RV64I-NEXT: call __umoddi3
17 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
18 ; RV64I-NEXT: addi sp, sp, 16
23 ; RV64IM-NEXT: remuw a0, a0, a1
29 define i32 @urem_constant_lhs(i32 %a) nounwind {
30 ; RV64I-LABEL: urem_constant_lhs:
32 ; RV64I-NEXT: addi sp, sp, -16
33 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
34 ; RV64I-NEXT: slli a0, a0, 32
35 ; RV64I-NEXT: srli a1, a0, 32
36 ; RV64I-NEXT: li a0, 10
37 ; RV64I-NEXT: call __umoddi3
38 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
39 ; RV64I-NEXT: addi sp, sp, 16
42 ; RV64IM-LABEL: urem_constant_lhs:
44 ; RV64IM-NEXT: li a1, 10
45 ; RV64IM-NEXT: remuw a0, a1, a0
51 define i32 @srem(i32 %a, i32 %b) nounwind {
54 ; RV64I-NEXT: addi sp, sp, -16
55 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
56 ; RV64I-NEXT: sext.w a0, a0
57 ; RV64I-NEXT: sext.w a1, a1
58 ; RV64I-NEXT: call __moddi3
59 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
60 ; RV64I-NEXT: addi sp, sp, 16
65 ; RV64IM-NEXT: remw a0, a0, a1
71 define i32 @srem_pow2(i32 %a) nounwind {
72 ; RV64I-LABEL: srem_pow2:
74 ; RV64I-NEXT: sraiw a1, a0, 31
75 ; RV64I-NEXT: srliw a1, a1, 29
76 ; RV64I-NEXT: add a1, a0, a1
77 ; RV64I-NEXT: andi a1, a1, -8
78 ; RV64I-NEXT: subw a0, a0, a1
81 ; RV64IM-LABEL: srem_pow2:
83 ; RV64IM-NEXT: sraiw a1, a0, 31
84 ; RV64IM-NEXT: srliw a1, a1, 29
85 ; RV64IM-NEXT: add a1, a0, a1
86 ; RV64IM-NEXT: andi a1, a1, -8
87 ; RV64IM-NEXT: subw a0, a0, a1
93 define i32 @srem_pow2_2(i32 %a) nounwind {
94 ; RV64I-LABEL: srem_pow2_2:
96 ; RV64I-NEXT: sraiw a1, a0, 31
97 ; RV64I-NEXT: srliw a1, a1, 16
98 ; RV64I-NEXT: add a1, a0, a1
99 ; RV64I-NEXT: lui a2, 1048560
100 ; RV64I-NEXT: and a1, a1, a2
101 ; RV64I-NEXT: subw a0, a0, a1
104 ; RV64IM-LABEL: srem_pow2_2:
106 ; RV64IM-NEXT: sraiw a1, a0, 31
107 ; RV64IM-NEXT: srliw a1, a1, 16
108 ; RV64IM-NEXT: add a1, a0, a1
109 ; RV64IM-NEXT: lui a2, 1048560
110 ; RV64IM-NEXT: and a1, a1, a2
111 ; RV64IM-NEXT: subw a0, a0, a1
113 %1 = srem i32 %a, 65536
117 define i32 @srem_constant_lhs(i32 %a) nounwind {
118 ; RV64I-LABEL: srem_constant_lhs:
120 ; RV64I-NEXT: addi sp, sp, -16
121 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
122 ; RV64I-NEXT: sext.w a1, a0
123 ; RV64I-NEXT: li a0, -10
124 ; RV64I-NEXT: call __moddi3
125 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
126 ; RV64I-NEXT: addi sp, sp, 16
129 ; RV64IM-LABEL: srem_constant_lhs:
131 ; RV64IM-NEXT: li a1, -10
132 ; RV64IM-NEXT: remw a0, a1, a0
134 %1 = srem i32 -10, %a
138 define i64 @urem64(i64 %a, i64 %b) nounwind {
139 ; RV64I-LABEL: urem64:
141 ; RV64I-NEXT: tail __umoddi3
143 ; RV64IM-LABEL: urem64:
145 ; RV64IM-NEXT: remu a0, a0, a1
151 define i64 @urem64_constant_lhs(i64 %a) nounwind {
152 ; RV64I-LABEL: urem64_constant_lhs:
154 ; RV64I-NEXT: mv a1, a0
155 ; RV64I-NEXT: li a0, 10
156 ; RV64I-NEXT: tail __umoddi3
158 ; RV64IM-LABEL: urem64_constant_lhs:
160 ; RV64IM-NEXT: li a1, 10
161 ; RV64IM-NEXT: remu a0, a1, a0
167 define i64 @srem64(i64 %a, i64 %b) nounwind {
168 ; RV64I-LABEL: srem64:
170 ; RV64I-NEXT: tail __moddi3
172 ; RV64IM-LABEL: srem64:
174 ; RV64IM-NEXT: rem a0, a0, a1
180 define i64 @srem64_constant_lhs(i64 %a) nounwind {
181 ; RV64I-LABEL: srem64_constant_lhs:
183 ; RV64I-NEXT: mv a1, a0
184 ; RV64I-NEXT: li a0, -10
185 ; RV64I-NEXT: tail __moddi3
187 ; RV64IM-LABEL: srem64_constant_lhs:
189 ; RV64IM-NEXT: li a1, -10
190 ; RV64IM-NEXT: rem a0, a1, a0
192 %1 = srem i64 -10, %a
196 define i8 @urem8(i8 %a, i8 %b) nounwind {
197 ; RV64I-LABEL: urem8:
199 ; RV64I-NEXT: addi sp, sp, -16
200 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
201 ; RV64I-NEXT: andi a0, a0, 255
202 ; RV64I-NEXT: andi a1, a1, 255
203 ; RV64I-NEXT: call __umoddi3
204 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
205 ; RV64I-NEXT: addi sp, sp, 16
208 ; RV64IM-LABEL: urem8:
210 ; RV64IM-NEXT: andi a1, a1, 255
211 ; RV64IM-NEXT: andi a0, a0, 255
212 ; RV64IM-NEXT: remuw a0, a0, a1
218 define i8 @urem8_constant_lhs(i8 %a) nounwind {
219 ; RV64I-LABEL: urem8_constant_lhs:
221 ; RV64I-NEXT: addi sp, sp, -16
222 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
223 ; RV64I-NEXT: andi a1, a0, 255
224 ; RV64I-NEXT: li a0, 10
225 ; RV64I-NEXT: call __umoddi3
226 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
227 ; RV64I-NEXT: addi sp, sp, 16
230 ; RV64IM-LABEL: urem8_constant_lhs:
232 ; RV64IM-NEXT: andi a0, a0, 255
233 ; RV64IM-NEXT: li a1, 10
234 ; RV64IM-NEXT: remuw a0, a1, a0
241 define i8 @srem8(i8 %a, i8 %b) nounwind {
242 ; RV64I-LABEL: srem8:
244 ; RV64I-NEXT: addi sp, sp, -16
245 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
246 ; RV64I-NEXT: slli a1, a1, 24
247 ; RV64I-NEXT: sraiw a1, a1, 24
248 ; RV64I-NEXT: slli a0, a0, 24
249 ; RV64I-NEXT: sraiw a0, a0, 24
250 ; RV64I-NEXT: call __moddi3
251 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
252 ; RV64I-NEXT: addi sp, sp, 16
255 ; RV64IM-LABEL: srem8:
257 ; RV64IM-NEXT: slli a1, a1, 24
258 ; RV64IM-NEXT: sraiw a1, a1, 24
259 ; RV64IM-NEXT: slli a0, a0, 24
260 ; RV64IM-NEXT: sraiw a0, a0, 24
261 ; RV64IM-NEXT: remw a0, a0, a1
267 define i8 @srem8_constant_lhs(i8 %a) nounwind {
268 ; RV64I-LABEL: srem8_constant_lhs:
270 ; RV64I-NEXT: addi sp, sp, -16
271 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
272 ; RV64I-NEXT: slli a0, a0, 24
273 ; RV64I-NEXT: sraiw a1, a0, 24
274 ; RV64I-NEXT: li a0, -10
275 ; RV64I-NEXT: call __moddi3
276 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
277 ; RV64I-NEXT: addi sp, sp, 16
280 ; RV64IM-LABEL: srem8_constant_lhs:
282 ; RV64IM-NEXT: slli a0, a0, 24
283 ; RV64IM-NEXT: sraiw a0, a0, 24
284 ; RV64IM-NEXT: li a1, -10
285 ; RV64IM-NEXT: remw a0, a1, a0
292 define i16 @urem16(i16 %a, i16 %b) nounwind {
293 ; RV64I-LABEL: urem16:
295 ; RV64I-NEXT: addi sp, sp, -16
296 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
297 ; RV64I-NEXT: lui a2, 16
298 ; RV64I-NEXT: addiw a2, a2, -1
299 ; RV64I-NEXT: and a0, a0, a2
300 ; RV64I-NEXT: and a1, a1, a2
301 ; RV64I-NEXT: call __umoddi3
302 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
303 ; RV64I-NEXT: addi sp, sp, 16
306 ; RV64IM-LABEL: urem16:
308 ; RV64IM-NEXT: lui a2, 16
309 ; RV64IM-NEXT: addi a2, a2, -1
310 ; RV64IM-NEXT: and a1, a1, a2
311 ; RV64IM-NEXT: and a0, a0, a2
312 ; RV64IM-NEXT: remuw a0, a0, a1
318 define i16 @urem16_constant_lhs(i16 %a) nounwind {
319 ; RV64I-LABEL: urem16_constant_lhs:
321 ; RV64I-NEXT: addi sp, sp, -16
322 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
323 ; RV64I-NEXT: slli a0, a0, 48
324 ; RV64I-NEXT: srli a1, a0, 48
325 ; RV64I-NEXT: li a0, 10
326 ; RV64I-NEXT: call __umoddi3
327 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
328 ; RV64I-NEXT: addi sp, sp, 16
331 ; RV64IM-LABEL: urem16_constant_lhs:
333 ; RV64IM-NEXT: slli a0, a0, 48
334 ; RV64IM-NEXT: srli a0, a0, 48
335 ; RV64IM-NEXT: li a1, 10
336 ; RV64IM-NEXT: remuw a0, a1, a0
342 define i16 @srem16(i16 %a, i16 %b) nounwind {
343 ; RV64I-LABEL: srem16:
345 ; RV64I-NEXT: addi sp, sp, -16
346 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
347 ; RV64I-NEXT: slli a1, a1, 16
348 ; RV64I-NEXT: sraiw a1, a1, 16
349 ; RV64I-NEXT: slli a0, a0, 16
350 ; RV64I-NEXT: sraiw a0, a0, 16
351 ; RV64I-NEXT: call __moddi3
352 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
353 ; RV64I-NEXT: addi sp, sp, 16
356 ; RV64IM-LABEL: srem16:
358 ; RV64IM-NEXT: slli a1, a1, 16
359 ; RV64IM-NEXT: sraiw a1, a1, 16
360 ; RV64IM-NEXT: slli a0, a0, 16
361 ; RV64IM-NEXT: sraiw a0, a0, 16
362 ; RV64IM-NEXT: remw a0, a0, a1
368 define i16 @srem16_constant_lhs(i16 %a) nounwind {
369 ; RV64I-LABEL: srem16_constant_lhs:
371 ; RV64I-NEXT: addi sp, sp, -16
372 ; RV64I-NEXT: sd ra, 8(sp) # 8-byte Folded Spill
373 ; RV64I-NEXT: slli a0, a0, 16
374 ; RV64I-NEXT: sraiw a1, a0, 16
375 ; RV64I-NEXT: li a0, -10
376 ; RV64I-NEXT: call __moddi3
377 ; RV64I-NEXT: ld ra, 8(sp) # 8-byte Folded Reload
378 ; RV64I-NEXT: addi sp, sp, 16
381 ; RV64IM-LABEL: srem16_constant_lhs:
383 ; RV64IM-NEXT: slli a0, a0, 16
384 ; RV64IM-NEXT: sraiw a0, a0, 16
385 ; RV64IM-NEXT: li a1, -10
386 ; RV64IM-NEXT: remw a0, a1, a0
388 %1 = srem i16 -10, %a