1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=x86_64-unknown-unknown -mattr=+sse4.1 < %s | FileCheck %s
4 define i32 @and_self(i32 %x) {
5 ; CHECK-LABEL: and_self:
7 ; CHECK-NEXT: movl %edi, %eax
13 define <4 x i32> @and_self_vec(<4 x i32> %x) {
14 ; CHECK-LABEL: and_self_vec:
17 %and = and <4 x i32> %x, %x
22 ; Verify that the DAGCombiner is able to fold a vector AND into a blend
23 ; if one of the operands to the AND is a vector of all constants, and each
24 ; constant element is either zero or all-ones.
27 define <4 x i32> @test1(<4 x i32> %A) {
30 ; CHECK-NEXT: xorps %xmm1, %xmm1
31 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2,3]
33 %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 0, i32 0>
37 define <4 x i32> @test2(<4 x i32> %A) {
40 ; CHECK-NEXT: xorps %xmm1, %xmm1
41 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1],xmm1[2,3]
43 %1 = and <4 x i32> %A, <i32 0, i32 -1, i32 0, i32 0>
47 define <4 x i32> @test3(<4 x i32> %A) {
50 ; CHECK-NEXT: xorps %xmm1, %xmm1
51 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2],xmm1[3]
53 %1 = and <4 x i32> %A, <i32 0, i32 0, i32 -1, i32 0>
57 define <4 x i32> @test4(<4 x i32> %A) {
60 ; CHECK-NEXT: xorps %xmm1, %xmm1
61 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1,2],xmm0[3]
63 %1 = and <4 x i32> %A, <i32 0, i32 0, i32 0, i32 -1>
67 define <4 x i32> @test5(<4 x i32> %A) {
70 ; CHECK-NEXT: xorps %xmm1, %xmm1
71 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1],xmm0[2],xmm1[3]
73 %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 -1, i32 0>
77 define <4 x i32> @test6(<4 x i32> %A) {
80 ; CHECK-NEXT: xorps %xmm1, %xmm1
81 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1],xmm1[2],xmm0[3]
83 %1 = and <4 x i32> %A, <i32 0, i32 -1, i32 0, i32 -1>
87 define <4 x i32> @test7(<4 x i32> %A) {
90 ; CHECK-NEXT: xorps %xmm1, %xmm1
91 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0,1],xmm0[2,3]
93 %1 = and <4 x i32> %A, <i32 0, i32 0, i32 -1, i32 -1>
97 define <4 x i32> @test8(<4 x i32> %A) {
100 ; CHECK-NEXT: xorps %xmm1, %xmm1
101 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1,2],xmm0[3]
103 %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 0, i32 -1>
107 define <4 x i32> @test9(<4 x i32> %A) {
108 ; CHECK-LABEL: test9:
110 ; CHECK-NEXT: movq {{.*#+}} xmm0 = xmm0[0],zero
112 %1 = and <4 x i32> %A, <i32 -1, i32 -1, i32 0, i32 0>
116 define <4 x i32> @test10(<4 x i32> %A) {
117 ; CHECK-LABEL: test10:
119 ; CHECK-NEXT: xorps %xmm1, %xmm1
120 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2],xmm1[3]
122 %1 = and <4 x i32> %A, <i32 0, i32 -1, i32 -1, i32 0>
126 define <4 x i32> @test11(<4 x i32> %A) {
127 ; CHECK-LABEL: test11:
129 ; CHECK-NEXT: xorps %xmm1, %xmm1
130 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1,2,3]
132 %1 = and <4 x i32> %A, <i32 0, i32 -1, i32 -1, i32 -1>
136 define <4 x i32> @test12(<4 x i32> %A) {
137 ; CHECK-LABEL: test12:
139 ; CHECK-NEXT: xorps %xmm1, %xmm1
140 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1,2],xmm1[3]
142 %1 = and <4 x i32> %A, <i32 -1, i32 -1, i32 -1, i32 0>
146 define <4 x i32> @test13(<4 x i32> %A) {
147 ; CHECK-LABEL: test13:
149 ; CHECK-NEXT: xorps %xmm1, %xmm1
150 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0,1],xmm1[2],xmm0[3]
152 %1 = and <4 x i32> %A, <i32 -1, i32 -1, i32 0, i32 -1>
156 define <4 x i32> @test14(<4 x i32> %A) {
157 ; CHECK-LABEL: test14:
159 ; CHECK-NEXT: xorps %xmm1, %xmm1
160 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1],xmm0[2,3]
162 %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 -1, i32 -1>
166 define <4 x i32> @test15(<4 x i32> %A, <4 x i32> %B) {
167 ; CHECK-LABEL: test15:
169 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1],xmm0[2,3]
171 %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 -1, i32 -1>
172 %2 = and <4 x i32> %B, <i32 0, i32 -1, i32 0, i32 0>
173 %3 = or <4 x i32> %1, %2
177 define <4 x i32> @test16(<4 x i32> %A, <4 x i32> %B) {
178 ; CHECK-LABEL: test16:
180 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm0[0],xmm1[1],xmm0[2],xmm1[3]
182 %1 = and <4 x i32> %A, <i32 -1, i32 0, i32 -1, i32 0>
183 %2 = and <4 x i32> %B, <i32 0, i32 -1, i32 0, i32 -1>
184 %3 = or <4 x i32> %1, %2
188 define <4 x i32> @test17(<4 x i32> %A, <4 x i32> %B) {
189 ; CHECK-LABEL: test17:
191 ; CHECK-NEXT: blendps {{.*#+}} xmm0 = xmm1[0],xmm0[1],xmm1[2],xmm0[3]
193 %1 = and <4 x i32> %A, <i32 0, i32 -1, i32 0, i32 -1>
194 %2 = and <4 x i32> %B, <i32 -1, i32 0, i32 -1, i32 0>
195 %3 = or <4 x i32> %1, %2
200 ; fold (and (or x, C), D) -> D if (C & D) == D
203 define <2 x i64> @and_or_v2i64(<2 x i64> %a0) {
204 ; CHECK-LABEL: and_or_v2i64:
206 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [8,8]
208 %1 = or <2 x i64> %a0, <i64 255, i64 255>
209 %2 = and <2 x i64> %1, <i64 8, i64 8>
213 define <4 x i32> @and_or_v4i32(<4 x i32> %a0) {
214 ; CHECK-LABEL: and_or_v4i32:
216 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [3,3,3,3]
218 %1 = or <4 x i32> %a0, <i32 15, i32 15, i32 15, i32 15>
219 %2 = and <4 x i32> %1, <i32 3, i32 3, i32 3, i32 3>
223 define <8 x i16> @and_or_v8i16(<8 x i16> %a0) {
224 ; CHECK-LABEL: and_or_v8i16:
226 ; CHECK-NEXT: movaps {{.*#+}} xmm0 = [15,7,3,1,14,10,2,32767]
228 %1 = or <8 x i16> %a0, <i16 255, i16 127, i16 63, i16 31, i16 15, i16 31, i16 63, i16 -1>
229 %2 = and <8 x i16> %1, <i16 15, i16 7, i16 3, i16 1, i16 14, i16 10, i16 2, i16 32767>
237 define <2 x i64> @and_or_zext_v2i32(<2 x i32> %a0) {
238 ; CHECK-LABEL: and_or_zext_v2i32:
240 ; CHECK-NEXT: xorps %xmm0, %xmm0
242 %1 = zext <2 x i32> %a0 to <2 x i64>
243 %2 = or <2 x i64> %1, <i64 1, i64 1>
244 %3 = and <2 x i64> %2, <i64 4294967296, i64 4294967296>
248 define <4 x i32> @and_or_zext_v4i16(<4 x i16> %a0) {
249 ; CHECK-LABEL: and_or_zext_v4i16:
251 ; CHECK-NEXT: xorps %xmm0, %xmm0
253 %1 = zext <4 x i16> %a0 to <4 x i32>
254 %2 = or <4 x i32> %1, <i32 1, i32 1, i32 1, i32 1>
255 %3 = and <4 x i32> %2, <i32 65536, i32 65536, i32 65536, i32 65536>
260 ; known sign bits folding
263 define <8 x i16> @ashr_mask1_v8i16(<8 x i16> %a0) {
264 ; CHECK-LABEL: ashr_mask1_v8i16:
266 ; CHECK-NEXT: psrlw $15, %xmm0
268 %1 = ashr <8 x i16> %a0, <i16 15, i16 15, i16 15, i16 15, i16 15, i16 15, i16 15, i16 15>
269 %2 = and <8 x i16> %1, <i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1, i16 1>
273 define <4 x i32> @ashr_mask7_v4i32(<4 x i32> %a0) {
274 ; CHECK-LABEL: ashr_mask7_v4i32:
276 ; CHECK-NEXT: psrad $31, %xmm0
277 ; CHECK-NEXT: psrld $29, %xmm0
279 %1 = ashr <4 x i32> %a0, <i32 31, i32 31, i32 31, i32 31>
280 %2 = and <4 x i32> %1, <i32 7, i32 7, i32 7, i32 7>
285 ; SimplifyDemandedBits
288 ; PR34620 - redundant PAND after vector shift of a byte vector (PSRLW)
289 define <16 x i8> @PR34620(<16 x i8> %a0, <16 x i8> %a1) {
290 ; CHECK-LABEL: PR34620:
292 ; CHECK-NEXT: psrlw $1, %xmm0
293 ; CHECK-NEXT: pand {{.*}}(%rip), %xmm0
294 ; CHECK-NEXT: paddb %xmm1, %xmm0
296 %1 = lshr <16 x i8> %a0, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
297 %2 = and <16 x i8> %1, <i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1, i8 1>
298 %3 = add <16 x i8> %2, %a1