blob: a98b49a688c2d149437ba7bdbcd5f913814cd3ad [file] [log] [blame]
NAKAMURA Takumicf396cf2013-12-28 13:04:29 +00001; RUN: llc -mtriple=x86_64-unknown-unknown -mcpu=corei7 -mattr=-sse4.1 < %s | FileCheck %s
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +00002
3; Verify that we don't emit packed vector shifts instructions if the
4; condition used by the vector select is a vector of constants.
5
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +00006define <4 x float> @test1(<4 x float> %a, <4 x float> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +00007; CHECK-LABEL: test1:
8; CHECK: # BB#0:
9; CHECK-NEXT: andps {{.*}}(%rip), %xmm1
10; CHECK-NEXT: andps {{.*}}(%rip), %xmm0
11; CHECK-NEXT: orps %xmm1, %xmm0
12; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000013 %1 = select <4 x i1> <i1 true, i1 false, i1 true, i1 false>, <4 x float> %a, <4 x float> %b
14 ret <4 x float> %1
15}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000016
17define <4 x float> @test2(<4 x float> %a, <4 x float> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +000018; CHECK-LABEL: test2:
19; CHECK: # BB#0:
20; CHECK-NEXT: movsd %xmm0, %xmm1
21; CHECK-NEXT: movaps %xmm1, %xmm0
22; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000023 %1 = select <4 x i1> <i1 true, i1 true, i1 false, i1 false>, <4 x float> %a, <4 x float> %b
24 ret <4 x float> %1
25}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000026
27define <4 x float> @test3(<4 x float> %a, <4 x float> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +000028; CHECK-LABEL: test3:
29; CHECK: # BB#0:
30; CHECK-NEXT: movsd %xmm1, %xmm0
31; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000032 %1 = select <4 x i1> <i1 false, i1 false, i1 true, i1 true>, <4 x float> %a, <4 x float> %b
33 ret <4 x float> %1
34}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000035
36define <4 x float> @test4(<4 x float> %a, <4 x float> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +000037; CHECK-LABEL: test4:
38; CHECK: # BB#0:
39; CHECK-NEXT: movaps %xmm1, %xmm0
40; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000041 %1 = select <4 x i1> <i1 false, i1 false, i1 false, i1 false>, <4 x float> %a, <4 x float> %b
42 ret <4 x float> %1
43}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000044
45define <4 x float> @test5(<4 x float> %a, <4 x float> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +000046; CHECK-LABEL: test5:
47; CHECK: # BB#0:
48; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000049 %1 = select <4 x i1> <i1 true, i1 true, i1 true, i1 true>, <4 x float> %a, <4 x float> %b
50 ret <4 x float> %1
51}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000052
53define <8 x i16> @test6(<8 x i16> %a, <8 x i16> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +000054; CHECK-LABEL: test6:
55; CHECK: # BB#0:
56; CHECK-NEXT: movaps {{.*#+}} xmm1 = [0,65535,0,65535,0,65535,0,65535]
57; CHECK-NEXT: andps %xmm0, %xmm1
58; CHECK-NEXT: andps {{.*}}(%rip), %xmm0
59; CHECK-NEXT: orps %xmm1, %xmm0
60; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000061 %1 = select <8 x i1> <i1 true, i1 false, i1 true, i1 false, i1 true, i1 false, i1 true, i1 false>, <8 x i16> %a, <8 x i16> %a
62 ret <8 x i16> %1
63}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000064
65define <8 x i16> @test7(<8 x i16> %a, <8 x i16> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +000066; CHECK-LABEL: test7:
67; CHECK: # BB#0:
68; CHECK-NEXT: andps {{.*}}(%rip), %xmm1
69; CHECK-NEXT: andps {{.*}}(%rip), %xmm0
70; CHECK-NEXT: orps %xmm1, %xmm0
71; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000072 %1 = select <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 false, i1 false, i1 false, i1 false>, <8 x i16> %a, <8 x i16> %b
73 ret <8 x i16> %1
74}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000075
76define <8 x i16> @test8(<8 x i16> %a, <8 x i16> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +000077; CHECK-LABEL: test8:
78; CHECK: # BB#0:
79; CHECK-NEXT: andps {{.*}}(%rip), %xmm1
80; CHECK-NEXT: andps {{.*}}(%rip), %xmm0
81; CHECK-NEXT: orps %xmm1, %xmm0
82; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000083 %1 = select <8 x i1> <i1 false, i1 false, i1 false, i1 false, i1 true, i1 true, i1 true, i1 true>, <8 x i16> %a, <8 x i16> %b
84 ret <8 x i16> %1
85}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000086
87define <8 x i16> @test9(<8 x i16> %a, <8 x i16> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +000088; CHECK-LABEL: test9:
89; CHECK: # BB#0:
90; CHECK-NEXT: movaps %xmm1, %xmm0
91; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000092 %1 = select <8 x i1> <i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false>, <8 x i16> %a, <8 x i16> %b
93 ret <8 x i16> %1
94}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +000095
96define <8 x i16> @test10(<8 x i16> %a, <8 x i16> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +000097; CHECK-LABEL: test10:
98; CHECK: # BB#0:
99; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +0000100 %1 = select <8 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true>, <8 x i16> %a, <8 x i16> %b
101 ret <8 x i16> %1
102}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +0000103
104define <8 x i16> @test11(<8 x i16> %a, <8 x i16> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000105; CHECK-LABEL: test11:
106; CHECK: # BB#0:
107; CHECK-NEXT: movaps {{.*#+}} xmm2 = <0,65535,65535,0,u,65535,65535,u>
108; CHECK-NEXT: andps %xmm2, %xmm0
109; CHECK-NEXT: andnps %xmm1, %xmm2
110; CHECK-NEXT: orps %xmm0, %xmm2
111; CHECK-NEXT: movaps %xmm2, %xmm0
112; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +0000113 %1 = select <8 x i1> <i1 false, i1 true, i1 true, i1 false, i1 undef, i1 true, i1 true, i1 undef>, <8 x i16> %a, <8 x i16> %b
114 ret <8 x i16> %1
115}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +0000116
117define <8 x i16> @test12(<8 x i16> %a, <8 x i16> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000118; CHECK-LABEL: test12:
119; CHECK: # BB#0:
120; CHECK-NEXT: movaps %xmm1, %xmm0
121; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +0000122 %1 = select <8 x i1> <i1 false, i1 false, i1 undef, i1 false, i1 false, i1 false, i1 false, i1 undef>, <8 x i16> %a, <8 x i16> %b
123 ret <8 x i16> %1
124}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +0000125
126define <8 x i16> @test13(<8 x i16> %a, <8 x i16> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000127; CHECK-LABEL: test13:
128; CHECK: # BB#0:
129; CHECK-NEXT: movaps %xmm1, %xmm0
130; CHECK-NEXT: retq
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +0000131 %1 = select <8 x i1> <i1 undef, i1 undef, i1 undef, i1 undef, i1 undef, i1 undef, i1 undef, i1 undef>, <8 x i16> %a, <8 x i16> %b
132 ret <8 x i16> %1
133}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +0000134
Andrea Di Biagio23df4e42014-01-08 18:33:04 +0000135; Fold (vselect (build_vector AllOnes), N1, N2) -> N1
Andrea Di Biagio23df4e42014-01-08 18:33:04 +0000136define <4 x float> @test14(<4 x float> %a, <4 x float> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000137; CHECK-LABEL: test14:
138; CHECK: # BB#0:
139; CHECK-NEXT: retq
Andrea Di Biagio23df4e42014-01-08 18:33:04 +0000140 %1 = select <4 x i1> <i1 true, i1 undef, i1 true, i1 undef>, <4 x float> %a, <4 x float> %b
141 ret <4 x float> %1
142}
Andrea Di Biagio23df4e42014-01-08 18:33:04 +0000143
144define <8 x i16> @test15(<8 x i16> %a, <8 x i16> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000145; CHECK-LABEL: test15:
146; CHECK: # BB#0:
147; CHECK-NEXT: retq
Andrea Di Biagio23df4e42014-01-08 18:33:04 +0000148 %1 = select <8 x i1> <i1 true, i1 true, i1 true, i1 undef, i1 undef, i1 true, i1 true, i1 undef>, <8 x i16> %a, <8 x i16> %b
149 ret <8 x i16> %1
150}
Andrea Di Biagio23df4e42014-01-08 18:33:04 +0000151
152; Fold (vselect (build_vector AllZeros), N1, N2) -> N2
Andrea Di Biagio23df4e42014-01-08 18:33:04 +0000153define <4 x float> @test16(<4 x float> %a, <4 x float> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000154; CHECK-LABEL: test16:
155; CHECK: # BB#0:
156; CHECK-NEXT: movaps %xmm1, %xmm0
157; CHECK-NEXT: retq
Andrea Di Biagio23df4e42014-01-08 18:33:04 +0000158 %1 = select <4 x i1> <i1 false, i1 undef, i1 false, i1 undef>, <4 x float> %a, <4 x float> %b
159 ret <4 x float> %1
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000160}
Andrea Di Biagio23df4e42014-01-08 18:33:04 +0000161
162define <8 x i16> @test17(<8 x i16> %a, <8 x i16> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000163; CHECK-LABEL: test17:
164; CHECK: # BB#0:
165; CHECK-NEXT: movaps %xmm1, %xmm0
166; CHECK-NEXT: retq
Andrea Di Biagio23df4e42014-01-08 18:33:04 +0000167 %1 = select <8 x i1> <i1 false, i1 false, i1 false, i1 undef, i1 undef, i1 false, i1 false, i1 undef>, <8 x i16> %a, <8 x i16> %b
168 ret <8 x i16> %1
169}
Andrea Di Biagio46dcddb2013-12-27 20:20:28 +0000170
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000171define <4 x float> @test18(<4 x float> %a, <4 x float> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000172; CHECK-LABEL: test18:
173; CHECK: # BB#0:
174; CHECK-NEXT: movss %xmm1, %xmm0
175; CHECK-NEXT: retq
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000176 %1 = select <4 x i1> <i1 false, i1 true, i1 true, i1 true>, <4 x float> %a, <4 x float> %b
177 ret <4 x float> %1
178}
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000179
180define <4 x i32> @test19(<4 x i32> %a, <4 x i32> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000181; CHECK-LABEL: test19:
182; CHECK: # BB#0:
183; CHECK-NEXT: movss %xmm1, %xmm0
184; CHECK-NEXT: retq
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000185 %1 = select <4 x i1> <i1 false, i1 true, i1 true, i1 true>, <4 x i32> %a, <4 x i32> %b
186 ret <4 x i32> %1
187}
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000188
189define <2 x double> @test20(<2 x double> %a, <2 x double> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000190; CHECK-LABEL: test20:
191; CHECK: # BB#0:
192; CHECK-NEXT: movsd %xmm1, %xmm0
193; CHECK-NEXT: retq
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000194 %1 = select <2 x i1> <i1 false, i1 true>, <2 x double> %a, <2 x double> %b
195 ret <2 x double> %1
196}
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000197
198define <2 x i64> @test21(<2 x i64> %a, <2 x i64> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000199; CHECK-LABEL: test21:
200; CHECK: # BB#0:
201; CHECK-NEXT: movsd %xmm1, %xmm0
202; CHECK-NEXT: retq
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000203 %1 = select <2 x i1> <i1 false, i1 true>, <2 x i64> %a, <2 x i64> %b
204 ret <2 x i64> %1
205}
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000206
207define <4 x float> @test22(<4 x float> %a, <4 x float> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000208; CHECK-LABEL: test22:
209; CHECK: # BB#0:
210; CHECK-NEXT: movss %xmm0, %xmm1
211; CHECK-NEXT: movaps %xmm1, %xmm0
212; CHECK-NEXT: retq
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000213 %1 = select <4 x i1> <i1 true, i1 false, i1 false, i1 false>, <4 x float> %a, <4 x float> %b
214 ret <4 x float> %1
215}
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000216
217define <4 x i32> @test23(<4 x i32> %a, <4 x i32> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000218; CHECK-LABEL: test23:
219; CHECK: # BB#0:
220; CHECK-NEXT: movss %xmm0, %xmm1
221; CHECK-NEXT: movaps %xmm1, %xmm0
222; CHECK-NEXT: retq
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000223 %1 = select <4 x i1> <i1 true, i1 false, i1 false, i1 false>, <4 x i32> %a, <4 x i32> %b
224 ret <4 x i32> %1
225}
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000226
227define <2 x double> @test24(<2 x double> %a, <2 x double> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000228; CHECK-LABEL: test24:
229; CHECK: # BB#0:
230; CHECK-NEXT: movsd %xmm0, %xmm1
231; CHECK-NEXT: movaps %xmm1, %xmm0
232; CHECK-NEXT: retq
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000233 %1 = select <2 x i1> <i1 true, i1 false>, <2 x double> %a, <2 x double> %b
234 ret <2 x double> %1
235}
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000236
237define <2 x i64> @test25(<2 x i64> %a, <2 x i64> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000238; CHECK-LABEL: test25:
239; CHECK: # BB#0:
240; CHECK-NEXT: movsd %xmm0, %xmm1
241; CHECK-NEXT: movaps %xmm1, %xmm0
242; CHECK-NEXT: retq
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000243 %1 = select <2 x i1> <i1 true, i1 false>, <2 x i64> %a, <2 x i64> %b
244 ret <2 x i64> %1
245}
Andrea Di Biagio450d1662014-01-20 19:35:22 +0000246
Filipe Cabecinhas82111f12014-05-30 23:03:11 +0000247define <4 x float> @select_of_shuffles_0(<2 x float> %a0, <2 x float> %b0, <2 x float> %a1, <2 x float> %b1) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000248; CHECK-LABEL: select_of_shuffles_0:
249; CHECK: # BB#0:
Chandler Carruth99627bf2014-10-04 03:52:55 +0000250; CHECK-NEXT: unpcklpd {{.*#+}} xmm0 = xmm0[0],xmm2[0]
251; CHECK-NEXT: unpcklpd {{.*#+}} xmm1 = xmm1[0],xmm3[0]
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000252; CHECK-NEXT: subps %xmm1, %xmm0
253; CHECK-NEXT: retq
Filipe Cabecinhas82111f12014-05-30 23:03:11 +0000254 %1 = shufflevector <2 x float> %a0, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
255 %2 = shufflevector <2 x float> %a1, <2 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
256 %3 = select <4 x i1> <i1 false, i1 false, i1 true, i1 true>, <4 x float> %2, <4 x float> %1
257 %4 = shufflevector <2 x float> %b0, <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 undef, i32 undef>
258 %5 = shufflevector <2 x float> %b1, <2 x float> undef, <4 x i32> <i32 undef, i32 undef, i32 0, i32 1>
259 %6 = select <4 x i1> <i1 false, i1 false, i1 true, i1 true>, <4 x float> %5, <4 x float> %4
260 %7 = fsub <4 x float> %3, %6
261 ret <4 x float> %7
262}
Benjamin Kramerff8b8832014-08-21 13:28:02 +0000263
Benjamin Kramerff8b8832014-08-21 13:28:02 +0000264; PR20677
265define <16 x double> @select_illegal(<16 x double> %a, <16 x double> %b) {
Chandler Carruth3a0883f2014-10-03 01:57:38 +0000266; CHECK-LABEL: select_illegal:
267; CHECK: # BB#0:
268; CHECK-NEXT: movaps {{[0-9]+}}(%rsp), %xmm4
269; CHECK-NEXT: movaps {{[0-9]+}}(%rsp), %xmm5
270; CHECK-NEXT: movaps {{[0-9]+}}(%rsp), %xmm6
271; CHECK-NEXT: movaps {{[0-9]+}}(%rsp), %xmm7
272; CHECK-NEXT: movaps %xmm7, 112(%rdi)
273; CHECK-NEXT: movaps %xmm6, 96(%rdi)
274; CHECK-NEXT: movaps %xmm5, 80(%rdi)
275; CHECK-NEXT: movaps %xmm4, 64(%rdi)
276; CHECK-NEXT: movaps %xmm3, 48(%rdi)
277; CHECK-NEXT: movaps %xmm2, 32(%rdi)
278; CHECK-NEXT: movaps %xmm1, 16(%rdi)
279; CHECK-NEXT: movaps %xmm0, (%rdi)
280; CHECK-NEXT: retq
Benjamin Kramerff8b8832014-08-21 13:28:02 +0000281 %sel = select <16 x i1> <i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 true, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false, i1 false>, <16 x double> %a, <16 x double> %b
282 ret <16 x double> %sel
283}