1 ; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -mcpu=corei7-avx -mattr=+avx | FileCheck %s
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.
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>
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>
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>
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>
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>
68 ; CHECK-NOT: vinsertf128
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>
81 ; CHECK-NOT: vinsertf128
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>
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>
114 ; CHECK-NOT: vinsertf128
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>
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>
146 ; CHECK-LABEL: test10
147 ; CHECK-NOT: vinsertf128
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>
160 ; CHECK-LABEL: test11
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>
172 ; CHECK-LABEL: test12
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>
184 ; CHECK-LABEL: test13
185 ; CHECK-NOT: vinsertf128
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>
197 ; CHECK-LABEL: test14
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>
209 ; CHECK-LABEL: test15
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>
221 ; CHECK-LABEL: test16
222 ; CHECK-NOT: vinsertf128
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>
238 ; CHECK-LABEL: test17
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>
254 ; CHECK-LABEL: test18
255 ; CHECK-NOT: vinsertf128
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>
271 ; CHECK-LABEL: test19
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>
287 ; CHECK-LABEL: test20
288 ; CHECK-NOT: vinsertf128