1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse2 | FileCheck %s --check-prefixes=CHECK,SSE2
3 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+sse4.2 | FileCheck %s --check-prefixes=CHECK,SSE4
4 ; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+avx2 | FileCheck %s --check-prefixes=CHECK,AVX2
7 ; icmp eq/ne (urem %x, C), 0
8 ; Iff C is not a power of two (those should not get to here though),
9 ; and %x may have at most one bit set, omit the 'urem':
12 ;------------------------------------------------------------------------------;
14 ;------------------------------------------------------------------------------;
16 define i1 @p0_scalar_urem_by_const(i32 %x, i32 %y) {
17 ; CHECK-LABEL: p0_scalar_urem_by_const:
19 ; CHECK-NEXT: testb %dil, %dil
20 ; CHECK-NEXT: setns %al
22 %t0 = and i32 %x, 128 ; clearly a power-of-two or zero
23 %t1 = urem i32 %t0, 6 ; '6' is clearly not a power of two
24 %t2 = icmp eq i32 %t1, 0
28 define i1 @p1_scalar_urem_by_nonconst(i32 %x, i32 %y) {
29 ; CHECK-LABEL: p1_scalar_urem_by_nonconst:
31 ; CHECK-NEXT: testb %dil, %dil
32 ; CHECK-NEXT: setns %al
34 %t0 = and i32 %x, 128 ; clearly a power-of-two or zero
35 %t1 = or i32 %y, 6 ; two bits set, clearly not a power of two
36 %t2 = urem i32 %t0, %t1
37 %t3 = icmp eq i32 %t2, 0
41 define i1 @p2_scalar_shifted_urem_by_const(i32 %x, i32 %y) {
42 ; CHECK-LABEL: p2_scalar_shifted_urem_by_const:
44 ; CHECK-NEXT: movl %esi, %ecx
45 ; CHECK-NEXT: andl $1, %edi
46 ; CHECK-NEXT: # kill: def $cl killed $cl killed $ecx
47 ; CHECK-NEXT: shll %cl, %edi
48 ; CHECK-NEXT: imull $-1431655765, %edi, %eax # imm = 0xAAAAAAAB
49 ; CHECK-NEXT: cmpl $1431655766, %eax # imm = 0x55555556
50 ; CHECK-NEXT: setb %al
52 %t0 = and i32 %x, 1 ; clearly a power-of-two or zero
53 %t1 = shl i32 %t0, %y ; will still be a power-of-two or zero with any %y
54 %t2 = urem i32 %t1, 3 ; '3' is clearly not a power of two
55 %t3 = icmp eq i32 %t2, 0
59 define i1 @p3_scalar_shifted2_urem_by_const(i32 %x, i32 %y) {
60 ; CHECK-LABEL: p3_scalar_shifted2_urem_by_const:
62 ; CHECK-NEXT: movl %esi, %ecx
63 ; CHECK-NEXT: andl $2, %edi
64 ; CHECK-NEXT: # kill: def $cl killed $cl killed $ecx
65 ; CHECK-NEXT: shll %cl, %edi
66 ; CHECK-NEXT: imull $-1431655765, %edi, %eax # imm = 0xAAAAAAAB
67 ; CHECK-NEXT: cmpl $1431655766, %eax # imm = 0x55555556
68 ; CHECK-NEXT: setb %al
70 %t0 = and i32 %x, 2 ; clearly a power-of-two or zero
71 %t1 = shl i32 %t0, %y ; will still be a power-of-two or zero with any %y
72 %t2 = urem i32 %t1, 3 ; '3' is clearly not a power of two
73 %t3 = icmp eq i32 %t2, 0
77 ;------------------------------------------------------------------------------;
79 ;------------------------------------------------------------------------------;
81 define <4 x i1> @p4_vector_urem_by_const__splat(<4 x i32> %x, <4 x i32> %y) {
82 ; SSE2-LABEL: p4_vector_urem_by_const__splat:
84 ; SSE2-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
85 ; SSE2-NEXT: movdqa {{.*#+}} xmm1 = [2863311531,2863311531,2863311531,2863311531]
86 ; SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm0[1,1,3,3]
87 ; SSE2-NEXT: pmuludq %xmm1, %xmm0
88 ; SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm0[0,2,2,3]
89 ; SSE2-NEXT: pmuludq %xmm1, %xmm2
90 ; SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm2[0,2,2,3]
91 ; SSE2-NEXT: punpckldq {{.*#+}} xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
92 ; SSE2-NEXT: movdqa %xmm3, %xmm0
93 ; SSE2-NEXT: psrld $1, %xmm0
94 ; SSE2-NEXT: pslld $31, %xmm3
95 ; SSE2-NEXT: por %xmm0, %xmm3
96 ; SSE2-NEXT: pxor {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm3
97 ; SSE2-NEXT: pcmpgtd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm3
98 ; SSE2-NEXT: pcmpeqd %xmm0, %xmm0
99 ; SSE2-NEXT: pxor %xmm3, %xmm0
102 ; SSE4-LABEL: p4_vector_urem_by_const__splat:
104 ; SSE4-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
105 ; SSE4-NEXT: pmulld {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
106 ; SSE4-NEXT: psrld $1, %xmm0
107 ; SSE4-NEXT: movdqa {{.*#+}} xmm1 = [715827882,715827882,715827882,715827882]
108 ; SSE4-NEXT: pminud %xmm0, %xmm1
109 ; SSE4-NEXT: pcmpeqd %xmm1, %xmm0
112 ; AVX2-LABEL: p4_vector_urem_by_const__splat:
114 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm1 = [128,128,128,128]
115 ; AVX2-NEXT: vpand %xmm1, %xmm0, %xmm0
116 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm1 = [2863311531,2863311531,2863311531,2863311531]
117 ; AVX2-NEXT: vpmulld %xmm1, %xmm0, %xmm0
118 ; AVX2-NEXT: vpsrld $1, %xmm0, %xmm0
119 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm1 = [715827882,715827882,715827882,715827882]
120 ; AVX2-NEXT: vpminud %xmm1, %xmm0, %xmm1
121 ; AVX2-NEXT: vpcmpeqd %xmm1, %xmm0, %xmm0
123 %t0 = and <4 x i32> %x, <i32 128, i32 128, i32 128, i32 128> ; clearly a power-of-two or zero
124 %t1 = urem <4 x i32> %t0, <i32 6, i32 6, i32 6, i32 6> ; '6' is clearly not a power of two
125 %t2 = icmp eq <4 x i32> %t1, <i32 0, i32 0, i32 0, i32 0>
129 define <4 x i1> @p5_vector_urem_by_const__nonsplat(<4 x i32> %x, <4 x i32> %y) {
130 ; SSE2-LABEL: p5_vector_urem_by_const__nonsplat:
132 ; SSE2-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
133 ; SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,1,3,3]
134 ; SSE2-NEXT: pmuludq {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1
135 ; SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm1[0,2,2,3]
136 ; SSE2-NEXT: pmuludq {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
137 ; SSE2-NEXT: pmuludq {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
138 ; SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm0[0,2,2,3]
139 ; SSE2-NEXT: punpckldq {{.*#+}} xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
140 ; SSE2-NEXT: psrlq $32, %xmm0
141 ; SSE2-NEXT: por %xmm2, %xmm0
142 ; SSE2-NEXT: pxor {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
143 ; SSE2-NEXT: pcmpgtd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
144 ; SSE2-NEXT: pcmpeqd %xmm1, %xmm1
145 ; SSE2-NEXT: pxor %xmm1, %xmm0
148 ; SSE4-LABEL: p5_vector_urem_by_const__nonsplat:
150 ; SSE4-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
151 ; SSE4-NEXT: pmulld {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
152 ; SSE4-NEXT: movdqa {{.*#+}} xmm1 = <1,u,2147483648,u>
153 ; SSE4-NEXT: pmuludq %xmm0, %xmm1
154 ; SSE4-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3],xmm1[4,5],xmm0[6,7]
155 ; SSE4-NEXT: psrlq $32, %xmm1
156 ; SSE4-NEXT: por %xmm1, %xmm0
157 ; SSE4-NEXT: movdqa {{.*#+}} xmm1 = [1431655765,858993459,715827882,477218588]
158 ; SSE4-NEXT: pminud %xmm0, %xmm1
159 ; SSE4-NEXT: pcmpeqd %xmm1, %xmm0
162 ; AVX2-LABEL: p5_vector_urem_by_const__nonsplat:
164 ; AVX2-NEXT: vpand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
165 ; AVX2-NEXT: vpmulld {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
166 ; AVX2-NEXT: vpsrlvd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm1
167 ; AVX2-NEXT: vpsllvd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm0
168 ; AVX2-NEXT: vpor %xmm1, %xmm0, %xmm0
169 ; AVX2-NEXT: vpminud {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0, %xmm1
170 ; AVX2-NEXT: vpcmpeqd %xmm1, %xmm0, %xmm0
172 %t0 = and <4 x i32> %x, <i32 128, i32 2, i32 4, i32 8>
173 %t1 = urem <4 x i32> %t0, <i32 3, i32 5, i32 6, i32 9>
174 %t2 = icmp eq <4 x i32> %t1, <i32 0, i32 0, i32 0, i32 0>
178 define <4 x i1> @p6_vector_urem_by_const__nonsplat_undef0(<4 x i32> %x, <4 x i32> %y) {
179 ; SSE2-LABEL: p6_vector_urem_by_const__nonsplat_undef0:
181 ; SSE2-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
182 ; SSE2-NEXT: movdqa {{.*#+}} xmm1 = [2863311531,2863311531,2863311531,2863311531]
183 ; SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm0[1,1,3,3]
184 ; SSE2-NEXT: pmuludq %xmm1, %xmm0
185 ; SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm0[0,2,2,3]
186 ; SSE2-NEXT: pmuludq %xmm1, %xmm2
187 ; SSE2-NEXT: pshufd {{.*#+}} xmm0 = xmm2[0,2,2,3]
188 ; SSE2-NEXT: punpckldq {{.*#+}} xmm3 = xmm3[0],xmm0[0],xmm3[1],xmm0[1]
189 ; SSE2-NEXT: movdqa %xmm3, %xmm0
190 ; SSE2-NEXT: psrld $1, %xmm0
191 ; SSE2-NEXT: pslld $31, %xmm3
192 ; SSE2-NEXT: por %xmm0, %xmm3
193 ; SSE2-NEXT: pxor {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm3
194 ; SSE2-NEXT: pcmpgtd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm3
195 ; SSE2-NEXT: pcmpeqd %xmm0, %xmm0
196 ; SSE2-NEXT: pxor %xmm3, %xmm0
199 ; SSE4-LABEL: p6_vector_urem_by_const__nonsplat_undef0:
201 ; SSE4-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
202 ; SSE4-NEXT: pmulld {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
203 ; SSE4-NEXT: movdqa %xmm0, %xmm1
204 ; SSE4-NEXT: psrld $1, %xmm1
205 ; SSE4-NEXT: pslld $31, %xmm0
206 ; SSE4-NEXT: por %xmm1, %xmm0
207 ; SSE4-NEXT: movdqa {{.*#+}} xmm1 = [715827882,715827882,715827882,715827882]
208 ; SSE4-NEXT: pminud %xmm0, %xmm1
209 ; SSE4-NEXT: pcmpeqd %xmm1, %xmm0
212 ; AVX2-LABEL: p6_vector_urem_by_const__nonsplat_undef0:
214 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm1 = [128,128,128,128]
215 ; AVX2-NEXT: vpand %xmm1, %xmm0, %xmm0
216 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm1 = [2863311531,2863311531,2863311531,2863311531]
217 ; AVX2-NEXT: vpmulld %xmm1, %xmm0, %xmm0
218 ; AVX2-NEXT: vpsrld $1, %xmm0, %xmm0
219 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm1 = [715827882,715827882,715827882,715827882]
220 ; AVX2-NEXT: vpminud %xmm1, %xmm0, %xmm1
221 ; AVX2-NEXT: vpcmpeqd %xmm1, %xmm0, %xmm0
223 %t0 = and <4 x i32> %x, <i32 128, i32 128, i32 undef, i32 128>
224 %t1 = urem <4 x i32> %t0, <i32 6, i32 6, i32 6, i32 6> ; '6' is clearly not a power of two
225 %t2 = icmp eq <4 x i32> %t1, <i32 0, i32 0, i32 0, i32 0>
229 define <4 x i1> @p7_vector_urem_by_const__nonsplat_undef2(<4 x i32> %x, <4 x i32> %y) {
230 ; SSE2-LABEL: p7_vector_urem_by_const__nonsplat_undef2:
232 ; SSE2-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
233 ; SSE2-NEXT: movdqa {{.*#+}} xmm1 = [2863311531,2863311531,2863311531,2863311531]
234 ; SSE2-NEXT: movdqa %xmm0, %xmm2
235 ; SSE2-NEXT: pmuludq %xmm1, %xmm2
236 ; SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm2[1,3,2,3]
237 ; SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm0[1,1,3,3]
238 ; SSE2-NEXT: pmuludq %xmm1, %xmm3
239 ; SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm3[1,3,2,3]
240 ; SSE2-NEXT: punpckldq {{.*#+}} xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
241 ; SSE2-NEXT: psrld $2, %xmm2
242 ; SSE2-NEXT: pmaddwd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm2
243 ; SSE2-NEXT: psubd %xmm2, %xmm0
244 ; SSE2-NEXT: pxor %xmm1, %xmm1
245 ; SSE2-NEXT: pcmpeqd %xmm1, %xmm0
248 ; SSE4-LABEL: p7_vector_urem_by_const__nonsplat_undef2:
250 ; SSE4-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
251 ; SSE4-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,1,3,3]
252 ; SSE4-NEXT: movdqa {{.*#+}} xmm2 = [2863311531,2863311531,2863311531,2863311531]
253 ; SSE4-NEXT: pmuludq %xmm2, %xmm1
254 ; SSE4-NEXT: pmuludq %xmm0, %xmm2
255 ; SSE4-NEXT: pshufd {{.*#+}} xmm2 = xmm2[1,1,3,3]
256 ; SSE4-NEXT: pblendw {{.*#+}} xmm2 = xmm2[0,1],xmm1[2,3],xmm2[4,5],xmm1[6,7]
257 ; SSE4-NEXT: psrld $2, %xmm2
258 ; SSE4-NEXT: pmaddwd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm2
259 ; SSE4-NEXT: psubd %xmm2, %xmm0
260 ; SSE4-NEXT: pxor %xmm1, %xmm1
261 ; SSE4-NEXT: pcmpeqd %xmm1, %xmm0
264 ; AVX2-LABEL: p7_vector_urem_by_const__nonsplat_undef2:
266 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm1 = [128,128,128,128]
267 ; AVX2-NEXT: vpand %xmm1, %xmm0, %xmm0
268 ; AVX2-NEXT: vpshufd {{.*#+}} xmm1 = xmm0[1,1,3,3]
269 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm2 = [2863311531,2863311531,2863311531,2863311531]
270 ; AVX2-NEXT: vpmuludq %xmm2, %xmm1, %xmm1
271 ; AVX2-NEXT: vpmuludq %xmm2, %xmm0, %xmm2
272 ; AVX2-NEXT: vpshufd {{.*#+}} xmm2 = xmm2[1,1,3,3]
273 ; AVX2-NEXT: vpblendd {{.*#+}} xmm1 = xmm2[0],xmm1[1],xmm2[2],xmm1[3]
274 ; AVX2-NEXT: vpsrld $2, %xmm1, %xmm1
275 ; AVX2-NEXT: vpmaddwd {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm1, %xmm1
276 ; AVX2-NEXT: vpsubd %xmm1, %xmm0, %xmm0
277 ; AVX2-NEXT: vpxor %xmm1, %xmm1, %xmm1
278 ; AVX2-NEXT: vpcmpeqd %xmm1, %xmm0, %xmm0
280 %t0 = and <4 x i32> %x, <i32 128, i32 128, i32 128, i32 128> ; clearly a power-of-two or zero
281 %t1 = urem <4 x i32> %t0, <i32 6, i32 6, i32 6, i32 6> ; '6' is clearly not a power of two
282 %t2 = icmp eq <4 x i32> %t1, <i32 0, i32 0, i32 undef, i32 0>
286 define <4 x i1> @p8_vector_urem_by_const__nonsplat_undef3(<4 x i32> %x, <4 x i32> %y) {
287 ; SSE2-LABEL: p8_vector_urem_by_const__nonsplat_undef3:
289 ; SSE2-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
290 ; SSE2-NEXT: movdqa {{.*#+}} xmm1 = [2863311531,2863311531,2863311531,2863311531]
291 ; SSE2-NEXT: movdqa %xmm0, %xmm2
292 ; SSE2-NEXT: pmuludq %xmm1, %xmm2
293 ; SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm2[1,3,2,3]
294 ; SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm0[1,1,3,3]
295 ; SSE2-NEXT: pmuludq %xmm1, %xmm3
296 ; SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm3[1,3,2,3]
297 ; SSE2-NEXT: punpckldq {{.*#+}} xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
298 ; SSE2-NEXT: psrld $2, %xmm2
299 ; SSE2-NEXT: movdqa {{.*#+}} xmm1 = [6,6,6,6]
300 ; SSE2-NEXT: pshufd {{.*#+}} xmm3 = xmm2[1,1,3,3]
301 ; SSE2-NEXT: pmuludq %xmm1, %xmm2
302 ; SSE2-NEXT: pshufd {{.*#+}} xmm2 = xmm2[0,2,2,3]
303 ; SSE2-NEXT: pmuludq %xmm1, %xmm3
304 ; SSE2-NEXT: pshufd {{.*#+}} xmm1 = xmm3[0,2,2,3]
305 ; SSE2-NEXT: punpckldq {{.*#+}} xmm2 = xmm2[0],xmm1[0],xmm2[1],xmm1[1]
306 ; SSE2-NEXT: psubd %xmm2, %xmm0
307 ; SSE2-NEXT: pxor %xmm1, %xmm1
308 ; SSE2-NEXT: pcmpeqd %xmm1, %xmm0
311 ; SSE4-LABEL: p8_vector_urem_by_const__nonsplat_undef3:
313 ; SSE4-NEXT: pand {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm0
314 ; SSE4-NEXT: pshufd {{.*#+}} xmm1 = xmm0[1,1,3,3]
315 ; SSE4-NEXT: movdqa {{.*#+}} xmm2 = [2863311531,2863311531,2863311531,2863311531]
316 ; SSE4-NEXT: pmuludq %xmm2, %xmm1
317 ; SSE4-NEXT: pmuludq %xmm0, %xmm2
318 ; SSE4-NEXT: pshufd {{.*#+}} xmm2 = xmm2[1,1,3,3]
319 ; SSE4-NEXT: pblendw {{.*#+}} xmm2 = xmm2[0,1],xmm1[2,3],xmm2[4,5],xmm1[6,7]
320 ; SSE4-NEXT: psrld $2, %xmm2
321 ; SSE4-NEXT: pmulld {{\.?LCPI[0-9]+_[0-9]+}}(%rip), %xmm2
322 ; SSE4-NEXT: psubd %xmm2, %xmm0
323 ; SSE4-NEXT: pxor %xmm1, %xmm1
324 ; SSE4-NEXT: pcmpeqd %xmm1, %xmm0
327 ; AVX2-LABEL: p8_vector_urem_by_const__nonsplat_undef3:
329 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm1 = [128,128,128,128]
330 ; AVX2-NEXT: vpand %xmm1, %xmm0, %xmm0
331 ; AVX2-NEXT: vpshufd {{.*#+}} xmm1 = xmm0[1,1,3,3]
332 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm2 = [2863311531,2863311531,2863311531,2863311531]
333 ; AVX2-NEXT: vpmuludq %xmm2, %xmm1, %xmm1
334 ; AVX2-NEXT: vpmuludq %xmm2, %xmm0, %xmm2
335 ; AVX2-NEXT: vpshufd {{.*#+}} xmm2 = xmm2[1,1,3,3]
336 ; AVX2-NEXT: vpblendd {{.*#+}} xmm1 = xmm2[0],xmm1[1],xmm2[2],xmm1[3]
337 ; AVX2-NEXT: vpsrld $2, %xmm1, %xmm1
338 ; AVX2-NEXT: vpbroadcastd {{.*#+}} xmm2 = [6,6,6,6]
339 ; AVX2-NEXT: vpmulld %xmm2, %xmm1, %xmm1
340 ; AVX2-NEXT: vpsubd %xmm1, %xmm0, %xmm0
341 ; AVX2-NEXT: vpxor %xmm1, %xmm1, %xmm1
342 ; AVX2-NEXT: vpcmpeqd %xmm1, %xmm0, %xmm0
344 %t0 = and <4 x i32> %x, <i32 128, i32 128, i32 undef, i32 128>
345 %t1 = urem <4 x i32> %t0, <i32 6, i32 6, i32 6, i32 6> ; '6' is clearly not a power of two
346 %t2 = icmp eq <4 x i32> %t1, <i32 0, i32 0, i32 undef, i32 0>
350 ;------------------------------------------------------------------------------;
351 ; Basic negative tests
352 ;------------------------------------------------------------------------------;
354 define i1 @n0_urem_of_maybe_not_power_of_two(i32 %x, i32 %y) {
355 ; CHECK-LABEL: n0_urem_of_maybe_not_power_of_two:
357 ; CHECK-NEXT: andl $3, %edi
358 ; CHECK-NEXT: imull $-1431655765, %edi, %eax # imm = 0xAAAAAAAB
359 ; CHECK-NEXT: cmpl $1431655766, %eax # imm = 0x55555556
360 ; CHECK-NEXT: setb %al
362 %t0 = and i32 %x, 3 ; up to two bits set, not power-of-two
363 %t1 = urem i32 %t0, 3
364 %t2 = icmp eq i32 %t1, 0
368 define i1 @n1_urem_by_maybe_power_of_two(i32 %x, i32 %y) {
369 ; CHECK-LABEL: n1_urem_by_maybe_power_of_two:
371 ; CHECK-NEXT: movl %edi, %eax
372 ; CHECK-NEXT: andl $128, %eax
373 ; CHECK-NEXT: orl $1, %esi
374 ; CHECK-NEXT: xorl %edx, %edx
375 ; CHECK-NEXT: divl %esi
376 ; CHECK-NEXT: testl %edx, %edx
377 ; CHECK-NEXT: sete %al
379 %t0 = and i32 %x, 128 ; clearly a power-of-two or zero
380 %t1 = or i32 %y, 1 ; one low bit set, may be a power of two
381 %t2 = urem i32 %t0, %t1
382 %t3 = icmp eq i32 %t2, 0