[AVX512] Bring back vector-shuffle lowering support through broadcasts
[oota-llvm.git] / test / CodeGen / X86 / fold-vector-sext-zext.ll
1 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7-avx -mattr=+avx | FileCheck %s
2
3 ; Verify that the backend correctly folds a sign/zero extend of a vector where
4 ; elements are all constant values or UNDEFs.
5 ; The backend should be able to optimize all the test functions below into
6 ; simple loads from constant pool of the result. That is because the resulting
7 ; vector should be known at static time.
8
9
10 define <4 x i16> @test1() {
11   %1 = insertelement <4 x i8> undef, i8 0, i32 0
12   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
13   %3 = insertelement <4 x i8> %2, i8 2, i32 2
14   %4 = insertelement <4 x i8> %3, i8 -3, i32 3
15   %5 = sext <4 x i8> %4 to <4 x i16>
16   ret <4 x i16> %5
17 }
18 ; CHECK-LABEL: test1
19 ; CHECK: vmovaps
20 ; CHECK-NEXT: ret
21
22 define <4 x i16> @test2() {
23   %1 = insertelement <4 x i8> undef, i8 undef, i32 0
24   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
25   %3 = insertelement <4 x i8> %2, i8 undef, i32 2
26   %4 = insertelement <4 x i8> %3, i8 -3, i32 3
27   %5 = sext <4 x i8> %4 to <4 x i16>
28   ret <4 x i16> %5
29 }
30 ; CHECK-LABEL: test2
31 ; CHECK: vmovaps
32 ; CHECK-NEXT: ret
33
34 define <4 x i32> @test3() {
35   %1 = insertelement <4 x i8> undef, i8 0, i32 0
36   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
37   %3 = insertelement <4 x i8> %2, i8 2, i32 2
38   %4 = insertelement <4 x i8> %3, i8 -3, i32 3
39   %5 = sext <4 x i8> %4 to <4 x i32>
40   ret <4 x i32> %5
41 }
42 ; CHECK-LABEL: test3
43 ; CHECK: vmovaps
44 ; CHECK-NEXT: ret
45
46 define <4 x i32> @test4() {
47   %1 = insertelement <4 x i8> undef, i8 undef, i32 0
48   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
49   %3 = insertelement <4 x i8> %2, i8 undef, i32 2
50   %4 = insertelement <4 x i8> %3, i8 -3, i32 3
51   %5 = sext <4 x i8> %4 to <4 x i32>
52   ret <4 x i32> %5
53 }
54 ; CHECK-LABEL: test4
55 ; CHECK: vmovaps
56 ; CHECK-NEXT: ret
57
58
59 define <4 x i64> @test5() {
60   %1 = insertelement <4 x i8> undef, i8 0, i32 0
61   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
62   %3 = insertelement <4 x i8> %2, i8 2, i32 2
63   %4 = insertelement <4 x i8> %3, i8 -3, i32 3
64   %5 = sext <4 x i8> %4 to <4 x i64>
65   ret <4 x i64> %5
66 }
67 ; CHECK-LABEL: test5
68 ; CHECK-NOT: vinsertf128
69 ; CHECK: vmovaps
70 ; CHECK-NEXT: ret
71
72 define <4 x i64> @test6() {
73   %1 = insertelement <4 x i8> undef, i8 undef, i32 0
74   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
75   %3 = insertelement <4 x i8> %2, i8 undef, i32 2
76   %4 = insertelement <4 x i8> %3, i8 -3, i32 3
77   %5 = sext <4 x i8> %4 to <4 x i64>
78   ret <4 x i64> %5
79 }
80 ; CHECK-LABEL: test6
81 ; CHECK-NOT: vinsertf128
82 ; CHECK: vmovaps
83 ; CHECK-NEXT: ret
84
85 define <8 x i16> @test7() {
86   %1 = insertelement <8 x i8> undef, i8 0, i32 0
87   %2 = insertelement <8 x i8> %1, i8 -1, i32 1
88   %3 = insertelement <8 x i8> %2, i8 2, i32 2
89   %4 = insertelement <8 x i8> %3, i8 -3, i32 3
90   %5 = insertelement <8 x i8> %4, i8 4, i32 4
91   %6 = insertelement <8 x i8> %5, i8 -5, i32 5
92   %7 = insertelement <8 x i8> %6, i8 6, i32 6
93   %8 = insertelement <8 x i8> %7, i8 -7, i32 7
94   %9 = sext <8 x i8> %4 to <8 x i16>
95   ret <8 x i16> %9
96 }
97 ; CHECK-LABEL: test7
98 ; CHECK: vmovaps
99 ; CHECK-NEXT: ret
100
101 define <8 x i32> @test8() {
102   %1 = insertelement <8 x i8> undef, i8 0, i32 0
103   %2 = insertelement <8 x i8> %1, i8 -1, i32 1
104   %3 = insertelement <8 x i8> %2, i8 2, i32 2
105   %4 = insertelement <8 x i8> %3, i8 -3, i32 3
106   %5 = insertelement <8 x i8> %4, i8 4, i32 4
107   %6 = insertelement <8 x i8> %5, i8 -5, i32 5
108   %7 = insertelement <8 x i8> %6, i8 6, i32 6
109   %8 = insertelement <8 x i8> %7, i8 -7, i32 7
110   %9 = sext <8 x i8> %4 to <8 x i32>
111   ret <8 x i32> %9
112 }
113 ; CHECK-LABEL: test8
114 ; CHECK-NOT: vinsertf128
115 ; CHECK: vmovaps
116 ; CHECK-NEXT: ret
117
118 define <8 x i16> @test9() {
119   %1 = insertelement <8 x i8> undef, i8 undef, i32 0
120   %2 = insertelement <8 x i8> %1, i8 -1, i32 1
121   %3 = insertelement <8 x i8> %2, i8 undef, i32 2
122   %4 = insertelement <8 x i8> %3, i8 -3, i32 3
123   %5 = insertelement <8 x i8> %4, i8 undef, i32 4
124   %6 = insertelement <8 x i8> %5, i8 -5, i32 5
125   %7 = insertelement <8 x i8> %6, i8 undef, i32 6
126   %8 = insertelement <8 x i8> %7, i8 -7, i32 7
127   %9 = sext <8 x i8> %4 to <8 x i16>
128   ret <8 x i16> %9
129 }
130 ; CHECK-LABEL: test9
131 ; CHECK: vmovaps
132 ; CHECK-NEXT: ret
133
134 define <8 x i32> @test10() {
135   %1 = insertelement <8 x i8> undef, i8 0, i32 0
136   %2 = insertelement <8 x i8> %1, i8 undef, i32 1
137   %3 = insertelement <8 x i8> %2, i8 2, i32 2
138   %4 = insertelement <8 x i8> %3, i8 undef, i32 3
139   %5 = insertelement <8 x i8> %4, i8 4, i32 4
140   %6 = insertelement <8 x i8> %5, i8 undef, i32 5
141   %7 = insertelement <8 x i8> %6, i8 6, i32 6
142   %8 = insertelement <8 x i8> %7, i8 undef, i32 7
143   %9 = sext <8 x i8> %4 to <8 x i32>
144   ret <8 x i32> %9
145 }
146 ; CHECK-LABEL: test10
147 ; CHECK-NOT: vinsertf128
148 ; CHECK: vmovaps
149 ; CHECK-NEXT: ret
150
151
152 define <4 x i16> @test11() {
153   %1 = insertelement <4 x i8> undef, i8 0, i32 0
154   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
155   %3 = insertelement <4 x i8> %2, i8 2, i32 2
156   %4 = insertelement <4 x i8> %3, i8 -3, i32 3
157   %5 = zext <4 x i8> %4 to <4 x i16>
158   ret <4 x i16> %5
159 }
160 ; CHECK-LABEL: test11
161 ; CHECK: vmovaps
162 ; CHECK-NEXT: ret
163
164 define <4 x i32> @test12() {
165   %1 = insertelement <4 x i8> undef, i8 0, i32 0
166   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
167   %3 = insertelement <4 x i8> %2, i8 2, i32 2
168   %4 = insertelement <4 x i8> %3, i8 -3, i32 3
169   %5 = zext <4 x i8> %4 to <4 x i32>
170   ret <4 x i32> %5
171 }
172 ; CHECK-LABEL: test12
173 ; CHECK: vmovaps
174 ; CHECK-NEXT: ret
175
176 define <4 x i64> @test13() {
177   %1 = insertelement <4 x i8> undef, i8 0, i32 0
178   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
179   %3 = insertelement <4 x i8> %2, i8 2, i32 2
180   %4 = insertelement <4 x i8> %3, i8 -3, i32 3
181   %5 = zext <4 x i8> %4 to <4 x i64>
182   ret <4 x i64> %5
183 }
184 ; CHECK-LABEL: test13
185 ; CHECK-NOT: vinsertf128
186 ; CHECK: vmovaps
187 ; CHECK-NEXT: ret
188
189 define <4 x i16> @test14() {
190   %1 = insertelement <4 x i8> undef, i8 undef, i32 0
191   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
192   %3 = insertelement <4 x i8> %2, i8 undef, i32 2
193   %4 = insertelement <4 x i8> %3, i8 -3, i32 3
194   %5 = zext <4 x i8> %4 to <4 x i16>
195   ret <4 x i16> %5
196 }
197 ; CHECK-LABEL: test14
198 ; CHECK: vmovaps
199 ; CHECK-NEXT: ret
200
201 define <4 x i32> @test15() {
202   %1 = insertelement <4 x i8> undef, i8 0, i32 0
203   %2 = insertelement <4 x i8> %1, i8 undef, i32 1
204   %3 = insertelement <4 x i8> %2, i8 2, i32 2
205   %4 = insertelement <4 x i8> %3, i8 undef, i32 3
206   %5 = zext <4 x i8> %4 to <4 x i32>
207   ret <4 x i32> %5
208 }
209 ; CHECK-LABEL: test15
210 ; CHECK: vmovaps
211 ; CHECK-NEXT: ret
212
213 define <4 x i64> @test16() {
214   %1 = insertelement <4 x i8> undef, i8 undef, i32 0
215   %2 = insertelement <4 x i8> %1, i8 -1, i32 1
216   %3 = insertelement <4 x i8> %2, i8 2, i32 2
217   %4 = insertelement <4 x i8> %3, i8 undef, i32 3
218   %5 = zext <4 x i8> %4 to <4 x i64>
219   ret <4 x i64> %5
220 }
221 ; CHECK-LABEL: test16
222 ; CHECK-NOT: vinsertf128
223 ; CHECK: vmovaps
224 ; CHECK-NEXT: ret
225
226 define <8 x i16> @test17() {
227   %1 = insertelement <8 x i8> undef, i8 0, i32 0
228   %2 = insertelement <8 x i8> %1, i8 -1, i32 1
229   %3 = insertelement <8 x i8> %2, i8 2, i32 2
230   %4 = insertelement <8 x i8> %3, i8 -3, i32 3
231   %5 = insertelement <8 x i8> %4, i8 4, i32 4
232   %6 = insertelement <8 x i8> %5, i8 -5, i32 5
233   %7 = insertelement <8 x i8> %6, i8 6, i32 6
234   %8 = insertelement <8 x i8> %7, i8 -7, i32 7
235   %9 = zext <8 x i8> %8 to <8 x i16>
236   ret <8 x i16> %9
237 }
238 ; CHECK-LABEL: test17
239 ; CHECK: vmovaps
240 ; CHECK-NEXT: ret
241
242 define <8 x i32> @test18() {
243   %1 = insertelement <8 x i8> undef, i8 0, i32 0
244   %2 = insertelement <8 x i8> %1, i8 -1, i32 1
245   %3 = insertelement <8 x i8> %2, i8 2, i32 2
246   %4 = insertelement <8 x i8> %3, i8 -3, i32 3
247   %5 = insertelement <8 x i8> %4, i8 4, i32 4
248   %6 = insertelement <8 x i8> %5, i8 -5, i32 5
249   %7 = insertelement <8 x i8> %6, i8 6, i32 6
250   %8 = insertelement <8 x i8> %7, i8 -7, i32 7
251   %9 = zext <8 x i8> %8 to <8 x i32>
252   ret <8 x i32> %9
253 }
254 ; CHECK-LABEL: test18
255 ; CHECK-NOT: vinsertf128
256 ; CHECK: vmovaps
257 ; CHECK-NEXT: ret
258
259 define <8 x i16> @test19() {
260   %1 = insertelement <8 x i8> undef, i8 undef, i32 0
261   %2 = insertelement <8 x i8> %1, i8 -1, i32 1
262   %3 = insertelement <8 x i8> %2, i8 undef, i32 2
263   %4 = insertelement <8 x i8> %3, i8 -3, i32 3
264   %5 = insertelement <8 x i8> %4, i8 undef, i32 4
265   %6 = insertelement <8 x i8> %5, i8 -5, i32 5
266   %7 = insertelement <8 x i8> %6, i8 undef, i32 6
267   %8 = insertelement <8 x i8> %7, i8 -7, i32 7
268   %9 = zext <8 x i8> %8 to <8 x i16>
269   ret <8 x i16> %9
270 }
271 ; CHECK-LABEL: test19
272 ; CHECK: vmovaps
273 ; CHECK-NEXT: ret
274
275 define <8 x i32> @test20() {
276   %1 = insertelement <8 x i8> undef, i8 0, i32 0
277   %2 = insertelement <8 x i8> %1, i8 undef, i32 1
278   %3 = insertelement <8 x i8> %2, i8 2, i32 2
279   %4 = insertelement <8 x i8> %3, i8 -3, i32 3
280   %5 = insertelement <8 x i8> %4, i8 4, i32 4
281   %6 = insertelement <8 x i8> %5, i8 undef, i32 5
282   %7 = insertelement <8 x i8> %6, i8 6, i32 6
283   %8 = insertelement <8 x i8> %7, i8 undef, i32 7
284   %9 = zext <8 x i8> %8 to <8 x i32>
285   ret <8 x i32> %9
286 }
287 ; CHECK-LABEL: test20
288 ; CHECK-NOT: vinsertf128
289 ; CHECK: vmovaps
290 ; CHECK-NEXT: ret
291