1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -slp-vectorizer -slp-threshold=-10000 < %s | FileCheck %s
3 ; RUN: opt -S -slp-vectorizer -slp-threshold=0 < %s | FileCheck %s --check-prefix=ZEROTHRESH
4 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-n8:16:32:64-S128"
6 target triple = "x86_64-apple-macosx10.8.0"
8 define <4 x float> @simple_select(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
9 ; CHECK-LABEL: @simple_select(
10 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
11 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
12 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[TMP2]], i32 0
13 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[TMP3]], i32 0
14 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP2]], i32 1
15 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP4]], i32 1
16 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP2]], i32 2
17 ; CHECK-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[TMP5]], i32 2
18 ; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[TMP2]], i32 3
19 ; CHECK-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[TMP6]], i32 3
20 ; CHECK-NEXT: ret <4 x float> [[RD]]
22 ; ZEROTHRESH-LABEL: @simple_select(
23 ; ZEROTHRESH-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
24 ; ZEROTHRESH-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
25 ; ZEROTHRESH-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[TMP2]], i32 0
26 ; ZEROTHRESH-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[TMP3]], i32 0
27 ; ZEROTHRESH-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP2]], i32 1
28 ; ZEROTHRESH-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP4]], i32 1
29 ; ZEROTHRESH-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP2]], i32 2
30 ; ZEROTHRESH-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[TMP5]], i32 2
31 ; ZEROTHRESH-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[TMP2]], i32 3
32 ; ZEROTHRESH-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[TMP6]], i32 3
33 ; ZEROTHRESH-NEXT: ret <4 x float> [[RD]]
35 %c0 = extractelement <4 x i32> %c, i32 0
36 %c1 = extractelement <4 x i32> %c, i32 1
37 %c2 = extractelement <4 x i32> %c, i32 2
38 %c3 = extractelement <4 x i32> %c, i32 3
39 %a0 = extractelement <4 x float> %a, i32 0
40 %a1 = extractelement <4 x float> %a, i32 1
41 %a2 = extractelement <4 x float> %a, i32 2
42 %a3 = extractelement <4 x float> %a, i32 3
43 %b0 = extractelement <4 x float> %b, i32 0
44 %b1 = extractelement <4 x float> %b, i32 1
45 %b2 = extractelement <4 x float> %b, i32 2
46 %b3 = extractelement <4 x float> %b, i32 3
47 %cmp0 = icmp ne i32 %c0, 0
48 %cmp1 = icmp ne i32 %c1, 0
49 %cmp2 = icmp ne i32 %c2, 0
50 %cmp3 = icmp ne i32 %c3, 0
51 %s0 = select i1 %cmp0, float %a0, float %b0
52 %s1 = select i1 %cmp1, float %a1, float %b1
53 %s2 = select i1 %cmp2, float %a2, float %b2
54 %s3 = select i1 %cmp3, float %a3, float %b3
55 %ra = insertelement <4 x float> undef, float %s0, i32 0
56 %rb = insertelement <4 x float> %ra, float %s1, i32 1
57 %rc = insertelement <4 x float> %rb, float %s2, i32 2
58 %rd = insertelement <4 x float> %rc, float %s3, i32 3
62 declare void @llvm.assume(i1) nounwind
64 ; This entire tree is ephemeral, don't vectorize any of it.
65 define <4 x float> @simple_select_eph(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
66 ; CHECK-LABEL: @simple_select_eph(
67 ; CHECK-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
68 ; CHECK-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
69 ; CHECK-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
70 ; CHECK-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
71 ; CHECK-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
72 ; CHECK-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
73 ; CHECK-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2
74 ; CHECK-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3
75 ; CHECK-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
76 ; CHECK-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
77 ; CHECK-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2
78 ; CHECK-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3
79 ; CHECK-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0
80 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0
81 ; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0
82 ; CHECK-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0
83 ; CHECK-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]]
84 ; CHECK-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]]
85 ; CHECK-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]]
86 ; CHECK-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]]
87 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[S0]], i32 0
88 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1
89 ; CHECK-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2
90 ; CHECK-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3
91 ; CHECK-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0
92 ; CHECK-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1
93 ; CHECK-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2
94 ; CHECK-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3
95 ; CHECK-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]]
96 ; CHECK-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]]
97 ; CHECK-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]]
98 ; CHECK-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]]
99 ; CHECK-NEXT: call void @llvm.assume(i1 [[QI]])
100 ; CHECK-NEXT: ret <4 x float> undef
102 ; ZEROTHRESH-LABEL: @simple_select_eph(
103 ; ZEROTHRESH-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
104 ; ZEROTHRESH-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
105 ; ZEROTHRESH-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
106 ; ZEROTHRESH-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
107 ; ZEROTHRESH-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
108 ; ZEROTHRESH-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
109 ; ZEROTHRESH-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2
110 ; ZEROTHRESH-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3
111 ; ZEROTHRESH-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
112 ; ZEROTHRESH-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
113 ; ZEROTHRESH-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2
114 ; ZEROTHRESH-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3
115 ; ZEROTHRESH-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0
116 ; ZEROTHRESH-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0
117 ; ZEROTHRESH-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0
118 ; ZEROTHRESH-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0
119 ; ZEROTHRESH-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]]
120 ; ZEROTHRESH-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]]
121 ; ZEROTHRESH-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]]
122 ; ZEROTHRESH-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]]
123 ; ZEROTHRESH-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[S0]], i32 0
124 ; ZEROTHRESH-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1
125 ; ZEROTHRESH-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2
126 ; ZEROTHRESH-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3
127 ; ZEROTHRESH-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0
128 ; ZEROTHRESH-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1
129 ; ZEROTHRESH-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2
130 ; ZEROTHRESH-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3
131 ; ZEROTHRESH-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]]
132 ; ZEROTHRESH-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]]
133 ; ZEROTHRESH-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]]
134 ; ZEROTHRESH-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]]
135 ; ZEROTHRESH-NEXT: call void @llvm.assume(i1 [[QI]])
136 ; ZEROTHRESH-NEXT: ret <4 x float> undef
138 %c0 = extractelement <4 x i32> %c, i32 0
139 %c1 = extractelement <4 x i32> %c, i32 1
140 %c2 = extractelement <4 x i32> %c, i32 2
141 %c3 = extractelement <4 x i32> %c, i32 3
142 %a0 = extractelement <4 x float> %a, i32 0
143 %a1 = extractelement <4 x float> %a, i32 1
144 %a2 = extractelement <4 x float> %a, i32 2
145 %a3 = extractelement <4 x float> %a, i32 3
146 %b0 = extractelement <4 x float> %b, i32 0
147 %b1 = extractelement <4 x float> %b, i32 1
148 %b2 = extractelement <4 x float> %b, i32 2
149 %b3 = extractelement <4 x float> %b, i32 3
150 %cmp0 = icmp ne i32 %c0, 0
151 %cmp1 = icmp ne i32 %c1, 0
152 %cmp2 = icmp ne i32 %c2, 0
153 %cmp3 = icmp ne i32 %c3, 0
154 %s0 = select i1 %cmp0, float %a0, float %b0
155 %s1 = select i1 %cmp1, float %a1, float %b1
156 %s2 = select i1 %cmp2, float %a2, float %b2
157 %s3 = select i1 %cmp3, float %a3, float %b3
158 %ra = insertelement <4 x float> undef, float %s0, i32 0
159 %rb = insertelement <4 x float> %ra, float %s1, i32 1
160 %rc = insertelement <4 x float> %rb, float %s2, i32 2
161 %rd = insertelement <4 x float> %rc, float %s3, i32 3
162 %q0 = extractelement <4 x float> %rd, i32 0
163 %q1 = extractelement <4 x float> %rd, i32 1
164 %q2 = extractelement <4 x float> %rd, i32 2
165 %q3 = extractelement <4 x float> %rd, i32 3
166 %q4 = fadd float %q0, %q1
167 %q5 = fadd float %q2, %q3
168 %q6 = fadd float %q4, %q5
169 %qi = fcmp olt float %q6, %q5
170 call void @llvm.assume(i1 %qi)
171 ret <4 x float> undef
174 ; Insert in an order different from the vector indices to make sure it
176 define <4 x float> @simple_select_insert_out_of_order(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
177 ; CHECK-LABEL: @simple_select_insert_out_of_order(
178 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
179 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
180 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[TMP2]], i32 0
181 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[TMP3]], i32 2
182 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP2]], i32 1
183 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP4]], i32 1
184 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP2]], i32 2
185 ; CHECK-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[TMP5]], i32 0
186 ; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[TMP2]], i32 3
187 ; CHECK-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[TMP6]], i32 3
188 ; CHECK-NEXT: ret <4 x float> [[RD]]
190 ; ZEROTHRESH-LABEL: @simple_select_insert_out_of_order(
191 ; ZEROTHRESH-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
192 ; ZEROTHRESH-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
193 ; ZEROTHRESH-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[TMP2]], i32 0
194 ; ZEROTHRESH-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[TMP3]], i32 2
195 ; ZEROTHRESH-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP2]], i32 1
196 ; ZEROTHRESH-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP4]], i32 1
197 ; ZEROTHRESH-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP2]], i32 2
198 ; ZEROTHRESH-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[TMP5]], i32 0
199 ; ZEROTHRESH-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[TMP2]], i32 3
200 ; ZEROTHRESH-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[TMP6]], i32 3
201 ; ZEROTHRESH-NEXT: ret <4 x float> [[RD]]
203 %c0 = extractelement <4 x i32> %c, i32 0
204 %c1 = extractelement <4 x i32> %c, i32 1
205 %c2 = extractelement <4 x i32> %c, i32 2
206 %c3 = extractelement <4 x i32> %c, i32 3
207 %a0 = extractelement <4 x float> %a, i32 0
208 %a1 = extractelement <4 x float> %a, i32 1
209 %a2 = extractelement <4 x float> %a, i32 2
210 %a3 = extractelement <4 x float> %a, i32 3
211 %b0 = extractelement <4 x float> %b, i32 0
212 %b1 = extractelement <4 x float> %b, i32 1
213 %b2 = extractelement <4 x float> %b, i32 2
214 %b3 = extractelement <4 x float> %b, i32 3
215 %cmp0 = icmp ne i32 %c0, 0
216 %cmp1 = icmp ne i32 %c1, 0
217 %cmp2 = icmp ne i32 %c2, 0
218 %cmp3 = icmp ne i32 %c3, 0
219 %s0 = select i1 %cmp0, float %a0, float %b0
220 %s1 = select i1 %cmp1, float %a1, float %b1
221 %s2 = select i1 %cmp2, float %a2, float %b2
222 %s3 = select i1 %cmp3, float %a3, float %b3
223 %ra = insertelement <4 x float> undef, float %s0, i32 2
224 %rb = insertelement <4 x float> %ra, float %s1, i32 1
225 %rc = insertelement <4 x float> %rb, float %s2, i32 0
226 %rd = insertelement <4 x float> %rc, float %s3, i32 3
230 declare void @v4f32_user(<4 x float>) #0
231 declare void @f32_user(float) #0
233 ; Multiple users of the final constructed vector
234 define <4 x float> @simple_select_users(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
235 ; CHECK-LABEL: @simple_select_users(
236 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
237 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
238 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[TMP2]], i32 0
239 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[TMP3]], i32 0
240 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP2]], i32 1
241 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP4]], i32 1
242 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP2]], i32 2
243 ; CHECK-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[TMP5]], i32 2
244 ; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[TMP2]], i32 3
245 ; CHECK-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[TMP6]], i32 3
246 ; CHECK-NEXT: call void @v4f32_user(<4 x float> [[RD]]) #0
247 ; CHECK-NEXT: ret <4 x float> [[RD]]
249 ; ZEROTHRESH-LABEL: @simple_select_users(
250 ; ZEROTHRESH-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
251 ; ZEROTHRESH-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
252 ; ZEROTHRESH-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[TMP2]], i32 0
253 ; ZEROTHRESH-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[TMP3]], i32 0
254 ; ZEROTHRESH-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP2]], i32 1
255 ; ZEROTHRESH-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP4]], i32 1
256 ; ZEROTHRESH-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP2]], i32 2
257 ; ZEROTHRESH-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[TMP5]], i32 2
258 ; ZEROTHRESH-NEXT: [[TMP6:%.*]] = extractelement <4 x float> [[TMP2]], i32 3
259 ; ZEROTHRESH-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[TMP6]], i32 3
260 ; ZEROTHRESH-NEXT: call void @v4f32_user(<4 x float> [[RD]]) #0
261 ; ZEROTHRESH-NEXT: ret <4 x float> [[RD]]
263 %c0 = extractelement <4 x i32> %c, i32 0
264 %c1 = extractelement <4 x i32> %c, i32 1
265 %c2 = extractelement <4 x i32> %c, i32 2
266 %c3 = extractelement <4 x i32> %c, i32 3
267 %a0 = extractelement <4 x float> %a, i32 0
268 %a1 = extractelement <4 x float> %a, i32 1
269 %a2 = extractelement <4 x float> %a, i32 2
270 %a3 = extractelement <4 x float> %a, i32 3
271 %b0 = extractelement <4 x float> %b, i32 0
272 %b1 = extractelement <4 x float> %b, i32 1
273 %b2 = extractelement <4 x float> %b, i32 2
274 %b3 = extractelement <4 x float> %b, i32 3
275 %cmp0 = icmp ne i32 %c0, 0
276 %cmp1 = icmp ne i32 %c1, 0
277 %cmp2 = icmp ne i32 %c2, 0
278 %cmp3 = icmp ne i32 %c3, 0
279 %s0 = select i1 %cmp0, float %a0, float %b0
280 %s1 = select i1 %cmp1, float %a1, float %b1
281 %s2 = select i1 %cmp2, float %a2, float %b2
282 %s3 = select i1 %cmp3, float %a3, float %b3
283 %ra = insertelement <4 x float> undef, float %s0, i32 0
284 %rb = insertelement <4 x float> %ra, float %s1, i32 1
285 %rc = insertelement <4 x float> %rb, float %s2, i32 2
286 %rd = insertelement <4 x float> %rc, float %s3, i32 3
287 call void @v4f32_user(<4 x float> %rd) #0
291 ; Unused insertelement
292 define <4 x float> @simple_select_no_users(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
293 ; CHECK-LABEL: @simple_select_no_users(
294 ; CHECK-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
295 ; CHECK-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
296 ; CHECK-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
297 ; CHECK-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
298 ; CHECK-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
299 ; CHECK-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
300 ; CHECK-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2
301 ; CHECK-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3
302 ; CHECK-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
303 ; CHECK-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
304 ; CHECK-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2
305 ; CHECK-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3
306 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> undef, i32 [[C0]], i32 0
307 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x i32> [[TMP1]], i32 [[C1]], i32 1
308 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne <2 x i32> [[TMP2]], zeroinitializer
309 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x i32> undef, i32 [[C2]], i32 0
310 ; CHECK-NEXT: [[TMP5:%.*]] = insertelement <2 x i32> [[TMP4]], i32 [[C3]], i32 1
311 ; CHECK-NEXT: [[TMP6:%.*]] = icmp ne <2 x i32> [[TMP5]], zeroinitializer
312 ; CHECK-NEXT: [[TMP7:%.*]] = insertelement <2 x float> undef, float [[A0]], i32 0
313 ; CHECK-NEXT: [[TMP8:%.*]] = insertelement <2 x float> [[TMP7]], float [[A1]], i32 1
314 ; CHECK-NEXT: [[TMP9:%.*]] = insertelement <2 x float> undef, float [[B0]], i32 0
315 ; CHECK-NEXT: [[TMP10:%.*]] = insertelement <2 x float> [[TMP9]], float [[B1]], i32 1
316 ; CHECK-NEXT: [[TMP11:%.*]] = select <2 x i1> [[TMP3]], <2 x float> [[TMP8]], <2 x float> [[TMP10]]
317 ; CHECK-NEXT: [[TMP12:%.*]] = insertelement <2 x float> undef, float [[A2]], i32 0
318 ; CHECK-NEXT: [[TMP13:%.*]] = insertelement <2 x float> [[TMP12]], float [[A3]], i32 1
319 ; CHECK-NEXT: [[TMP14:%.*]] = insertelement <2 x float> undef, float [[B2]], i32 0
320 ; CHECK-NEXT: [[TMP15:%.*]] = insertelement <2 x float> [[TMP14]], float [[B3]], i32 1
321 ; CHECK-NEXT: [[TMP16:%.*]] = select <2 x i1> [[TMP6]], <2 x float> [[TMP13]], <2 x float> [[TMP15]]
322 ; CHECK-NEXT: [[TMP17:%.*]] = extractelement <2 x float> [[TMP11]], i32 0
323 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[TMP17]], i32 0
324 ; CHECK-NEXT: [[TMP18:%.*]] = extractelement <2 x float> [[TMP11]], i32 1
325 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP18]], i32 1
326 ; CHECK-NEXT: [[TMP19:%.*]] = extractelement <2 x float> [[TMP16]], i32 0
327 ; CHECK-NEXT: [[RC:%.*]] = insertelement <4 x float> undef, float [[TMP19]], i32 2
328 ; CHECK-NEXT: [[TMP20:%.*]] = extractelement <2 x float> [[TMP16]], i32 1
329 ; CHECK-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[TMP20]], i32 3
330 ; CHECK-NEXT: ret <4 x float> [[RD]]
332 ; ZEROTHRESH-LABEL: @simple_select_no_users(
333 ; ZEROTHRESH-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
334 ; ZEROTHRESH-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
335 ; ZEROTHRESH-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
336 ; ZEROTHRESH-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
337 ; ZEROTHRESH-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
338 ; ZEROTHRESH-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
339 ; ZEROTHRESH-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2
340 ; ZEROTHRESH-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3
341 ; ZEROTHRESH-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
342 ; ZEROTHRESH-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
343 ; ZEROTHRESH-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2
344 ; ZEROTHRESH-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3
345 ; ZEROTHRESH-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0
346 ; ZEROTHRESH-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0
347 ; ZEROTHRESH-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0
348 ; ZEROTHRESH-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0
349 ; ZEROTHRESH-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]]
350 ; ZEROTHRESH-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]]
351 ; ZEROTHRESH-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]]
352 ; ZEROTHRESH-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]]
353 ; ZEROTHRESH-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[S0]], i32 0
354 ; ZEROTHRESH-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1
355 ; ZEROTHRESH-NEXT: [[RC:%.*]] = insertelement <4 x float> undef, float [[S2]], i32 2
356 ; ZEROTHRESH-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3
357 ; ZEROTHRESH-NEXT: ret <4 x float> [[RD]]
359 %c0 = extractelement <4 x i32> %c, i32 0
360 %c1 = extractelement <4 x i32> %c, i32 1
361 %c2 = extractelement <4 x i32> %c, i32 2
362 %c3 = extractelement <4 x i32> %c, i32 3
363 %a0 = extractelement <4 x float> %a, i32 0
364 %a1 = extractelement <4 x float> %a, i32 1
365 %a2 = extractelement <4 x float> %a, i32 2
366 %a3 = extractelement <4 x float> %a, i32 3
367 %b0 = extractelement <4 x float> %b, i32 0
368 %b1 = extractelement <4 x float> %b, i32 1
369 %b2 = extractelement <4 x float> %b, i32 2
370 %b3 = extractelement <4 x float> %b, i32 3
371 %cmp0 = icmp ne i32 %c0, 0
372 %cmp1 = icmp ne i32 %c1, 0
373 %cmp2 = icmp ne i32 %c2, 0
374 %cmp3 = icmp ne i32 %c3, 0
375 %s0 = select i1 %cmp0, float %a0, float %b0
376 %s1 = select i1 %cmp1, float %a1, float %b1
377 %s2 = select i1 %cmp2, float %a2, float %b2
378 %s3 = select i1 %cmp3, float %a3, float %b3
379 %ra = insertelement <4 x float> undef, float %s0, i32 0
380 %rb = insertelement <4 x float> %ra, float %s1, i32 1
381 %rc = insertelement <4 x float> undef, float %s2, i32 2
382 %rd = insertelement <4 x float> %rc, float %s3, i32 3
386 ; Make sure infinite loop doesn't happen which I ran into when trying
387 ; to do this backwards this backwards
388 define <4 x i32> @reconstruct(<4 x i32> %c) #0 {
389 ; CHECK-LABEL: @reconstruct(
390 ; CHECK-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
391 ; CHECK-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
392 ; CHECK-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
393 ; CHECK-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
394 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x i32> undef, i32 [[C0]], i32 0
395 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x i32> [[RA]], i32 [[C1]], i32 1
396 ; CHECK-NEXT: [[RC:%.*]] = insertelement <4 x i32> [[RB]], i32 [[C2]], i32 2
397 ; CHECK-NEXT: [[RD:%.*]] = insertelement <4 x i32> [[RC]], i32 [[C3]], i32 3
398 ; CHECK-NEXT: ret <4 x i32> [[RD]]
400 ; ZEROTHRESH-LABEL: @reconstruct(
401 ; ZEROTHRESH-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
402 ; ZEROTHRESH-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
403 ; ZEROTHRESH-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
404 ; ZEROTHRESH-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
405 ; ZEROTHRESH-NEXT: [[RA:%.*]] = insertelement <4 x i32> undef, i32 [[C0]], i32 0
406 ; ZEROTHRESH-NEXT: [[RB:%.*]] = insertelement <4 x i32> [[RA]], i32 [[C1]], i32 1
407 ; ZEROTHRESH-NEXT: [[RC:%.*]] = insertelement <4 x i32> [[RB]], i32 [[C2]], i32 2
408 ; ZEROTHRESH-NEXT: [[RD:%.*]] = insertelement <4 x i32> [[RC]], i32 [[C3]], i32 3
409 ; ZEROTHRESH-NEXT: ret <4 x i32> [[RD]]
411 %c0 = extractelement <4 x i32> %c, i32 0
412 %c1 = extractelement <4 x i32> %c, i32 1
413 %c2 = extractelement <4 x i32> %c, i32 2
414 %c3 = extractelement <4 x i32> %c, i32 3
415 %ra = insertelement <4 x i32> undef, i32 %c0, i32 0
416 %rb = insertelement <4 x i32> %ra, i32 %c1, i32 1
417 %rc = insertelement <4 x i32> %rb, i32 %c2, i32 2
418 %rd = insertelement <4 x i32> %rc, i32 %c3, i32 3
422 define <2 x float> @simple_select_v2(<2 x float> %a, <2 x float> %b, <2 x i32> %c) #0 {
423 ; CHECK-LABEL: @simple_select_v2(
424 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <2 x i32> [[C:%.*]], zeroinitializer
425 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[TMP1]], <2 x float> [[A:%.*]], <2 x float> [[B:%.*]]
426 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <2 x float> [[TMP2]], i32 0
427 ; CHECK-NEXT: [[RA:%.*]] = insertelement <2 x float> undef, float [[TMP3]], i32 0
428 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x float> [[TMP2]], i32 1
429 ; CHECK-NEXT: [[RB:%.*]] = insertelement <2 x float> [[RA]], float [[TMP4]], i32 1
430 ; CHECK-NEXT: ret <2 x float> [[RB]]
432 ; ZEROTHRESH-LABEL: @simple_select_v2(
433 ; ZEROTHRESH-NEXT: [[C0:%.*]] = extractelement <2 x i32> [[C:%.*]], i32 0
434 ; ZEROTHRESH-NEXT: [[C1:%.*]] = extractelement <2 x i32> [[C]], i32 1
435 ; ZEROTHRESH-NEXT: [[A0:%.*]] = extractelement <2 x float> [[A:%.*]], i32 0
436 ; ZEROTHRESH-NEXT: [[A1:%.*]] = extractelement <2 x float> [[A]], i32 1
437 ; ZEROTHRESH-NEXT: [[B0:%.*]] = extractelement <2 x float> [[B:%.*]], i32 0
438 ; ZEROTHRESH-NEXT: [[B1:%.*]] = extractelement <2 x float> [[B]], i32 1
439 ; ZEROTHRESH-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0
440 ; ZEROTHRESH-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0
441 ; ZEROTHRESH-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]]
442 ; ZEROTHRESH-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]]
443 ; ZEROTHRESH-NEXT: [[RA:%.*]] = insertelement <2 x float> undef, float [[S0]], i32 0
444 ; ZEROTHRESH-NEXT: [[RB:%.*]] = insertelement <2 x float> [[RA]], float [[S1]], i32 1
445 ; ZEROTHRESH-NEXT: ret <2 x float> [[RB]]
447 %c0 = extractelement <2 x i32> %c, i32 0
448 %c1 = extractelement <2 x i32> %c, i32 1
449 %a0 = extractelement <2 x float> %a, i32 0
450 %a1 = extractelement <2 x float> %a, i32 1
451 %b0 = extractelement <2 x float> %b, i32 0
452 %b1 = extractelement <2 x float> %b, i32 1
453 %cmp0 = icmp ne i32 %c0, 0
454 %cmp1 = icmp ne i32 %c1, 0
455 %s0 = select i1 %cmp0, float %a0, float %b0
456 %s1 = select i1 %cmp1, float %a1, float %b1
457 %ra = insertelement <2 x float> undef, float %s0, i32 0
458 %rb = insertelement <2 x float> %ra, float %s1, i32 1
462 ; Make sure when we construct partial vectors, we don't keep
463 ; re-visiting the insertelement chains starting with undef
464 ; (low cost threshold needed to force this to happen)
465 define <4 x float> @simple_select_partial_vector(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
466 ; CHECK-LABEL: @simple_select_partial_vector(
467 ; CHECK-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
468 ; CHECK-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
469 ; CHECK-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
470 ; CHECK-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
471 ; CHECK-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
472 ; CHECK-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
473 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> undef, i32 [[C0]], i32 0
474 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x i32> [[TMP1]], i32 [[C1]], i32 1
475 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne <2 x i32> [[TMP2]], zeroinitializer
476 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x float> undef, float [[A0]], i32 0
477 ; CHECK-NEXT: [[TMP5:%.*]] = insertelement <2 x float> [[TMP4]], float [[A1]], i32 1
478 ; CHECK-NEXT: [[TMP6:%.*]] = insertelement <2 x float> undef, float [[B0]], i32 0
479 ; CHECK-NEXT: [[TMP7:%.*]] = insertelement <2 x float> [[TMP6]], float [[B1]], i32 1
480 ; CHECK-NEXT: [[TMP8:%.*]] = select <2 x i1> [[TMP3]], <2 x float> [[TMP5]], <2 x float> [[TMP7]]
481 ; CHECK-NEXT: [[TMP9:%.*]] = extractelement <2 x float> [[TMP8]], i32 0
482 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[TMP9]], i32 0
483 ; CHECK-NEXT: [[TMP10:%.*]] = extractelement <2 x float> [[TMP8]], i32 1
484 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP10]], i32 1
485 ; CHECK-NEXT: ret <4 x float> [[RB]]
487 ; ZEROTHRESH-LABEL: @simple_select_partial_vector(
488 ; ZEROTHRESH-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
489 ; ZEROTHRESH-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
490 ; ZEROTHRESH-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
491 ; ZEROTHRESH-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
492 ; ZEROTHRESH-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
493 ; ZEROTHRESH-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
494 ; ZEROTHRESH-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> undef, i32 [[C0]], i32 0
495 ; ZEROTHRESH-NEXT: [[TMP2:%.*]] = insertelement <2 x i32> [[TMP1]], i32 [[C1]], i32 1
496 ; ZEROTHRESH-NEXT: [[TMP3:%.*]] = icmp ne <2 x i32> [[TMP2]], zeroinitializer
497 ; ZEROTHRESH-NEXT: [[TMP4:%.*]] = insertelement <2 x float> undef, float [[A0]], i32 0
498 ; ZEROTHRESH-NEXT: [[TMP5:%.*]] = insertelement <2 x float> [[TMP4]], float [[A1]], i32 1
499 ; ZEROTHRESH-NEXT: [[TMP6:%.*]] = insertelement <2 x float> undef, float [[B0]], i32 0
500 ; ZEROTHRESH-NEXT: [[TMP7:%.*]] = insertelement <2 x float> [[TMP6]], float [[B1]], i32 1
501 ; ZEROTHRESH-NEXT: [[TMP8:%.*]] = select <2 x i1> [[TMP3]], <2 x float> [[TMP5]], <2 x float> [[TMP7]]
502 ; ZEROTHRESH-NEXT: [[TMP9:%.*]] = extractelement <2 x float> [[TMP8]], i32 0
503 ; ZEROTHRESH-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[TMP9]], i32 0
504 ; ZEROTHRESH-NEXT: [[TMP10:%.*]] = extractelement <2 x float> [[TMP8]], i32 1
505 ; ZEROTHRESH-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP10]], i32 1
506 ; ZEROTHRESH-NEXT: ret <4 x float> [[RB]]
508 %c0 = extractelement <4 x i32> %c, i32 0
509 %c1 = extractelement <4 x i32> %c, i32 1
510 %a0 = extractelement <4 x float> %a, i32 0
511 %a1 = extractelement <4 x float> %a, i32 1
512 %b0 = extractelement <4 x float> %b, i32 0
513 %b1 = extractelement <4 x float> %b, i32 1
514 %1 = insertelement <2 x i32> undef, i32 %c0, i32 0
515 %2 = insertelement <2 x i32> %1, i32 %c1, i32 1
516 %3 = icmp ne <2 x i32> %2, zeroinitializer
517 %4 = insertelement <2 x float> undef, float %a0, i32 0
518 %5 = insertelement <2 x float> %4, float %a1, i32 1
519 %6 = insertelement <2 x float> undef, float %b0, i32 0
520 %7 = insertelement <2 x float> %6, float %b1, i32 1
521 %8 = select <2 x i1> %3, <2 x float> %5, <2 x float> %7
522 %9 = extractelement <2 x float> %8, i32 0
523 %ra = insertelement <4 x float> undef, float %9, i32 0
524 %10 = extractelement <2 x float> %8, i32 1
525 %rb = insertelement <4 x float> %ra, float %10, i32 1
529 ; Make sure that vectorization happens even if insertelements operations
530 ; must be rescheduled. The case here is from compiling Julia.
531 define <4 x float> @reschedule_extract(<4 x float> %a, <4 x float> %b) {
532 ; CHECK-LABEL: @reschedule_extract(
533 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]]
534 ; CHECK-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[TMP1]], i32 0
535 ; CHECK-NEXT: [[V0:%.*]] = insertelement <4 x float> undef, float [[TMP2]], i32 0
536 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[TMP1]], i32 1
537 ; CHECK-NEXT: [[V1:%.*]] = insertelement <4 x float> [[V0]], float [[TMP3]], i32 1
538 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP1]], i32 2
539 ; CHECK-NEXT: [[V2:%.*]] = insertelement <4 x float> [[V1]], float [[TMP4]], i32 2
540 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP1]], i32 3
541 ; CHECK-NEXT: [[V3:%.*]] = insertelement <4 x float> [[V2]], float [[TMP5]], i32 3
542 ; CHECK-NEXT: ret <4 x float> [[V3]]
544 ; ZEROTHRESH-LABEL: @reschedule_extract(
545 ; ZEROTHRESH-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]]
546 ; ZEROTHRESH-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[TMP1]], i32 0
547 ; ZEROTHRESH-NEXT: [[V0:%.*]] = insertelement <4 x float> undef, float [[TMP2]], i32 0
548 ; ZEROTHRESH-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[TMP1]], i32 1
549 ; ZEROTHRESH-NEXT: [[V1:%.*]] = insertelement <4 x float> [[V0]], float [[TMP3]], i32 1
550 ; ZEROTHRESH-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP1]], i32 2
551 ; ZEROTHRESH-NEXT: [[V2:%.*]] = insertelement <4 x float> [[V1]], float [[TMP4]], i32 2
552 ; ZEROTHRESH-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP1]], i32 3
553 ; ZEROTHRESH-NEXT: [[V3:%.*]] = insertelement <4 x float> [[V2]], float [[TMP5]], i32 3
554 ; ZEROTHRESH-NEXT: ret <4 x float> [[V3]]
556 %a0 = extractelement <4 x float> %a, i32 0
557 %b0 = extractelement <4 x float> %b, i32 0
558 %c0 = fadd float %a0, %b0
559 %v0 = insertelement <4 x float> undef, float %c0, i32 0
560 %a1 = extractelement <4 x float> %a, i32 1
561 %b1 = extractelement <4 x float> %b, i32 1
562 %c1 = fadd float %a1, %b1
563 %v1 = insertelement <4 x float> %v0, float %c1, i32 1
564 %a2 = extractelement <4 x float> %a, i32 2
565 %b2 = extractelement <4 x float> %b, i32 2
566 %c2 = fadd float %a2, %b2
567 %v2 = insertelement <4 x float> %v1, float %c2, i32 2
568 %a3 = extractelement <4 x float> %a, i32 3
569 %b3 = extractelement <4 x float> %b, i32 3
570 %c3 = fadd float %a3, %b3
571 %v3 = insertelement <4 x float> %v2, float %c3, i32 3
575 ; Check that cost model for vectorization takes credit for
576 ; instructions that are erased.
577 define <4 x float> @take_credit(<4 x float> %a, <4 x float> %b) {
578 ; CHECK-LABEL: @take_credit(
579 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]]
580 ; CHECK-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[TMP1]], i32 0
581 ; CHECK-NEXT: [[V0:%.*]] = insertelement <4 x float> undef, float [[TMP2]], i32 0
582 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[TMP1]], i32 1
583 ; CHECK-NEXT: [[V1:%.*]] = insertelement <4 x float> [[V0]], float [[TMP3]], i32 1
584 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP1]], i32 2
585 ; CHECK-NEXT: [[V2:%.*]] = insertelement <4 x float> [[V1]], float [[TMP4]], i32 2
586 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP1]], i32 3
587 ; CHECK-NEXT: [[V3:%.*]] = insertelement <4 x float> [[V2]], float [[TMP5]], i32 3
588 ; CHECK-NEXT: ret <4 x float> [[V3]]
590 ; ZEROTHRESH-LABEL: @take_credit(
591 ; ZEROTHRESH-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]]
592 ; ZEROTHRESH-NEXT: [[TMP2:%.*]] = extractelement <4 x float> [[TMP1]], i32 0
593 ; ZEROTHRESH-NEXT: [[V0:%.*]] = insertelement <4 x float> undef, float [[TMP2]], i32 0
594 ; ZEROTHRESH-NEXT: [[TMP3:%.*]] = extractelement <4 x float> [[TMP1]], i32 1
595 ; ZEROTHRESH-NEXT: [[V1:%.*]] = insertelement <4 x float> [[V0]], float [[TMP3]], i32 1
596 ; ZEROTHRESH-NEXT: [[TMP4:%.*]] = extractelement <4 x float> [[TMP1]], i32 2
597 ; ZEROTHRESH-NEXT: [[V2:%.*]] = insertelement <4 x float> [[V1]], float [[TMP4]], i32 2
598 ; ZEROTHRESH-NEXT: [[TMP5:%.*]] = extractelement <4 x float> [[TMP1]], i32 3
599 ; ZEROTHRESH-NEXT: [[V3:%.*]] = insertelement <4 x float> [[V2]], float [[TMP5]], i32 3
600 ; ZEROTHRESH-NEXT: ret <4 x float> [[V3]]
602 %a0 = extractelement <4 x float> %a, i32 0
603 %b0 = extractelement <4 x float> %b, i32 0
604 %c0 = fadd float %a0, %b0
605 %a1 = extractelement <4 x float> %a, i32 1
606 %b1 = extractelement <4 x float> %b, i32 1
607 %c1 = fadd float %a1, %b1
608 %a2 = extractelement <4 x float> %a, i32 2
609 %b2 = extractelement <4 x float> %b, i32 2
610 %c2 = fadd float %a2, %b2
611 %a3 = extractelement <4 x float> %a, i32 3
612 %b3 = extractelement <4 x float> %b, i32 3
613 %c3 = fadd float %a3, %b3
614 %v0 = insertelement <4 x float> undef, float %c0, i32 0
615 %v1 = insertelement <4 x float> %v0, float %c1, i32 1
616 %v2 = insertelement <4 x float> %v1, float %c2, i32 2
617 %v3 = insertelement <4 x float> %v2, float %c3, i32 3
621 ; Make sure we handle multiple trees that feed one build vector correctly.
622 define <4 x double> @multi_tree(double %w, double %x, double %y, double %z) {
623 ; CHECK-LABEL: @multi_tree(
625 ; CHECK-NEXT: [[TMP0:%.*]] = insertelement <4 x double> undef, double [[W:%.*]], i32 0
626 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x double> [[TMP0]], double [[X:%.*]], i32 1
627 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x double> [[TMP1]], double [[Y:%.*]], i32 2
628 ; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x double> [[TMP2]], double [[Z:%.*]], i32 3
629 ; CHECK-NEXT: [[TMP4:%.*]] = fadd <4 x double> [[TMP3]], <double 0.000000e+00, double 1.000000e+00, double 2.000000e+00, double 3.000000e+00>
630 ; CHECK-NEXT: [[TMP5:%.*]] = fmul <4 x double> [[TMP4]], <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>
631 ; CHECK-NEXT: [[TMP6:%.*]] = extractelement <4 x double> [[TMP5]], i32 0
632 ; CHECK-NEXT: [[I1:%.*]] = insertelement <4 x double> undef, double [[TMP6]], i32 3
633 ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <4 x double> [[TMP5]], i32 1
634 ; CHECK-NEXT: [[I2:%.*]] = insertelement <4 x double> [[I1]], double [[TMP7]], i32 2
635 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <4 x double> [[TMP5]], i32 2
636 ; CHECK-NEXT: [[I3:%.*]] = insertelement <4 x double> [[I2]], double [[TMP8]], i32 1
637 ; CHECK-NEXT: [[TMP9:%.*]] = extractelement <4 x double> [[TMP5]], i32 3
638 ; CHECK-NEXT: [[I4:%.*]] = insertelement <4 x double> [[I3]], double [[TMP9]], i32 0
639 ; CHECK-NEXT: ret <4 x double> [[I4]]
641 ; ZEROTHRESH-LABEL: @multi_tree(
642 ; ZEROTHRESH-NEXT: entry:
643 ; ZEROTHRESH-NEXT: [[TMP0:%.*]] = insertelement <4 x double> undef, double [[W:%.*]], i32 0
644 ; ZEROTHRESH-NEXT: [[TMP1:%.*]] = insertelement <4 x double> [[TMP0]], double [[X:%.*]], i32 1
645 ; ZEROTHRESH-NEXT: [[TMP2:%.*]] = insertelement <4 x double> [[TMP1]], double [[Y:%.*]], i32 2
646 ; ZEROTHRESH-NEXT: [[TMP3:%.*]] = insertelement <4 x double> [[TMP2]], double [[Z:%.*]], i32 3
647 ; ZEROTHRESH-NEXT: [[TMP4:%.*]] = fadd <4 x double> [[TMP3]], <double 0.000000e+00, double 1.000000e+00, double 2.000000e+00, double 3.000000e+00>
648 ; ZEROTHRESH-NEXT: [[TMP5:%.*]] = fmul <4 x double> [[TMP4]], <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>
649 ; ZEROTHRESH-NEXT: [[TMP6:%.*]] = extractelement <4 x double> [[TMP5]], i32 0
650 ; ZEROTHRESH-NEXT: [[I1:%.*]] = insertelement <4 x double> undef, double [[TMP6]], i32 3
651 ; ZEROTHRESH-NEXT: [[TMP7:%.*]] = extractelement <4 x double> [[TMP5]], i32 1
652 ; ZEROTHRESH-NEXT: [[I2:%.*]] = insertelement <4 x double> [[I1]], double [[TMP7]], i32 2
653 ; ZEROTHRESH-NEXT: [[TMP8:%.*]] = extractelement <4 x double> [[TMP5]], i32 2
654 ; ZEROTHRESH-NEXT: [[I3:%.*]] = insertelement <4 x double> [[I2]], double [[TMP8]], i32 1
655 ; ZEROTHRESH-NEXT: [[TMP9:%.*]] = extractelement <4 x double> [[TMP5]], i32 3
656 ; ZEROTHRESH-NEXT: [[I4:%.*]] = insertelement <4 x double> [[I3]], double [[TMP9]], i32 0
657 ; ZEROTHRESH-NEXT: ret <4 x double> [[I4]]
660 %t0 = fadd double %w , 0.000000e+00
661 %t1 = fadd double %x , 1.000000e+00
662 %t2 = fadd double %y , 2.000000e+00
663 %t3 = fadd double %z , 3.000000e+00
664 %t4 = fmul double %t0, 1.000000e+00
665 %i1 = insertelement <4 x double> undef, double %t4, i32 3
666 %t5 = fmul double %t1, 1.000000e+00
667 %i2 = insertelement <4 x double> %i1, double %t5, i32 2
668 %t6 = fmul double %t2, 1.000000e+00
669 %i3 = insertelement <4 x double> %i2, double %t6, i32 1
670 %t7 = fmul double %t3, 1.000000e+00
671 %i4 = insertelement <4 x double> %i3, double %t7, i32 0
675 define <8 x float> @_vadd256(<8 x float> %a, <8 x float> %b) local_unnamed_addr #0 {
676 ; CHECK-LABEL: @_vadd256(
678 ; CHECK-NEXT: [[TMP0:%.*]] = fadd <8 x float> [[A:%.*]], [[B:%.*]]
679 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <8 x float> [[TMP0]], i32 0
680 ; CHECK-NEXT: [[VECINIT_I:%.*]] = insertelement <8 x float> undef, float [[TMP1]], i32 0
681 ; CHECK-NEXT: [[TMP2:%.*]] = extractelement <8 x float> [[TMP0]], i32 1
682 ; CHECK-NEXT: [[VECINIT1_I:%.*]] = insertelement <8 x float> [[VECINIT_I]], float [[TMP2]], i32 1
683 ; CHECK-NEXT: [[TMP3:%.*]] = extractelement <8 x float> [[TMP0]], i32 2
684 ; CHECK-NEXT: [[VECINIT2_I:%.*]] = insertelement <8 x float> [[VECINIT1_I]], float [[TMP3]], i32 2
685 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <8 x float> [[TMP0]], i32 3
686 ; CHECK-NEXT: [[VECINIT3_I:%.*]] = insertelement <8 x float> [[VECINIT2_I]], float [[TMP4]], i32 3
687 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <8 x float> [[TMP0]], i32 4
688 ; CHECK-NEXT: [[VECINIT4_I:%.*]] = insertelement <8 x float> [[VECINIT3_I]], float [[TMP5]], i32 4
689 ; CHECK-NEXT: [[TMP6:%.*]] = extractelement <8 x float> [[TMP0]], i32 5
690 ; CHECK-NEXT: [[VECINIT5_I:%.*]] = insertelement <8 x float> [[VECINIT4_I]], float [[TMP6]], i32 5
691 ; CHECK-NEXT: [[TMP7:%.*]] = extractelement <8 x float> [[TMP0]], i32 6
692 ; CHECK-NEXT: [[VECINIT6_I:%.*]] = insertelement <8 x float> [[VECINIT5_I]], float [[TMP7]], i32 6
693 ; CHECK-NEXT: [[TMP8:%.*]] = extractelement <8 x float> [[TMP0]], i32 7
694 ; CHECK-NEXT: [[VECINIT7_I:%.*]] = insertelement <8 x float> [[VECINIT6_I]], float [[TMP8]], i32 7
695 ; CHECK-NEXT: ret <8 x float> [[VECINIT7_I]]
697 ; ZEROTHRESH-LABEL: @_vadd256(
698 ; ZEROTHRESH-NEXT: entry:
699 ; ZEROTHRESH-NEXT: [[TMP0:%.*]] = fadd <8 x float> [[A:%.*]], [[B:%.*]]
700 ; ZEROTHRESH-NEXT: [[TMP1:%.*]] = extractelement <8 x float> [[TMP0]], i32 0
701 ; ZEROTHRESH-NEXT: [[VECINIT_I:%.*]] = insertelement <8 x float> undef, float [[TMP1]], i32 0
702 ; ZEROTHRESH-NEXT: [[TMP2:%.*]] = extractelement <8 x float> [[TMP0]], i32 1
703 ; ZEROTHRESH-NEXT: [[VECINIT1_I:%.*]] = insertelement <8 x float> [[VECINIT_I]], float [[TMP2]], i32 1
704 ; ZEROTHRESH-NEXT: [[TMP3:%.*]] = extractelement <8 x float> [[TMP0]], i32 2
705 ; ZEROTHRESH-NEXT: [[VECINIT2_I:%.*]] = insertelement <8 x float> [[VECINIT1_I]], float [[TMP3]], i32 2
706 ; ZEROTHRESH-NEXT: [[TMP4:%.*]] = extractelement <8 x float> [[TMP0]], i32 3
707 ; ZEROTHRESH-NEXT: [[VECINIT3_I:%.*]] = insertelement <8 x float> [[VECINIT2_I]], float [[TMP4]], i32 3
708 ; ZEROTHRESH-NEXT: [[TMP5:%.*]] = extractelement <8 x float> [[TMP0]], i32 4
709 ; ZEROTHRESH-NEXT: [[VECINIT4_I:%.*]] = insertelement <8 x float> [[VECINIT3_I]], float [[TMP5]], i32 4
710 ; ZEROTHRESH-NEXT: [[TMP6:%.*]] = extractelement <8 x float> [[TMP0]], i32 5
711 ; ZEROTHRESH-NEXT: [[VECINIT5_I:%.*]] = insertelement <8 x float> [[VECINIT4_I]], float [[TMP6]], i32 5
712 ; ZEROTHRESH-NEXT: [[TMP7:%.*]] = extractelement <8 x float> [[TMP0]], i32 6
713 ; ZEROTHRESH-NEXT: [[VECINIT6_I:%.*]] = insertelement <8 x float> [[VECINIT5_I]], float [[TMP7]], i32 6
714 ; ZEROTHRESH-NEXT: [[TMP8:%.*]] = extractelement <8 x float> [[TMP0]], i32 7
715 ; ZEROTHRESH-NEXT: [[VECINIT7_I:%.*]] = insertelement <8 x float> [[VECINIT6_I]], float [[TMP8]], i32 7
716 ; ZEROTHRESH-NEXT: ret <8 x float> [[VECINIT7_I]]
719 %vecext = extractelement <8 x float> %a, i32 0
720 %vecext1 = extractelement <8 x float> %b, i32 0
721 %add = fadd float %vecext, %vecext1
722 %vecext2 = extractelement <8 x float> %a, i32 1
723 %vecext3 = extractelement <8 x float> %b, i32 1
724 %add4 = fadd float %vecext2, %vecext3
725 %vecext5 = extractelement <8 x float> %a, i32 2
726 %vecext6 = extractelement <8 x float> %b, i32 2
727 %add7 = fadd float %vecext5, %vecext6
728 %vecext8 = extractelement <8 x float> %a, i32 3
729 %vecext9 = extractelement <8 x float> %b, i32 3
730 %add10 = fadd float %vecext8, %vecext9
731 %vecext11 = extractelement <8 x float> %a, i32 4
732 %vecext12 = extractelement <8 x float> %b, i32 4
733 %add13 = fadd float %vecext11, %vecext12
734 %vecext14 = extractelement <8 x float> %a, i32 5
735 %vecext15 = extractelement <8 x float> %b, i32 5
736 %add16 = fadd float %vecext14, %vecext15
737 %vecext17 = extractelement <8 x float> %a, i32 6
738 %vecext18 = extractelement <8 x float> %b, i32 6
739 %add19 = fadd float %vecext17, %vecext18
740 %vecext20 = extractelement <8 x float> %a, i32 7
741 %vecext21 = extractelement <8 x float> %b, i32 7
742 %add22 = fadd float %vecext20, %vecext21
743 %vecinit.i = insertelement <8 x float> undef, float %add, i32 0
744 %vecinit1.i = insertelement <8 x float> %vecinit.i, float %add4, i32 1
745 %vecinit2.i = insertelement <8 x float> %vecinit1.i, float %add7, i32 2
746 %vecinit3.i = insertelement <8 x float> %vecinit2.i, float %add10, i32 3
747 %vecinit4.i = insertelement <8 x float> %vecinit3.i, float %add13, i32 4
748 %vecinit5.i = insertelement <8 x float> %vecinit4.i, float %add16, i32 5
749 %vecinit6.i = insertelement <8 x float> %vecinit5.i, float %add19, i32 6
750 %vecinit7.i = insertelement <8 x float> %vecinit6.i, float %add22, i32 7
751 ret <8 x float> %vecinit7.i
754 attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"="true" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }