1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv64 -mattr=+c,+m -verify-machineinstrs < %s \
3 ; RUN: | FileCheck -check-prefixes=CHECK,NOSFB %s
4 ; RUN: llc -mtriple=riscv64 -mcpu=sifive-u74 -verify-machineinstrs < %s \
5 ; RUN: | FileCheck -check-prefixes=CHECK,SFB %s
7 define signext i32 @sdiv2_32(i32 signext %0) {
8 ; NOSFB-LABEL: sdiv2_32:
10 ; NOSFB-NEXT: srliw a1, a0, 31
11 ; NOSFB-NEXT: add a0, a0, a1
12 ; NOSFB-NEXT: sraiw a0, a0, 1
15 ; SFB-LABEL: sdiv2_32:
17 ; SFB-NEXT: bgez a0, .LBB0_2
19 ; SFB-NEXT: addi a0, a0, 1
21 ; SFB-NEXT: sraiw a0, a0, 1
27 define signext i32 @sdivneg2_32(i32 signext %0) {
28 ; NOSFB-LABEL: sdivneg2_32:
30 ; NOSFB-NEXT: srliw a1, a0, 31
31 ; NOSFB-NEXT: add a0, a0, a1
32 ; NOSFB-NEXT: sraiw a0, a0, 1
33 ; NOSFB-NEXT: neg a0, a0
36 ; SFB-LABEL: sdivneg2_32:
38 ; SFB-NEXT: bgez a0, .LBB1_2
40 ; SFB-NEXT: addi a0, a0, 1
42 ; SFB-NEXT: sraiw a0, a0, 1
43 ; SFB-NEXT: neg a0, a0
45 %res = sdiv i32 %0, -2
49 define i64 @sdiv2_64(i64 %0) {
50 ; NOSFB-LABEL: sdiv2_64:
52 ; NOSFB-NEXT: srli a1, a0, 63
53 ; NOSFB-NEXT: add a0, a0, a1
54 ; NOSFB-NEXT: srai a0, a0, 1
57 ; SFB-LABEL: sdiv2_64:
59 ; SFB-NEXT: bgez a0, .LBB2_2
61 ; SFB-NEXT: addi a0, a0, 1
63 ; SFB-NEXT: srai a0, a0, 1
69 define i64 @sdivneg2_64(i64 %0) {
70 ; NOSFB-LABEL: sdivneg2_64:
72 ; NOSFB-NEXT: srli a1, a0, 63
73 ; NOSFB-NEXT: add a0, a0, a1
74 ; NOSFB-NEXT: srai a0, a0, 1
75 ; NOSFB-NEXT: neg a0, a0
78 ; SFB-LABEL: sdivneg2_64:
80 ; SFB-NEXT: bgez a0, .LBB3_2
82 ; SFB-NEXT: addi a0, a0, 1
84 ; SFB-NEXT: srai a0, a0, 1
85 ; SFB-NEXT: neg a0, a0
87 %res = sdiv i64 %0, -2
91 define signext i32 @srem2_32(i32 signext %0) {
92 ; NOSFB-LABEL: srem2_32:
94 ; NOSFB-NEXT: srliw a1, a0, 31
95 ; NOSFB-NEXT: add a1, a1, a0
96 ; NOSFB-NEXT: andi a1, a1, -2
97 ; NOSFB-NEXT: subw a0, a0, a1
100 ; SFB-LABEL: srem2_32:
102 ; SFB-NEXT: mv a1, a0
103 ; SFB-NEXT: bgez a0, .LBB4_2
105 ; SFB-NEXT: addi a1, a0, 1
107 ; SFB-NEXT: andi a1, a1, -2
108 ; SFB-NEXT: subw a0, a0, a1
110 %res = srem i32 %0, 2
114 define signext i32 @sremneg2_32(i32 signext %0) {
115 ; NOSFB-LABEL: sremneg2_32:
117 ; NOSFB-NEXT: srliw a1, a0, 31
118 ; NOSFB-NEXT: add a1, a1, a0
119 ; NOSFB-NEXT: andi a1, a1, -2
120 ; NOSFB-NEXT: subw a0, a0, a1
123 ; SFB-LABEL: sremneg2_32:
125 ; SFB-NEXT: mv a1, a0
126 ; SFB-NEXT: bgez a0, .LBB5_2
128 ; SFB-NEXT: addi a1, a0, 1
130 ; SFB-NEXT: andi a1, a1, -2
131 ; SFB-NEXT: subw a0, a0, a1
133 %res = srem i32 %0, -2
137 define i64 @srem2_64(i64 %0) {
138 ; NOSFB-LABEL: srem2_64:
140 ; NOSFB-NEXT: srli a1, a0, 63
141 ; NOSFB-NEXT: add a1, a1, a0
142 ; NOSFB-NEXT: andi a1, a1, -2
143 ; NOSFB-NEXT: sub a0, a0, a1
146 ; SFB-LABEL: srem2_64:
148 ; SFB-NEXT: mv a1, a0
149 ; SFB-NEXT: bgez a0, .LBB6_2
151 ; SFB-NEXT: addi a1, a0, 1
153 ; SFB-NEXT: andi a1, a1, -2
154 ; SFB-NEXT: sub a0, a0, a1
156 %res = srem i64 %0, 2
160 define i64 @sremneg2_64(i64 %0) {
161 ; NOSFB-LABEL: sremneg2_64:
163 ; NOSFB-NEXT: srli a1, a0, 63
164 ; NOSFB-NEXT: add a1, a1, a0
165 ; NOSFB-NEXT: andi a1, a1, -2
166 ; NOSFB-NEXT: sub a0, a0, a1
169 ; SFB-LABEL: sremneg2_64:
171 ; SFB-NEXT: mv a1, a0
172 ; SFB-NEXT: bgez a0, .LBB7_2
174 ; SFB-NEXT: addi a1, a0, 1
176 ; SFB-NEXT: andi a1, a1, -2
177 ; SFB-NEXT: sub a0, a0, a1
179 %res = srem i64 %0, -2
183 define signext i32 @sdiv8_32(i32 signext %0) {
184 ; NOSFB-LABEL: sdiv8_32:
186 ; NOSFB-NEXT: slli a1, a0, 1
187 ; NOSFB-NEXT: srli a1, a1, 61
188 ; NOSFB-NEXT: add a0, a0, a1
189 ; NOSFB-NEXT: sraiw a0, a0, 3
192 ; SFB-LABEL: sdiv8_32:
194 ; SFB-NEXT: bgez a0, .LBB8_2
196 ; SFB-NEXT: addi a0, a0, 7
198 ; SFB-NEXT: sraiw a0, a0, 3
200 %res = sdiv i32 %0, 8
204 define signext i32 @sdivneg8_32(i32 signext %0) {
205 ; NOSFB-LABEL: sdivneg8_32:
207 ; NOSFB-NEXT: slli a1, a0, 1
208 ; NOSFB-NEXT: srli a1, a1, 61
209 ; NOSFB-NEXT: add a0, a0, a1
210 ; NOSFB-NEXT: sraiw a0, a0, 3
211 ; NOSFB-NEXT: neg a0, a0
214 ; SFB-LABEL: sdivneg8_32:
216 ; SFB-NEXT: bgez a0, .LBB9_2
218 ; SFB-NEXT: addi a0, a0, 7
220 ; SFB-NEXT: sraiw a0, a0, 3
221 ; SFB-NEXT: neg a0, a0
223 %res = sdiv i32 %0, -8
227 define i64 @sdiv8_64(i64 %0) {
228 ; NOSFB-LABEL: sdiv8_64:
230 ; NOSFB-NEXT: srai a1, a0, 63
231 ; NOSFB-NEXT: srli a1, a1, 61
232 ; NOSFB-NEXT: add a0, a0, a1
233 ; NOSFB-NEXT: srai a0, a0, 3
236 ; SFB-LABEL: sdiv8_64:
238 ; SFB-NEXT: bgez a0, .LBB10_2
240 ; SFB-NEXT: addi a0, a0, 7
241 ; SFB-NEXT: .LBB10_2:
242 ; SFB-NEXT: srai a0, a0, 3
244 %res = sdiv i64 %0, 8
248 define i64 @sdivneg8_64(i64 %0) {
249 ; NOSFB-LABEL: sdivneg8_64:
251 ; NOSFB-NEXT: srai a1, a0, 63
252 ; NOSFB-NEXT: srli a1, a1, 61
253 ; NOSFB-NEXT: add a0, a0, a1
254 ; NOSFB-NEXT: srai a0, a0, 3
255 ; NOSFB-NEXT: neg a0, a0
258 ; SFB-LABEL: sdivneg8_64:
260 ; SFB-NEXT: bgez a0, .LBB11_2
262 ; SFB-NEXT: addi a0, a0, 7
263 ; SFB-NEXT: .LBB11_2:
264 ; SFB-NEXT: srai a0, a0, 3
265 ; SFB-NEXT: neg a0, a0
267 %res = sdiv i64 %0, -8
271 define signext i32 @srem8_32(i32 signext %0) {
272 ; NOSFB-LABEL: srem8_32:
274 ; NOSFB-NEXT: slli a1, a0, 1
275 ; NOSFB-NEXT: srli a1, a1, 61
276 ; NOSFB-NEXT: add a1, a1, a0
277 ; NOSFB-NEXT: andi a1, a1, -8
278 ; NOSFB-NEXT: subw a0, a0, a1
281 ; SFB-LABEL: srem8_32:
283 ; SFB-NEXT: mv a1, a0
284 ; SFB-NEXT: bgez a0, .LBB12_2
286 ; SFB-NEXT: addi a1, a0, 7
287 ; SFB-NEXT: .LBB12_2:
288 ; SFB-NEXT: andi a1, a1, -8
289 ; SFB-NEXT: subw a0, a0, a1
291 %res = srem i32 %0, 8
295 define signext i32 @sremneg8_32(i32 signext %0) {
296 ; NOSFB-LABEL: sremneg8_32:
298 ; NOSFB-NEXT: slli a1, a0, 1
299 ; NOSFB-NEXT: srli a1, a1, 61
300 ; NOSFB-NEXT: add a1, a1, a0
301 ; NOSFB-NEXT: andi a1, a1, -8
302 ; NOSFB-NEXT: subw a0, a0, a1
305 ; SFB-LABEL: sremneg8_32:
307 ; SFB-NEXT: mv a1, a0
308 ; SFB-NEXT: bgez a0, .LBB13_2
310 ; SFB-NEXT: addi a1, a0, 7
311 ; SFB-NEXT: .LBB13_2:
312 ; SFB-NEXT: andi a1, a1, -8
313 ; SFB-NEXT: subw a0, a0, a1
315 %res = srem i32 %0, -8
319 define i64 @srem8_64(i64 %0) {
320 ; NOSFB-LABEL: srem8_64:
322 ; NOSFB-NEXT: srai a1, a0, 63
323 ; NOSFB-NEXT: srli a1, a1, 61
324 ; NOSFB-NEXT: add a1, a1, a0
325 ; NOSFB-NEXT: andi a1, a1, -8
326 ; NOSFB-NEXT: sub a0, a0, a1
329 ; SFB-LABEL: srem8_64:
331 ; SFB-NEXT: mv a1, a0
332 ; SFB-NEXT: bgez a0, .LBB14_2
334 ; SFB-NEXT: addi a1, a0, 7
335 ; SFB-NEXT: .LBB14_2:
336 ; SFB-NEXT: andi a1, a1, -8
337 ; SFB-NEXT: sub a0, a0, a1
339 %res = srem i64 %0, 8
343 define i64 @sremneg8_64(i64 %0) {
344 ; NOSFB-LABEL: sremneg8_64:
346 ; NOSFB-NEXT: srai a1, a0, 63
347 ; NOSFB-NEXT: srli a1, a1, 61
348 ; NOSFB-NEXT: add a1, a1, a0
349 ; NOSFB-NEXT: andi a1, a1, -8
350 ; NOSFB-NEXT: sub a0, a0, a1
353 ; SFB-LABEL: sremneg8_64:
355 ; SFB-NEXT: mv a1, a0
356 ; SFB-NEXT: bgez a0, .LBB15_2
358 ; SFB-NEXT: addi a1, a0, 7
359 ; SFB-NEXT: .LBB15_2:
360 ; SFB-NEXT: andi a1, a1, -8
361 ; SFB-NEXT: sub a0, a0, a1
363 %res = srem i64 %0, -8
368 define i64 @sdiv4096(i64 %0) {
369 ; CHECK-LABEL: sdiv4096:
371 ; CHECK-NEXT: srai a1, a0, 63
372 ; CHECK-NEXT: srli a1, a1, 52
373 ; CHECK-NEXT: add a0, a0, a1
374 ; CHECK-NEXT: srai a0, a0, 12
376 %res = sdiv i64 %0, 4096