1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7 | FileCheck %s
4 define i32 @or_self(i32 %x) {
5 ; CHECK-LABEL: or_self:
7 ; CHECK-NEXT: movl %edi, %eax
13 define <4 x i32> @or_self_vec(<4 x i32> %x) {
14 ; CHECK-LABEL: or_self_vec:
17 %or = or <4 x i32> %x, %x
21 ; Verify that each of the following test cases is folded into a single
22 ; instruction which performs a blend operation.
24 define <2 x i64> @test1(<2 x i64> %a, <2 x i64> %b) {
27 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
29 %shuf1 = shufflevector <2 x i64> %a, <2 x i64> zeroinitializer, <2 x i32><i32 0, i32 2>
30 %shuf2 = shufflevector <2 x i64> %b, <2 x i64> zeroinitializer, <2 x i32><i32 2, i32 1>
31 %or = or <2 x i64> %shuf1, %shuf2
36 define <4 x i32> @test2(<4 x i32> %a, <4 x i32> %b) {
39 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
41 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> zeroinitializer, <4 x i32><i32 4, i32 4, i32 2, i32 3>
42 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> zeroinitializer, <4 x i32><i32 0, i32 1, i32 4, i32 4>
43 %or = or <4 x i32> %shuf1, %shuf2
48 define <2 x i64> @test3(<2 x i64> %a, <2 x i64> %b) {
51 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
53 %shuf1 = shufflevector <2 x i64> %a, <2 x i64> zeroinitializer, <2 x i32><i32 2, i32 1>
54 %shuf2 = shufflevector <2 x i64> %b, <2 x i64> zeroinitializer, <2 x i32><i32 0, i32 2>
55 %or = or <2 x i64> %shuf1, %shuf2
60 define <4 x i32> @test4(<4 x i32> %a, <4 x i32> %b) {
63 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3]
65 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> zeroinitializer, <4 x i32><i32 0, i32 4, i32 4, i32 4>
66 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> zeroinitializer, <4 x i32><i32 4, i32 1, i32 2, i32 3>
67 %or = or <4 x i32> %shuf1, %shuf2
72 define <4 x i32> @test5(<4 x i32> %a, <4 x i32> %b) {
75 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
77 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> zeroinitializer, <4 x i32><i32 4, i32 1, i32 2, i32 3>
78 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> zeroinitializer, <4 x i32><i32 0, i32 4, i32 4, i32 4>
79 %or = or <4 x i32> %shuf1, %shuf2
84 define <4 x i32> @test6(<4 x i32> %a, <4 x i32> %b) {
87 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
89 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> zeroinitializer, <4 x i32><i32 0, i32 1, i32 4, i32 4>
90 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> zeroinitializer, <4 x i32><i32 4, i32 4, i32 2, i32 3>
91 %or = or <4 x i32> %shuf1, %shuf2
96 define <4 x i32> @test7(<4 x i32> %a, <4 x i32> %b) {
99 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
101 %and1 = and <4 x i32> %a, <i32 -1, i32 -1, i32 0, i32 0>
102 %and2 = and <4 x i32> %b, <i32 0, i32 0, i32 -1, i32 -1>
103 %or = or <4 x i32> %and1, %and2
108 define <2 x i64> @test8(<2 x i64> %a, <2 x i64> %b) {
109 ; CHECK-LABEL: test8:
111 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2,3]
113 %and1 = and <2 x i64> %a, <i64 -1, i64 0>
114 %and2 = and <2 x i64> %b, <i64 0, i64 -1>
115 %or = or <2 x i64> %and1, %and2
120 define <4 x i32> @test9(<4 x i32> %a, <4 x i32> %b) {
121 ; CHECK-LABEL: test9:
123 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
125 %and1 = and <4 x i32> %a, <i32 0, i32 0, i32 -1, i32 -1>
126 %and2 = and <4 x i32> %b, <i32 -1, i32 -1, i32 0, i32 0>
127 %or = or <4 x i32> %and1, %and2
132 define <2 x i64> @test10(<2 x i64> %a, <2 x i64> %b) {
133 ; CHECK-LABEL: test10:
135 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
137 %and1 = and <2 x i64> %a, <i64 0, i64 -1>
138 %and2 = and <2 x i64> %b, <i64 -1, i64 0>
139 %or = or <2 x i64> %and1, %and2
144 define <4 x i32> @test11(<4 x i32> %a, <4 x i32> %b) {
145 ; CHECK-LABEL: test11:
147 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3]
149 %and1 = and <4 x i32> %a, <i32 -1, i32 0, i32 0, i32 0>
150 %and2 = and <4 x i32> %b, <i32 0, i32 -1, i32 -1, i32 -1>
151 %or = or <4 x i32> %and1, %and2
156 define <4 x i32> @test12(<4 x i32> %a, <4 x i32> %b) {
157 ; CHECK-LABEL: test12:
159 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
161 %and1 = and <4 x i32> %a, <i32 0, i32 -1, i32 -1, i32 -1>
162 %and2 = and <4 x i32> %b, <i32 -1, i32 0, i32 0, i32 0>
163 %or = or <4 x i32> %and1, %and2
168 ; Verify that the following test cases are folded into single shuffles.
170 define <4 x i32> @test13(<4 x i32> %a, <4 x i32> %b) {
171 ; CHECK-LABEL: test13:
173 ; CHECK-NEXT: shufps {{.*#+}} xmm0 = xmm0[1,1],xmm1[2,3]
175 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> zeroinitializer, <4 x i32><i32 1, i32 1, i32 4, i32 4>
176 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> zeroinitializer, <4 x i32><i32 4, i32 4, i32 2, i32 3>
177 %or = or <4 x i32> %shuf1, %shuf2
182 define <2 x i64> @test14(<2 x i64> %a, <2 x i64> %b) {
183 ; CHECK-LABEL: test14:
185 ; CHECK-NEXT: movlhps {{.*#+}} xmm0 = xmm0[0],xmm1[0]
187 %shuf1 = shufflevector <2 x i64> %a, <2 x i64> zeroinitializer, <2 x i32><i32 0, i32 2>
188 %shuf2 = shufflevector <2 x i64> %b, <2 x i64> zeroinitializer, <2 x i32><i32 2, i32 0>
189 %or = or <2 x i64> %shuf1, %shuf2
194 define <4 x i32> @test15(<4 x i32> %a, <4 x i32> %b) {
195 ; CHECK-LABEL: test15:
197 ; CHECK-NEXT: shufps {{.*#+}} xmm1 = xmm1[2,1],xmm0[2,1]
198 ; CHECK-NEXT: movaps %xmm1, %xmm0
200 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> zeroinitializer, <4 x i32><i32 4, i32 4, i32 2, i32 1>
201 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> zeroinitializer, <4 x i32><i32 2, i32 1, i32 4, i32 4>
202 %or = or <4 x i32> %shuf1, %shuf2
207 define <2 x i64> @test16(<2 x i64> %a, <2 x i64> %b) {
208 ; CHECK-LABEL: test16:
210 ; CHECK-NEXT: movlhps {{.*#+}} xmm1 = xmm1[0],xmm0[0]
211 ; CHECK-NEXT: movaps %xmm1, %xmm0
213 %shuf1 = shufflevector <2 x i64> %a, <2 x i64> zeroinitializer, <2 x i32><i32 2, i32 0>
214 %shuf2 = shufflevector <2 x i64> %b, <2 x i64> zeroinitializer, <2 x i32><i32 0, i32 2>
215 %or = or <2 x i64> %shuf1, %shuf2
220 ; Verify that the dag-combiner does not fold a OR of two shuffles into a single
221 ; shuffle instruction when the shuffle indexes are not compatible.
223 define <4 x i32> @test17(<4 x i32> %a, <4 x i32> %b) {
224 ; CHECK-LABEL: test17:
226 ; CHECK-NEXT: psllq $32, %xmm0
227 ; CHECK-NEXT: movq {{.*#+}} xmm1 = xmm1[0],zero
228 ; CHECK-NEXT: por %xmm1, %xmm0
230 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> zeroinitializer, <4 x i32><i32 4, i32 0, i32 4, i32 2>
231 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> zeroinitializer, <4 x i32><i32 0, i32 1, i32 4, i32 4>
232 %or = or <4 x i32> %shuf1, %shuf2
237 define <4 x i32> @test18(<4 x i32> %a, <4 x i32> %b) {
238 ; CHECK-LABEL: test18:
240 ; CHECK-NEXT: pxor %xmm2, %xmm2
241 ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm2[2,3,4,5,6,7]
242 ; CHECK-NEXT: pshufd {{.*#+}} xmm0 = xmm0[1,0,1,1]
243 ; CHECK-NEXT: pblendw {{.*#+}} xmm1 = xmm1[0,1],xmm2[2,3,4,5,6,7]
244 ; CHECK-NEXT: por %xmm1, %xmm0
246 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> zeroinitializer, <4 x i32><i32 4, i32 0, i32 4, i32 4>
247 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> zeroinitializer, <4 x i32><i32 0, i32 4, i32 4, i32 4>
248 %or = or <4 x i32> %shuf1, %shuf2
253 define <4 x i32> @test19(<4 x i32> %a, <4 x i32> %b) {
254 ; CHECK-LABEL: test19:
256 ; CHECK-NEXT: pshufd {{.*#+}} xmm2 = xmm0[0,0,2,3]
257 ; CHECK-NEXT: pxor %xmm3, %xmm3
258 ; CHECK-NEXT: pblendw {{.*#+}} xmm2 = xmm3[0,1],xmm2[2,3],xmm3[4,5],xmm2[6,7]
259 ; CHECK-NEXT: pshufd {{.*#+}} xmm0 = xmm1[0,1,2,2]
260 ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm0[0,1],xmm3[2,3],xmm0[4,5,6,7]
261 ; CHECK-NEXT: por %xmm2, %xmm0
263 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> zeroinitializer, <4 x i32><i32 4, i32 0, i32 4, i32 3>
264 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> zeroinitializer, <4 x i32><i32 0, i32 4, i32 2, i32 2>
265 %or = or <4 x i32> %shuf1, %shuf2
270 define <2 x i64> @test20(<2 x i64> %a, <2 x i64> %b) {
271 ; CHECK-LABEL: test20:
273 ; CHECK-NEXT: por %xmm1, %xmm0
274 ; CHECK-NEXT: movq {{.*#+}} xmm0 = xmm0[0],zero
276 %shuf1 = shufflevector <2 x i64> %a, <2 x i64> zeroinitializer, <2 x i32><i32 0, i32 2>
277 %shuf2 = shufflevector <2 x i64> %b, <2 x i64> zeroinitializer, <2 x i32><i32 0, i32 2>
278 %or = or <2 x i64> %shuf1, %shuf2
283 define <2 x i64> @test21(<2 x i64> %a, <2 x i64> %b) {
284 ; CHECK-LABEL: test21:
286 ; CHECK-NEXT: por %xmm1, %xmm0
287 ; CHECK-NEXT: pslldq {{.*#+}} xmm0 = zero,zero,zero,zero,zero,zero,zero,zero,xmm0[0,1,2,3,4,5,6,7]
289 %shuf1 = shufflevector <2 x i64> %a, <2 x i64> zeroinitializer, <2 x i32><i32 2, i32 0>
290 %shuf2 = shufflevector <2 x i64> %b, <2 x i64> zeroinitializer, <2 x i32><i32 2, i32 0>
291 %or = or <2 x i64> %shuf1, %shuf2
296 ; Verify that the dag-combiner keeps the correct domain for float/double vectors
297 ; bitcast to use the mask-or blend combine.
299 define <2 x double> @test22(<2 x double> %a0, <2 x double> %a1) {
300 ; CHECK-LABEL: test22:
302 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
304 %bc1 = bitcast <2 x double> %a0 to <2 x i64>
305 %bc2 = bitcast <2 x double> %a1 to <2 x i64>
306 %and1 = and <2 x i64> %bc1, <i64 0, i64 -1>
307 %and2 = and <2 x i64> %bc2, <i64 -1, i64 0>
308 %or = or <2 x i64> %and1, %and2
309 %bc3 = bitcast <2 x i64> %or to <2 x double>
310 ret <2 x double> %bc3
314 define <4 x float> @test23(<4 x float> %a0, <4 x float> %a1) {
315 ; CHECK-LABEL: test23:
317 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2],xmm1[3]
319 %bc1 = bitcast <4 x float> %a0 to <4 x i32>
320 %bc2 = bitcast <4 x float> %a1 to <4 x i32>
321 %and1 = and <4 x i32> %bc1, <i32 0, i32 -1, i32 -1, i32 0>
322 %and2 = and <4 x i32> %bc2, <i32 -1, i32 0, i32 0, i32 -1>
323 %or = or <4 x i32> %and1, %and2
324 %bc3 = bitcast <4 x i32> %or to <4 x float>
329 define <4 x float> @test24(<4 x float> %a0, <4 x float> %a1) {
330 ; CHECK-LABEL: test24:
332 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
334 %bc1 = bitcast <4 x float> %a0 to <2 x i64>
335 %bc2 = bitcast <4 x float> %a1 to <2 x i64>
336 %and1 = and <2 x i64> %bc1, <i64 0, i64 -1>
337 %and2 = and <2 x i64> %bc2, <i64 -1, i64 0>
338 %or = or <2 x i64> %and1, %and2
339 %bc3 = bitcast <2 x i64> %or to <4 x float>
344 define <4 x float> @test25(<4 x float> %a0) {
345 ; CHECK-LABEL: test25:
347 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = mem[0],xmm0[1,2],mem[3]
349 %bc1 = bitcast <4 x float> %a0 to <4 x i32>
350 %bc2 = bitcast <4 x float> <float 1.0, float 1.0, float 1.0, float 1.0> to <4 x i32>
351 %and1 = and <4 x i32> %bc1, <i32 0, i32 -1, i32 -1, i32 0>
352 %and2 = and <4 x i32> %bc2, <i32 -1, i32 0, i32 0, i32 -1>
353 %or = or <4 x i32> %and1, %and2
354 %bc3 = bitcast <4 x i32> %or to <4 x float>
359 ; Verify that the DAGCombiner doesn't crash in the attempt to check if a shuffle
360 ; with illegal type has a legal mask. Method 'isShuffleMaskLegal' only knows how to
361 ; handle legal vector value types.
362 define <4 x i8> @test_crash(<4 x i8> %a, <4 x i8> %b) {
363 ; CHECK-LABEL: test_crash:
365 ; CHECK-NEXT: pblendw {{.*#+}} xmm0 = xmm1[0],xmm0[1],xmm1[2,3,4,5,6,7]
367 %shuf1 = shufflevector <4 x i8> %a, <4 x i8> zeroinitializer, <4 x i32><i32 4, i32 4, i32 2, i32 3>
368 %shuf2 = shufflevector <4 x i8> %b, <4 x i8> zeroinitializer, <4 x i32><i32 0, i32 1, i32 4, i32 4>
369 %or = or <4 x i8> %shuf1, %shuf2
373 ; Verify that we can fold regardless of which operand is the zeroinitializer
375 define <4 x i32> @test2b(<4 x i32> %a, <4 x i32> %b) {
376 ; CHECK-LABEL: test2b:
378 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
380 %shuf1 = shufflevector <4 x i32> zeroinitializer, <4 x i32> %a, <4 x i32><i32 0, i32 0, i32 6, i32 7>
381 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> zeroinitializer, <4 x i32><i32 0, i32 1, i32 4, i32 4>
382 %or = or <4 x i32> %shuf1, %shuf2
386 define <4 x i32> @test2c(<4 x i32> %a, <4 x i32> %b) {
387 ; CHECK-LABEL: test2c:
389 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
391 %shuf1 = shufflevector <4 x i32> zeroinitializer, <4 x i32> %a, <4 x i32><i32 0, i32 0, i32 6, i32 7>
392 %shuf2 = shufflevector <4 x i32> zeroinitializer, <4 x i32> %b, <4 x i32><i32 4, i32 5, i32 0, i32 0>
393 %or = or <4 x i32> %shuf1, %shuf2
398 define <4 x i32> @test2d(<4 x i32> %a, <4 x i32> %b) {
399 ; CHECK-LABEL: test2d:
401 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
403 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> zeroinitializer, <4 x i32><i32 4, i32 4, i32 2, i32 3>
404 %shuf2 = shufflevector <4 x i32> zeroinitializer, <4 x i32> %b, <4 x i32><i32 4, i32 5, i32 0, i32 0>
405 %or = or <4 x i32> %shuf1, %shuf2
409 ; Make sure we can have an undef where an index pointing to the zero vector should be
411 define <4 x i32> @test2e(<4 x i32> %a, <4 x i32> %b) {
412 ; CHECK-LABEL: test2e:
414 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
416 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>, <4 x i32><i32 undef, i32 4, i32 2, i32 3>
417 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>, <4 x i32><i32 0, i32 1, i32 4, i32 4>
418 %or = or <4 x i32> %shuf1, %shuf2
422 define <4 x i32> @test2f(<4 x i32> %a, <4 x i32> %b) {
423 ; CHECK-LABEL: test2f:
425 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
427 %shuf1 = shufflevector <4 x i32> %a, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>, <4 x i32><i32 4, i32 4, i32 2, i32 3>
428 %shuf2 = shufflevector <4 x i32> %b, <4 x i32> <i32 0, i32 undef, i32 undef, i32 undef>, <4 x i32><i32 undef, i32 1, i32 4, i32 4>
429 %or = or <4 x i32> %shuf1, %shuf2
433 ; (or (and X, c1), c2) -> (and (or X, c2), c1|c2) iff (c1 & c2) != 0
435 define <2 x i64> @or_and_v2i64(<2 x i64> %a0) {
436 ; CHECK-LABEL: or_and_v2i64:
438 ; CHECK-NEXT: orps {{.*}}(%rip), %xmm0
439 ; CHECK-NEXT: andps {{.*}}(%rip), %xmm0
441 %1 = and <2 x i64> %a0, <i64 7, i64 7>
442 %2 = or <2 x i64> %1, <i64 3, i64 3>
446 define <4 x i32> @or_and_v4i32(<4 x i32> %a0) {
447 ; CHECK-LABEL: or_and_v4i32:
449 ; CHECK-NEXT: orps {{.*}}(%rip), %xmm0
450 ; CHECK-NEXT: andps {{.*}}(%rip), %xmm0
452 %1 = and <4 x i32> %a0, <i32 1, i32 3, i32 5, i32 7>
453 %2 = or <4 x i32> %1, <i32 3, i32 2, i32 15, i32 2>
457 ; If all masked bits are going to be set, that's a constant fold.
459 define <4 x i32> @or_and_v4i32_fold(<4 x i32> %a0) {
460 ; CHECK-LABEL: or_and_v4i32_fold:
462 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [3,3,3,3]
464 %1 = and <4 x i32> %a0, <i32 1, i32 1, i32 1, i32 1>
465 %2 = or <4 x i32> %1, <i32 3, i32 3, i32 3, i32 3>
469 ; fold (or x, c) -> c iff (x & ~c) == 0
471 define <2 x i64> @or_zext_v2i32(<2 x i32> %a0) {
472 ; CHECK-LABEL: or_zext_v2i32:
474 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [4294967295,4294967295]
476 %1 = zext <2 x i32> %a0 to <2 x i64>
477 %2 = or <2 x i64> %1, <i64 4294967295, i64 4294967295>
481 define <4 x i32> @or_zext_v4i16(<4 x i16> %a0) {
482 ; CHECK-LABEL: or_zext_v4i16:
484 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [65535,65535,65535,65535]
486 %1 = zext <4 x i16> %a0 to <4 x i32>
487 %2 = or <4 x i32> %1, <i32 65535, i32 65535, i32 65535, i32 65535>