1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=aarch64-unknown-linux-gnu < %s | FileCheck %s
4 ;------------------------------------------------------------------------------;
6 ;------------------------------------------------------------------------------;
8 define i32 @test_srem_odd(i32 %X) nounwind {
9 ; CHECK-LABEL: test_srem_odd:
11 ; CHECK-NEXT: mov w8, #52429
12 ; CHECK-NEXT: mov w9, #39321
13 ; CHECK-NEXT: movk w8, #52428, lsl #16
14 ; CHECK-NEXT: movk w9, #6553, lsl #16
15 ; CHECK-NEXT: madd w8, w0, w8, w9
16 ; CHECK-NEXT: mov w9, #858993459
17 ; CHECK-NEXT: cmp w8, w9
18 ; CHECK-NEXT: cset w0, lo
20 %srem = srem i32 %X, 5
21 %cmp = icmp eq i32 %srem, 0
22 %ret = zext i1 %cmp to i32
26 define i32 @test_srem_odd_25(i32 %X) nounwind {
27 ; CHECK-LABEL: test_srem_odd_25:
29 ; CHECK-NEXT: mov w8, #23593
30 ; CHECK-NEXT: mov w9, #47185
31 ; CHECK-NEXT: movk w8, #49807, lsl #16
32 ; CHECK-NEXT: movk w9, #1310, lsl #16
33 ; CHECK-NEXT: madd w8, w0, w8, w9
34 ; CHECK-NEXT: mov w9, #28835
35 ; CHECK-NEXT: movk w9, #2621, lsl #16
36 ; CHECK-NEXT: cmp w8, w9
37 ; CHECK-NEXT: cset w0, lo
39 %srem = srem i32 %X, 25
40 %cmp = icmp eq i32 %srem, 0
41 %ret = zext i1 %cmp to i32
45 ; This is like test_srem_odd, except the divisor has bit 30 set.
46 define i32 @test_srem_odd_bit30(i32 %X) nounwind {
47 ; CHECK-LABEL: test_srem_odd_bit30:
49 ; CHECK-NEXT: mov w8, #43691
50 ; CHECK-NEXT: movk w8, #27306, lsl #16
51 ; CHECK-NEXT: orr w9, wzr, #0x1
52 ; CHECK-NEXT: madd w8, w0, w8, w9
53 ; CHECK-NEXT: cmp w8, #3
54 ; CHECK-NEXT: cset w0, lo
56 %srem = srem i32 %X, 1073741827
57 %cmp = icmp eq i32 %srem, 0
58 %ret = zext i1 %cmp to i32
62 ; This is like test_srem_odd, except the divisor has bit 31 set.
63 define i32 @test_srem_odd_bit31(i32 %X) nounwind {
64 ; CHECK-LABEL: test_srem_odd_bit31:
66 ; CHECK-NEXT: mov w8, #21845
67 ; CHECK-NEXT: movk w8, #54613, lsl #16
68 ; CHECK-NEXT: orr w9, wzr, #0x1
69 ; CHECK-NEXT: madd w8, w0, w8, w9
70 ; CHECK-NEXT: cmp w8, #3
71 ; CHECK-NEXT: cset w0, lo
73 %srem = srem i32 %X, 2147483651
74 %cmp = icmp eq i32 %srem, 0
75 %ret = zext i1 %cmp to i32
79 ;------------------------------------------------------------------------------;
81 ;------------------------------------------------------------------------------;
83 define i16 @test_srem_even(i16 %X) nounwind {
84 ; CHECK-LABEL: test_srem_even:
86 ; CHECK-NEXT: mov w8, #28087
87 ; CHECK-NEXT: mov w9, #4680
88 ; CHECK-NEXT: madd w8, w0, w8, w9
89 ; CHECK-NEXT: lsl w10, w8, #15
90 ; CHECK-NEXT: bfxil w10, w8, #1, #15
91 ; CHECK-NEXT: cmp w9, w10, uxth
92 ; CHECK-NEXT: cset w0, lo
94 %srem = srem i16 %X, 14
95 %cmp = icmp ne i16 %srem, 0
96 %ret = zext i1 %cmp to i16
100 define i32 @test_srem_even_100(i32 %X) nounwind {
101 ; CHECK-LABEL: test_srem_even_100:
103 ; CHECK-NEXT: mov w8, #23593
104 ; CHECK-NEXT: mov w9, #47184
105 ; CHECK-NEXT: movk w8, #49807, lsl #16
106 ; CHECK-NEXT: movk w9, #1310, lsl #16
107 ; CHECK-NEXT: madd w8, w0, w8, w9
108 ; CHECK-NEXT: mov w9, #23593
109 ; CHECK-NEXT: ror w8, w8, #2
110 ; CHECK-NEXT: movk w9, #655, lsl #16
111 ; CHECK-NEXT: cmp w8, w9
112 ; CHECK-NEXT: cset w0, lo
114 %srem = srem i32 %X, 100
115 %cmp = icmp eq i32 %srem, 0
116 %ret = zext i1 %cmp to i32
120 ; This is like test_srem_even, except the divisor has bit 30 set.
121 define i32 @test_srem_even_bit30(i32 %X) nounwind {
122 ; CHECK-LABEL: test_srem_even_bit30:
124 ; CHECK-NEXT: mov w8, #20165
125 ; CHECK-NEXT: movk w8, #64748, lsl #16
126 ; CHECK-NEXT: orr w9, wzr, #0x8
127 ; CHECK-NEXT: madd w8, w0, w8, w9
128 ; CHECK-NEXT: ror w8, w8, #3
129 ; CHECK-NEXT: cmp w8, #3
130 ; CHECK-NEXT: cset w0, lo
132 %srem = srem i32 %X, 1073741928
133 %cmp = icmp eq i32 %srem, 0
134 %ret = zext i1 %cmp to i32
138 ; This is like test_srem_odd, except the divisor has bit 31 set.
139 define i32 @test_srem_even_bit31(i32 %X) nounwind {
140 ; CHECK-LABEL: test_srem_even_bit31:
142 ; CHECK-NEXT: mov w8, #1285
143 ; CHECK-NEXT: movk w8, #50437, lsl #16
144 ; CHECK-NEXT: orr w9, wzr, #0x2
145 ; CHECK-NEXT: madd w8, w0, w8, w9
146 ; CHECK-NEXT: ror w8, w8, #1
147 ; CHECK-NEXT: cmp w8, #3
148 ; CHECK-NEXT: cset w0, lo
150 %srem = srem i32 %X, 2147483750
151 %cmp = icmp eq i32 %srem, 0
152 %ret = zext i1 %cmp to i32
156 ;------------------------------------------------------------------------------;
158 ;------------------------------------------------------------------------------;
160 ; 'NE' predicate is fine too.
161 define i32 @test_srem_odd_setne(i32 %X) nounwind {
162 ; CHECK-LABEL: test_srem_odd_setne:
164 ; CHECK-NEXT: mov w8, #52429
165 ; CHECK-NEXT: mov w9, #39321
166 ; CHECK-NEXT: movk w8, #52428, lsl #16
167 ; CHECK-NEXT: movk w9, #6553, lsl #16
168 ; CHECK-NEXT: madd w8, w0, w8, w9
169 ; CHECK-NEXT: mov w9, #13106
170 ; CHECK-NEXT: movk w9, #13107, lsl #16
171 ; CHECK-NEXT: cmp w8, w9
172 ; CHECK-NEXT: cset w0, hi
174 %srem = srem i32 %X, 5
175 %cmp = icmp ne i32 %srem, 0
176 %ret = zext i1 %cmp to i32
180 ; The fold is only valid for positive divisors, negative-ones should be negated.
181 define i32 @test_srem_negative_odd(i32 %X) nounwind {
182 ; CHECK-LABEL: test_srem_negative_odd:
184 ; CHECK-NEXT: mov w8, #52429
185 ; CHECK-NEXT: mov w9, #39321
186 ; CHECK-NEXT: movk w8, #52428, lsl #16
187 ; CHECK-NEXT: movk w9, #6553, lsl #16
188 ; CHECK-NEXT: madd w8, w0, w8, w9
189 ; CHECK-NEXT: mov w9, #13106
190 ; CHECK-NEXT: movk w9, #13107, lsl #16
191 ; CHECK-NEXT: cmp w8, w9
192 ; CHECK-NEXT: cset w0, hi
194 %srem = srem i32 %X, -5
195 %cmp = icmp ne i32 %srem, 0
196 %ret = zext i1 %cmp to i32
199 define i32 @test_srem_negative_even(i32 %X) nounwind {
200 ; CHECK-LABEL: test_srem_negative_even:
202 ; CHECK-NEXT: mov w8, #28087
203 ; CHECK-NEXT: mov w9, #9362
204 ; CHECK-NEXT: movk w8, #46811, lsl #16
205 ; CHECK-NEXT: movk w9, #4681, lsl #16
206 ; CHECK-NEXT: madd w8, w0, w8, w9
207 ; CHECK-NEXT: ror w8, w8, #1
208 ; CHECK-NEXT: cmp w8, w9
209 ; CHECK-NEXT: cset w0, hi
211 %srem = srem i32 %X, -14
212 %cmp = icmp ne i32 %srem, 0
213 %ret = zext i1 %cmp to i32
217 ;------------------------------------------------------------------------------;
219 ;------------------------------------------------------------------------------;
221 ; We can lower remainder of division by one much better elsewhere.
222 define i32 @test_srem_one(i32 %X) nounwind {
223 ; CHECK-LABEL: test_srem_one:
225 ; CHECK-NEXT: mov w0, #1
227 %srem = srem i32 %X, 1
228 %cmp = icmp eq i32 %srem, 0
229 %ret = zext i1 %cmp to i32
233 ; We can lower remainder of division by powers of two much better elsewhere.
234 define i32 @test_srem_pow2(i32 %X) nounwind {
235 ; CHECK-LABEL: test_srem_pow2:
237 ; CHECK-NEXT: add w8, w0, #15
238 ; CHECK-NEXT: cmp w0, #0
239 ; CHECK-NEXT: csel w8, w8, w0, lt
240 ; CHECK-NEXT: and w8, w8, #0xfffffff0
241 ; CHECK-NEXT: cmp w0, w8
242 ; CHECK-NEXT: cset w0, eq
244 %srem = srem i32 %X, 16
245 %cmp = icmp eq i32 %srem, 0
246 %ret = zext i1 %cmp to i32
250 ; The fold is only valid for positive divisors, and we can't negate INT_MIN.
251 define i32 @test_srem_int_min(i32 %X) nounwind {
252 ; CHECK-LABEL: test_srem_int_min:
254 ; CHECK-NEXT: mov w8, #2147483647
255 ; CHECK-NEXT: add w8, w0, w8
256 ; CHECK-NEXT: cmp w0, #0
257 ; CHECK-NEXT: csel w8, w8, w0, lt
258 ; CHECK-NEXT: and w8, w8, #0x80000000
259 ; CHECK-NEXT: cmn w0, w8
260 ; CHECK-NEXT: cset w0, eq
262 %srem = srem i32 %X, 2147483648
263 %cmp = icmp eq i32 %srem, 0
264 %ret = zext i1 %cmp to i32
268 ; We can lower remainder of division by all-ones much better elsewhere.
269 define i32 @test_srem_allones(i32 %X) nounwind {
270 ; CHECK-LABEL: test_srem_allones:
272 ; CHECK-NEXT: mov w0, #1
274 %srem = srem i32 %X, 4294967295
275 %cmp = icmp eq i32 %srem, 0
276 %ret = zext i1 %cmp to i32