1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=i686-unknown-linux-gnu < %s | FileCheck %s --check-prefixes=CHECK,X86
3 ; RUN: llc -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s --check-prefixes=CHECK,X64
5 ;------------------------------------------------------------------------------;
7 ;------------------------------------------------------------------------------;
9 define i32 @test_urem_odd(i32 %X) nounwind {
10 ; X86-LABEL: test_urem_odd:
12 ; X86-NEXT: imull $-858993459, {{[0-9]+}}(%esp), %ecx # imm = 0xCCCCCCCD
13 ; X86-NEXT: xorl %eax, %eax
14 ; X86-NEXT: cmpl $858993460, %ecx # imm = 0x33333334
18 ; X64-LABEL: test_urem_odd:
20 ; X64-NEXT: imull $-858993459, %edi, %ecx # imm = 0xCCCCCCCD
21 ; X64-NEXT: xorl %eax, %eax
22 ; X64-NEXT: cmpl $858993460, %ecx # imm = 0x33333334
25 %urem = urem i32 %X, 5
26 %cmp = icmp eq i32 %urem, 0
27 %ret = zext i1 %cmp to i32
31 define i32 @test_urem_odd_25(i32 %X) nounwind {
32 ; X86-LABEL: test_urem_odd_25:
34 ; X86-NEXT: imull $-1030792151, {{[0-9]+}}(%esp), %ecx # imm = 0xC28F5C29
35 ; X86-NEXT: xorl %eax, %eax
36 ; X86-NEXT: cmpl $171798692, %ecx # imm = 0xA3D70A4
40 ; X64-LABEL: test_urem_odd_25:
42 ; X64-NEXT: imull $-1030792151, %edi, %ecx # imm = 0xC28F5C29
43 ; X64-NEXT: xorl %eax, %eax
44 ; X64-NEXT: cmpl $171798692, %ecx # imm = 0xA3D70A4
47 %urem = urem i32 %X, 25
48 %cmp = icmp eq i32 %urem, 0
49 %ret = zext i1 %cmp to i32
53 ; This is like test_urem_odd, except the divisor has bit 30 set.
54 define i32 @test_urem_odd_bit30(i32 %X) nounwind {
55 ; X86-LABEL: test_urem_odd_bit30:
57 ; X86-NEXT: imull $1789569707, {{[0-9]+}}(%esp), %ecx # imm = 0x6AAAAAAB
58 ; X86-NEXT: xorl %eax, %eax
59 ; X86-NEXT: cmpl $4, %ecx
63 ; X64-LABEL: test_urem_odd_bit30:
65 ; X64-NEXT: imull $1789569707, %edi, %ecx # imm = 0x6AAAAAAB
66 ; X64-NEXT: xorl %eax, %eax
67 ; X64-NEXT: cmpl $4, %ecx
70 %urem = urem i32 %X, 1073741827
71 %cmp = icmp eq i32 %urem, 0
72 %ret = zext i1 %cmp to i32
76 ; This is like test_urem_odd, except the divisor has bit 31 set.
77 define i32 @test_urem_odd_bit31(i32 %X) nounwind {
78 ; X86-LABEL: test_urem_odd_bit31:
80 ; X86-NEXT: imull $715827883, {{[0-9]+}}(%esp), %ecx # imm = 0x2AAAAAAB
81 ; X86-NEXT: xorl %eax, %eax
82 ; X86-NEXT: cmpl $2, %ecx
86 ; X64-LABEL: test_urem_odd_bit31:
88 ; X64-NEXT: imull $715827883, %edi, %ecx # imm = 0x2AAAAAAB
89 ; X64-NEXT: xorl %eax, %eax
90 ; X64-NEXT: cmpl $2, %ecx
93 %urem = urem i32 %X, 2147483651
94 %cmp = icmp eq i32 %urem, 0
95 %ret = zext i1 %cmp to i32
99 ;------------------------------------------------------------------------------;
101 ;------------------------------------------------------------------------------;
103 define i16 @test_urem_even(i16 %X) nounwind {
104 ; X86-LABEL: test_urem_even:
106 ; X86-NEXT: imull $28087, {{[0-9]+}}(%esp), %eax # imm = 0x6DB7
108 ; X86-NEXT: movzwl %ax, %ecx
109 ; X86-NEXT: xorl %eax, %eax
110 ; X86-NEXT: cmpl $4681, %ecx # imm = 0x1249
112 ; X86-NEXT: # kill: def $ax killed $ax killed $eax
115 ; X64-LABEL: test_urem_even:
117 ; X64-NEXT: imull $28087, %edi, %eax # imm = 0x6DB7
119 ; X64-NEXT: movzwl %ax, %ecx
120 ; X64-NEXT: xorl %eax, %eax
121 ; X64-NEXT: cmpl $4681, %ecx # imm = 0x1249
123 ; X64-NEXT: # kill: def $ax killed $ax killed $eax
125 %urem = urem i16 %X, 14
126 %cmp = icmp ne i16 %urem, 0
127 %ret = zext i1 %cmp to i16
131 define i32 @test_urem_even_100(i32 %X) nounwind {
132 ; X86-LABEL: test_urem_even_100:
134 ; X86-NEXT: imull $-1030792151, {{[0-9]+}}(%esp), %ecx # imm = 0xC28F5C29
135 ; X86-NEXT: rorl $2, %ecx
136 ; X86-NEXT: xorl %eax, %eax
137 ; X86-NEXT: cmpl $42949673, %ecx # imm = 0x28F5C29
141 ; X64-LABEL: test_urem_even_100:
143 ; X64-NEXT: imull $-1030792151, %edi, %ecx # imm = 0xC28F5C29
144 ; X64-NEXT: rorl $2, %ecx
145 ; X64-NEXT: xorl %eax, %eax
146 ; X64-NEXT: cmpl $42949673, %ecx # imm = 0x28F5C29
149 %urem = urem i32 %X, 100
150 %cmp = icmp eq i32 %urem, 0
151 %ret = zext i1 %cmp to i32
155 ; This is like test_urem_even, except the divisor has bit 30 set.
156 define i32 @test_urem_even_bit30(i32 %X) nounwind {
157 ; X86-LABEL: test_urem_even_bit30:
159 ; X86-NEXT: imull $-51622203, {{[0-9]+}}(%esp), %ecx # imm = 0xFCEC4EC5
160 ; X86-NEXT: rorl $3, %ecx
161 ; X86-NEXT: xorl %eax, %eax
162 ; X86-NEXT: cmpl $4, %ecx
166 ; X64-LABEL: test_urem_even_bit30:
168 ; X64-NEXT: imull $-51622203, %edi, %ecx # imm = 0xFCEC4EC5
169 ; X64-NEXT: rorl $3, %ecx
170 ; X64-NEXT: xorl %eax, %eax
171 ; X64-NEXT: cmpl $4, %ecx
174 %urem = urem i32 %X, 1073741928
175 %cmp = icmp eq i32 %urem, 0
176 %ret = zext i1 %cmp to i32
180 ; This is like test_urem_odd, except the divisor has bit 31 set.
181 define i32 @test_urem_even_bit31(i32 %X) nounwind {
182 ; X86-LABEL: test_urem_even_bit31:
184 ; X86-NEXT: imull $-1157956869, {{[0-9]+}}(%esp), %ecx # imm = 0xBAFAFAFB
185 ; X86-NEXT: rorl %ecx
186 ; X86-NEXT: xorl %eax, %eax
187 ; X86-NEXT: cmpl $2, %ecx
191 ; X64-LABEL: test_urem_even_bit31:
193 ; X64-NEXT: imull $-1157956869, %edi, %ecx # imm = 0xBAFAFAFB
194 ; X64-NEXT: rorl %ecx
195 ; X64-NEXT: xorl %eax, %eax
196 ; X64-NEXT: cmpl $2, %ecx
199 %urem = urem i32 %X, 2147483750
200 %cmp = icmp eq i32 %urem, 0
201 %ret = zext i1 %cmp to i32
205 ;------------------------------------------------------------------------------;
207 ;------------------------------------------------------------------------------;
209 ; 'NE' predicate is fine too.
210 define i32 @test_urem_odd_setne(i32 %X) nounwind {
211 ; X86-LABEL: test_urem_odd_setne:
213 ; X86-NEXT: imull $-858993459, {{[0-9]+}}(%esp), %ecx # imm = 0xCCCCCCCD
214 ; X86-NEXT: xorl %eax, %eax
215 ; X86-NEXT: cmpl $858993459, %ecx # imm = 0x33333333
219 ; X64-LABEL: test_urem_odd_setne:
221 ; X64-NEXT: imull $-858993459, %edi, %ecx # imm = 0xCCCCCCCD
222 ; X64-NEXT: xorl %eax, %eax
223 ; X64-NEXT: cmpl $858993459, %ecx # imm = 0x33333333
226 %urem = urem i32 %X, 5
227 %cmp = icmp ne i32 %urem, 0
228 %ret = zext i1 %cmp to i32
232 ; The fold is only valid for positive divisors, negative-ones should be negated.
233 define i32 @test_urem_negative_odd(i32 %X) nounwind {
234 ; X86-LABEL: test_urem_negative_odd:
236 ; X86-NEXT: imull $858993459, {{[0-9]+}}(%esp), %ecx # imm = 0x33333333
237 ; X86-NEXT: xorl %eax, %eax
238 ; X86-NEXT: cmpl $1, %ecx
242 ; X64-LABEL: test_urem_negative_odd:
244 ; X64-NEXT: imull $858993459, %edi, %ecx # imm = 0x33333333
245 ; X64-NEXT: xorl %eax, %eax
246 ; X64-NEXT: cmpl $1, %ecx
249 %urem = urem i32 %X, -5
250 %cmp = icmp ne i32 %urem, 0
251 %ret = zext i1 %cmp to i32
254 define i32 @test_urem_negative_even(i32 %X) nounwind {
255 ; X86-LABEL: test_urem_negative_even:
257 ; X86-NEXT: imull $-920350135, {{[0-9]+}}(%esp), %ecx # imm = 0xC9249249
258 ; X86-NEXT: rorl %ecx
259 ; X86-NEXT: xorl %eax, %eax
260 ; X86-NEXT: cmpl $1, %ecx
264 ; X64-LABEL: test_urem_negative_even:
266 ; X64-NEXT: imull $-920350135, %edi, %ecx # imm = 0xC9249249
267 ; X64-NEXT: rorl %ecx
268 ; X64-NEXT: xorl %eax, %eax
269 ; X64-NEXT: cmpl $1, %ecx
272 %urem = urem i32 %X, -14
273 %cmp = icmp ne i32 %urem, 0
274 %ret = zext i1 %cmp to i32
278 ;------------------------------------------------------------------------------;
280 ;------------------------------------------------------------------------------;
282 ; We can lower remainder of division by one much better elsewhere.
283 define i32 @test_urem_one(i32 %X) nounwind {
284 ; CHECK-LABEL: test_urem_one:
286 ; CHECK-NEXT: movl $1, %eax
287 ; CHECK-NEXT: ret{{[l|q]}}
288 %urem = urem i32 %X, 1
289 %cmp = icmp eq i32 %urem, 0
290 %ret = zext i1 %cmp to i32
294 ; We can lower remainder of division by powers of two much better elsewhere.
295 define i32 @test_urem_pow2(i32 %X) nounwind {
296 ; X86-LABEL: test_urem_pow2:
298 ; X86-NEXT: xorl %eax, %eax
299 ; X86-NEXT: testb $15, {{[0-9]+}}(%esp)
303 ; X64-LABEL: test_urem_pow2:
305 ; X64-NEXT: xorl %eax, %eax
306 ; X64-NEXT: testb $15, %dil
309 %urem = urem i32 %X, 16
310 %cmp = icmp eq i32 %urem, 0
311 %ret = zext i1 %cmp to i32
315 ; The fold is only valid for positive divisors, and we can't negate INT_MIN.
316 define i32 @test_urem_int_min(i32 %X) nounwind {
317 ; X86-LABEL: test_urem_int_min:
319 ; X86-NEXT: xorl %eax, %eax
320 ; X86-NEXT: testl $2147483647, {{[0-9]+}}(%esp) # imm = 0x7FFFFFFF
324 ; X64-LABEL: test_urem_int_min:
326 ; X64-NEXT: xorl %eax, %eax
327 ; X64-NEXT: testl $2147483647, %edi # imm = 0x7FFFFFFF
330 %urem = urem i32 %X, 2147483648
331 %cmp = icmp eq i32 %urem, 0
332 %ret = zext i1 %cmp to i32
336 ; We can lower remainder of division by all-ones much better elsewhere.
337 define i32 @test_urem_allones(i32 %X) nounwind {
338 ; X86-LABEL: test_urem_allones:
340 ; X86-NEXT: xorl %ecx, %ecx
341 ; X86-NEXT: subl {{[0-9]+}}(%esp), %ecx
342 ; X86-NEXT: xorl %eax, %eax
343 ; X86-NEXT: cmpl $2, %ecx
347 ; X64-LABEL: test_urem_allones:
349 ; X64-NEXT: negl %edi
350 ; X64-NEXT: xorl %eax, %eax
351 ; X64-NEXT: cmpl $2, %edi
354 %urem = urem i32 %X, 4294967295
355 %cmp = icmp eq i32 %urem, 0
356 %ret = zext i1 %cmp to i32