1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -S -passes=slp-vectorizer -slp-threshold=-10000 < %s | FileCheck %s --check-prefixes=CHECK,THRESHOLD
3 ; RUN: opt -S -passes=slp-vectorizer -slp-threshold=0 < %s | FileCheck %s --check-prefixes=CHECK,NOTHRESHOLD
4 ; RUN: opt -S -passes=slp-vectorizer -slp-threshold=-10000 -slp-min-tree-size=0 < %s | FileCheck %s --check-prefixes=CHECK,MINTREESIZE
6 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"
7 target triple = "x86_64-apple-macosx10.8.0"
9 define <4 x float> @simple_select(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
10 ; CHECK-LABEL: @simple_select(
11 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
12 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
13 ; CHECK-NEXT: ret <4 x float> [[TMP2]]
15 %c0 = extractelement <4 x i32> %c, i32 0
16 %c1 = extractelement <4 x i32> %c, i32 1
17 %c2 = extractelement <4 x i32> %c, i32 2
18 %c3 = extractelement <4 x i32> %c, i32 3
19 %a0 = extractelement <4 x float> %a, i32 0
20 %a1 = extractelement <4 x float> %a, i32 1
21 %a2 = extractelement <4 x float> %a, i32 2
22 %a3 = extractelement <4 x float> %a, i32 3
23 %b0 = extractelement <4 x float> %b, i32 0
24 %b1 = extractelement <4 x float> %b, i32 1
25 %b2 = extractelement <4 x float> %b, i32 2
26 %b3 = extractelement <4 x float> %b, i32 3
27 %cmp0 = icmp ne i32 %c0, 0
28 %cmp1 = icmp ne i32 %c1, 0
29 %cmp2 = icmp ne i32 %c2, 0
30 %cmp3 = icmp ne i32 %c3, 0
31 %s0 = select i1 %cmp0, float %a0, float %b0
32 %s1 = select i1 %cmp1, float %a1, float %b1
33 %s2 = select i1 %cmp2, float %a2, float %b2
34 %s3 = select i1 %cmp3, float %a3, float %b3
35 %ra = insertelement <4 x float> poison, float %s0, i32 0
36 %rb = insertelement <4 x float> %ra, float %s1, i32 1
37 %rc = insertelement <4 x float> %rb, float %s2, i32 2
38 %rd = insertelement <4 x float> %rc, float %s3, i32 3
42 declare void @llvm.assume(i1) nounwind
44 ; This entire tree is ephemeral, don't vectorize any of it.
45 define <4 x float> @simple_select_eph(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
46 ; THRESHOLD-LABEL: @simple_select_eph(
47 ; THRESHOLD-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
48 ; THRESHOLD-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
49 ; THRESHOLD-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
50 ; THRESHOLD-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
51 ; THRESHOLD-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
52 ; THRESHOLD-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
53 ; THRESHOLD-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2
54 ; THRESHOLD-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3
55 ; THRESHOLD-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
56 ; THRESHOLD-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
57 ; THRESHOLD-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2
58 ; THRESHOLD-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3
59 ; THRESHOLD-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0
60 ; THRESHOLD-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0
61 ; THRESHOLD-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0
62 ; THRESHOLD-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0
63 ; THRESHOLD-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]]
64 ; THRESHOLD-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]]
65 ; THRESHOLD-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]]
66 ; THRESHOLD-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]]
67 ; THRESHOLD-NEXT: [[RA:%.*]] = insertelement <4 x float> poison, float [[S0]], i32 0
68 ; THRESHOLD-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1
69 ; THRESHOLD-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2
70 ; THRESHOLD-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3
71 ; THRESHOLD-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0
72 ; THRESHOLD-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1
73 ; THRESHOLD-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2
74 ; THRESHOLD-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3
75 ; THRESHOLD-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]]
76 ; THRESHOLD-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]]
77 ; THRESHOLD-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]]
78 ; THRESHOLD-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]]
79 ; THRESHOLD-NEXT: call void @llvm.assume(i1 [[QI]])
80 ; THRESHOLD-NEXT: ret <4 x float> undef
82 ; NOTHRESHOLD-LABEL: @simple_select_eph(
83 ; NOTHRESHOLD-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
84 ; NOTHRESHOLD-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
85 ; NOTHRESHOLD-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
86 ; NOTHRESHOLD-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
87 ; NOTHRESHOLD-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
88 ; NOTHRESHOLD-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
89 ; NOTHRESHOLD-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2
90 ; NOTHRESHOLD-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3
91 ; NOTHRESHOLD-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
92 ; NOTHRESHOLD-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
93 ; NOTHRESHOLD-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2
94 ; NOTHRESHOLD-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3
95 ; NOTHRESHOLD-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0
96 ; NOTHRESHOLD-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0
97 ; NOTHRESHOLD-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0
98 ; NOTHRESHOLD-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0
99 ; NOTHRESHOLD-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]]
100 ; NOTHRESHOLD-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]]
101 ; NOTHRESHOLD-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]]
102 ; NOTHRESHOLD-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]]
103 ; NOTHRESHOLD-NEXT: [[RA:%.*]] = insertelement <4 x float> poison, float [[S0]], i32 0
104 ; NOTHRESHOLD-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1
105 ; NOTHRESHOLD-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2
106 ; NOTHRESHOLD-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3
107 ; NOTHRESHOLD-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0
108 ; NOTHRESHOLD-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1
109 ; NOTHRESHOLD-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2
110 ; NOTHRESHOLD-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3
111 ; NOTHRESHOLD-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]]
112 ; NOTHRESHOLD-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]]
113 ; NOTHRESHOLD-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]]
114 ; NOTHRESHOLD-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]]
115 ; NOTHRESHOLD-NEXT: call void @llvm.assume(i1 [[QI]])
116 ; NOTHRESHOLD-NEXT: ret <4 x float> undef
118 ; MINTREESIZE-LABEL: @simple_select_eph(
119 ; MINTREESIZE-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
120 ; MINTREESIZE-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
121 ; MINTREESIZE-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
122 ; MINTREESIZE-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
123 ; MINTREESIZE-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
124 ; MINTREESIZE-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
125 ; MINTREESIZE-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2
126 ; MINTREESIZE-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3
127 ; MINTREESIZE-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
128 ; MINTREESIZE-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
129 ; MINTREESIZE-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2
130 ; MINTREESIZE-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3
131 ; MINTREESIZE-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0
132 ; MINTREESIZE-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0
133 ; MINTREESIZE-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0
134 ; MINTREESIZE-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0
135 ; MINTREESIZE-NEXT: [[TMP1:%.*]] = insertelement <4 x i1> poison, i1 [[CMP3]], i32 0
136 ; MINTREESIZE-NEXT: [[TMP2:%.*]] = insertelement <4 x i1> [[TMP1]], i1 [[CMP2]], i32 1
137 ; MINTREESIZE-NEXT: [[TMP3:%.*]] = insertelement <4 x i1> [[TMP2]], i1 [[CMP1]], i32 2
138 ; MINTREESIZE-NEXT: [[TMP4:%.*]] = insertelement <4 x i1> [[TMP3]], i1 [[CMP0]], i32 3
139 ; MINTREESIZE-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]]
140 ; MINTREESIZE-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]]
141 ; MINTREESIZE-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]]
142 ; MINTREESIZE-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]]
143 ; MINTREESIZE-NEXT: [[RA:%.*]] = insertelement <4 x float> poison, float [[S0]], i32 0
144 ; MINTREESIZE-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1
145 ; MINTREESIZE-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2
146 ; MINTREESIZE-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3
147 ; MINTREESIZE-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0
148 ; MINTREESIZE-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1
149 ; MINTREESIZE-NEXT: [[TMP5:%.*]] = shufflevector <4 x float> [[RD]], <4 x float> poison, <2 x i32> <i32 0, i32 1>
150 ; MINTREESIZE-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2
151 ; MINTREESIZE-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3
152 ; MINTREESIZE-NEXT: [[TMP6:%.*]] = shufflevector <4 x float> [[RD]], <4 x float> poison, <2 x i32> <i32 2, i32 3>
153 ; MINTREESIZE-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]]
154 ; MINTREESIZE-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]]
155 ; MINTREESIZE-NEXT: [[TMP7:%.*]] = insertelement <2 x float> poison, float [[Q4]], i32 0
156 ; MINTREESIZE-NEXT: [[TMP8:%.*]] = insertelement <2 x float> [[TMP7]], float [[Q5]], i32 1
157 ; MINTREESIZE-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]]
158 ; MINTREESIZE-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]]
159 ; MINTREESIZE-NEXT: call void @llvm.assume(i1 [[QI]])
160 ; MINTREESIZE-NEXT: ret <4 x float> undef
162 %c0 = extractelement <4 x i32> %c, i32 0
163 %c1 = extractelement <4 x i32> %c, i32 1
164 %c2 = extractelement <4 x i32> %c, i32 2
165 %c3 = extractelement <4 x i32> %c, i32 3
166 %a0 = extractelement <4 x float> %a, i32 0
167 %a1 = extractelement <4 x float> %a, i32 1
168 %a2 = extractelement <4 x float> %a, i32 2
169 %a3 = extractelement <4 x float> %a, i32 3
170 %b0 = extractelement <4 x float> %b, i32 0
171 %b1 = extractelement <4 x float> %b, i32 1
172 %b2 = extractelement <4 x float> %b, i32 2
173 %b3 = extractelement <4 x float> %b, i32 3
174 %cmp0 = icmp ne i32 %c0, 0
175 %cmp1 = icmp ne i32 %c1, 0
176 %cmp2 = icmp ne i32 %c2, 0
177 %cmp3 = icmp ne i32 %c3, 0
178 %s0 = select i1 %cmp0, float %a0, float %b0
179 %s1 = select i1 %cmp1, float %a1, float %b1
180 %s2 = select i1 %cmp2, float %a2, float %b2
181 %s3 = select i1 %cmp3, float %a3, float %b3
182 %ra = insertelement <4 x float> poison, float %s0, i32 0
183 %rb = insertelement <4 x float> %ra, float %s1, i32 1
184 %rc = insertelement <4 x float> %rb, float %s2, i32 2
185 %rd = insertelement <4 x float> %rc, float %s3, i32 3
186 %q0 = extractelement <4 x float> %rd, i32 0
187 %q1 = extractelement <4 x float> %rd, i32 1
188 %q2 = extractelement <4 x float> %rd, i32 2
189 %q3 = extractelement <4 x float> %rd, i32 3
190 %q4 = fadd float %q0, %q1
191 %q5 = fadd float %q2, %q3
192 %q6 = fadd float %q4, %q5
193 %qi = fcmp olt float %q6, %q5
194 call void @llvm.assume(i1 %qi)
195 ret <4 x float> undef
198 ; Insert in an order different from the vector indices to make sure it
200 define <4 x float> @simple_select_insert_out_of_order(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
201 ; CHECK-LABEL: @simple_select_insert_out_of_order(
202 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
203 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
204 ; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x float> [[TMP2]], <4 x float> poison, <4 x i32> <i32 2, i32 1, i32 0, i32 3>
205 ; CHECK-NEXT: ret <4 x float> [[TMP3]]
207 %c0 = extractelement <4 x i32> %c, i32 0
208 %c1 = extractelement <4 x i32> %c, i32 1
209 %c2 = extractelement <4 x i32> %c, i32 2
210 %c3 = extractelement <4 x i32> %c, i32 3
211 %a0 = extractelement <4 x float> %a, i32 0
212 %a1 = extractelement <4 x float> %a, i32 1
213 %a2 = extractelement <4 x float> %a, i32 2
214 %a3 = extractelement <4 x float> %a, i32 3
215 %b0 = extractelement <4 x float> %b, i32 0
216 %b1 = extractelement <4 x float> %b, i32 1
217 %b2 = extractelement <4 x float> %b, i32 2
218 %b3 = extractelement <4 x float> %b, i32 3
219 %cmp0 = icmp ne i32 %c0, 0
220 %cmp1 = icmp ne i32 %c1, 0
221 %cmp2 = icmp ne i32 %c2, 0
222 %cmp3 = icmp ne i32 %c3, 0
223 %s0 = select i1 %cmp0, float %a0, float %b0
224 %s1 = select i1 %cmp1, float %a1, float %b1
225 %s2 = select i1 %cmp2, float %a2, float %b2
226 %s3 = select i1 %cmp3, float %a3, float %b3
227 %ra = insertelement <4 x float> poison, float %s0, i32 2
228 %rb = insertelement <4 x float> %ra, float %s1, i32 1
229 %rc = insertelement <4 x float> %rb, float %s2, i32 0
230 %rd = insertelement <4 x float> %rc, float %s3, i32 3
234 declare void @v4f32_user(<4 x float>) #0
235 declare void @f32_user(float) #0
237 ; Multiple users of the final constructed vector
238 define <4 x float> @simple_select_users(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
239 ; CHECK-LABEL: @simple_select_users(
240 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
241 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
242 ; CHECK-NEXT: call void @v4f32_user(<4 x float> [[TMP2]]) #[[ATTR0:[0-9]+]]
243 ; CHECK-NEXT: ret <4 x float> [[TMP2]]
245 %c0 = extractelement <4 x i32> %c, i32 0
246 %c1 = extractelement <4 x i32> %c, i32 1
247 %c2 = extractelement <4 x i32> %c, i32 2
248 %c3 = extractelement <4 x i32> %c, i32 3
249 %a0 = extractelement <4 x float> %a, i32 0
250 %a1 = extractelement <4 x float> %a, i32 1
251 %a2 = extractelement <4 x float> %a, i32 2
252 %a3 = extractelement <4 x float> %a, i32 3
253 %b0 = extractelement <4 x float> %b, i32 0
254 %b1 = extractelement <4 x float> %b, i32 1
255 %b2 = extractelement <4 x float> %b, i32 2
256 %b3 = extractelement <4 x float> %b, i32 3
257 %cmp0 = icmp ne i32 %c0, 0
258 %cmp1 = icmp ne i32 %c1, 0
259 %cmp2 = icmp ne i32 %c2, 0
260 %cmp3 = icmp ne i32 %c3, 0
261 %s0 = select i1 %cmp0, float %a0, float %b0
262 %s1 = select i1 %cmp1, float %a1, float %b1
263 %s2 = select i1 %cmp2, float %a2, float %b2
264 %s3 = select i1 %cmp3, float %a3, float %b3
265 %ra = insertelement <4 x float> poison, float %s0, i32 0
266 %rb = insertelement <4 x float> %ra, float %s1, i32 1
267 %rc = insertelement <4 x float> %rb, float %s2, i32 2
268 %rd = insertelement <4 x float> %rc, float %s3, i32 3
269 call void @v4f32_user(<4 x float> %rd) #0
273 ; Unused insertelement
274 define <4 x float> @simple_select_no_users(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
275 ; CHECK-LABEL: @simple_select_no_users(
276 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i32> [[C:%.*]], <4 x i32> poison, <2 x i32> <i32 0, i32 1>
277 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ne <2 x i32> [[TMP1]], zeroinitializer
278 ; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x float> [[A:%.*]], <4 x float> poison, <2 x i32> <i32 0, i32 1>
279 ; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x float> [[B:%.*]], <4 x float> poison, <2 x i32> <i32 0, i32 1>
280 ; CHECK-NEXT: [[TMP5:%.*]] = select <2 x i1> [[TMP2]], <2 x float> [[TMP3]], <2 x float> [[TMP4]]
281 ; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <4 x i32> [[C]], <4 x i32> poison, <2 x i32> <i32 2, i32 3>
282 ; CHECK-NEXT: [[TMP7:%.*]] = icmp ne <2 x i32> [[TMP6]], zeroinitializer
283 ; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <4 x float> [[A]], <4 x float> poison, <2 x i32> <i32 2, i32 3>
284 ; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <4 x float> [[B]], <4 x float> poison, <2 x i32> <i32 2, i32 3>
285 ; CHECK-NEXT: [[TMP10:%.*]] = select <2 x i1> [[TMP7]], <2 x float> [[TMP8]], <2 x float> [[TMP9]]
286 ; CHECK-NEXT: [[TMP11:%.*]] = shufflevector <2 x float> [[TMP5]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
287 ; CHECK-NEXT: [[TMP12:%.*]] = shufflevector <2 x float> [[TMP10]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
288 ; CHECK-NEXT: [[RD1:%.*]] = shufflevector <4 x float> [[TMP12]], <4 x float> poison, <4 x i32> <i32 poison, i32 poison, i32 0, i32 1>
289 ; CHECK-NEXT: ret <4 x float> [[RD1]]
291 %c0 = extractelement <4 x i32> %c, i32 0
292 %c1 = extractelement <4 x i32> %c, i32 1
293 %c2 = extractelement <4 x i32> %c, i32 2
294 %c3 = extractelement <4 x i32> %c, i32 3
295 %a0 = extractelement <4 x float> %a, i32 0
296 %a1 = extractelement <4 x float> %a, i32 1
297 %a2 = extractelement <4 x float> %a, i32 2
298 %a3 = extractelement <4 x float> %a, i32 3
299 %b0 = extractelement <4 x float> %b, i32 0
300 %b1 = extractelement <4 x float> %b, i32 1
301 %b2 = extractelement <4 x float> %b, i32 2
302 %b3 = extractelement <4 x float> %b, i32 3
303 %cmp0 = icmp ne i32 %c0, 0
304 %cmp1 = icmp ne i32 %c1, 0
305 %cmp2 = icmp ne i32 %c2, 0
306 %cmp3 = icmp ne i32 %c3, 0
307 %s0 = select i1 %cmp0, float %a0, float %b0
308 %s1 = select i1 %cmp1, float %a1, float %b1
309 %s2 = select i1 %cmp2, float %a2, float %b2
310 %s3 = select i1 %cmp3, float %a3, float %b3
311 %ra = insertelement <4 x float> poison, float %s0, i32 0
312 %rb = insertelement <4 x float> %ra, float %s1, i32 1
313 %rc = insertelement <4 x float> poison, float %s2, i32 2
314 %rd = insertelement <4 x float> %rc, float %s3, i32 3
318 ; Make sure infinite loop doesn't happen which I ran into when trying
319 ; to do this backwards this backwards
320 define <4 x i32> @reconstruct(<4 x i32> %c) #0 {
321 ; CHECK-LABEL: @reconstruct(
322 ; CHECK-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
323 ; CHECK-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
324 ; CHECK-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
325 ; CHECK-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
326 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x i32> poison, i32 [[C0]], i32 0
327 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x i32> [[RA]], i32 [[C1]], i32 1
328 ; CHECK-NEXT: [[RC:%.*]] = insertelement <4 x i32> [[RB]], i32 [[C2]], i32 2
329 ; CHECK-NEXT: [[RD:%.*]] = insertelement <4 x i32> [[RC]], i32 [[C3]], i32 3
330 ; CHECK-NEXT: ret <4 x i32> [[RD]]
332 %c0 = extractelement <4 x i32> %c, i32 0
333 %c1 = extractelement <4 x i32> %c, i32 1
334 %c2 = extractelement <4 x i32> %c, i32 2
335 %c3 = extractelement <4 x i32> %c, i32 3
336 %ra = insertelement <4 x i32> poison, i32 %c0, i32 0
337 %rb = insertelement <4 x i32> %ra, i32 %c1, i32 1
338 %rc = insertelement <4 x i32> %rb, i32 %c2, i32 2
339 %rd = insertelement <4 x i32> %rc, i32 %c3, i32 3
343 define <2 x float> @simple_select_v2(<2 x float> %a, <2 x float> %b, <2 x i32> %c) #0 {
344 ; CHECK-LABEL: @simple_select_v2(
345 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <2 x i32> [[C:%.*]], zeroinitializer
346 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[TMP1]], <2 x float> [[A:%.*]], <2 x float> [[B:%.*]]
347 ; CHECK-NEXT: ret <2 x float> [[TMP2]]
349 %c0 = extractelement <2 x i32> %c, i32 0
350 %c1 = extractelement <2 x i32> %c, i32 1
351 %a0 = extractelement <2 x float> %a, i32 0
352 %a1 = extractelement <2 x float> %a, i32 1
353 %b0 = extractelement <2 x float> %b, i32 0
354 %b1 = extractelement <2 x float> %b, i32 1
355 %cmp0 = icmp ne i32 %c0, 0
356 %cmp1 = icmp ne i32 %c1, 0
357 %s0 = select i1 %cmp0, float %a0, float %b0
358 %s1 = select i1 %cmp1, float %a1, float %b1
359 %ra = insertelement <2 x float> poison, float %s0, i32 0
360 %rb = insertelement <2 x float> %ra, float %s1, i32 1
364 ; Make sure when we construct partial vectors, we don't keep
365 ; re-visiting the insertelement chains starting with undef
366 ; (low cost threshold needed to force this to happen)
367 define <4 x float> @simple_select_partial_vector(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
368 ; CHECK-LABEL: @simple_select_partial_vector(
369 ; CHECK-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
370 ; CHECK-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
371 ; CHECK-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
372 ; CHECK-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
373 ; CHECK-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
374 ; CHECK-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
375 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> poison, i32 [[C0]], i32 0
376 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x i32> [[TMP1]], i32 [[C1]], i32 1
377 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne <2 x i32> [[TMP2]], zeroinitializer
378 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x float> poison, float [[A0]], i32 0
379 ; CHECK-NEXT: [[TMP5:%.*]] = insertelement <2 x float> [[TMP4]], float [[A1]], i32 1
380 ; CHECK-NEXT: [[TMP6:%.*]] = insertelement <2 x float> poison, float [[B0]], i32 0
381 ; CHECK-NEXT: [[TMP7:%.*]] = insertelement <2 x float> [[TMP6]], float [[B1]], i32 1
382 ; CHECK-NEXT: [[TMP8:%.*]] = select <2 x i1> [[TMP3]], <2 x float> [[TMP5]], <2 x float> [[TMP7]]
383 ; CHECK-NEXT: [[TMP9:%.*]] = extractelement <2 x float> [[TMP8]], i32 0
384 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x float> poison, float [[TMP9]], i32 0
385 ; CHECK-NEXT: [[TMP10:%.*]] = extractelement <2 x float> [[TMP8]], i32 1
386 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP10]], i32 1
387 ; CHECK-NEXT: ret <4 x float> [[RB]]
389 %c0 = extractelement <4 x i32> %c, i32 0
390 %c1 = extractelement <4 x i32> %c, i32 1
391 %a0 = extractelement <4 x float> %a, i32 0
392 %a1 = extractelement <4 x float> %a, i32 1
393 %b0 = extractelement <4 x float> %b, i32 0
394 %b1 = extractelement <4 x float> %b, i32 1
395 %1 = insertelement <2 x i32> poison, i32 %c0, i32 0
396 %2 = insertelement <2 x i32> %1, i32 %c1, i32 1
397 %3 = icmp ne <2 x i32> %2, zeroinitializer
398 %4 = insertelement <2 x float> poison, float %a0, i32 0
399 %5 = insertelement <2 x float> %4, float %a1, i32 1
400 %6 = insertelement <2 x float> poison, float %b0, i32 0
401 %7 = insertelement <2 x float> %6, float %b1, i32 1
402 %8 = select <2 x i1> %3, <2 x float> %5, <2 x float> %7
403 %9 = extractelement <2 x float> %8, i32 0
404 %ra = insertelement <4 x float> poison, float %9, i32 0
405 %10 = extractelement <2 x float> %8, i32 1
406 %rb = insertelement <4 x float> %ra, float %10, i32 1
410 ; Make sure that vectorization happens even if insertelements operations
411 ; must be rescheduled. The case here is from compiling Julia.
412 define <4 x float> @reschedule_extract(<4 x float> %a, <4 x float> %b) {
413 ; CHECK-LABEL: @reschedule_extract(
414 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]]
415 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
417 %a0 = extractelement <4 x float> %a, i32 0
418 %b0 = extractelement <4 x float> %b, i32 0
419 %c0 = fadd float %a0, %b0
420 %v0 = insertelement <4 x float> poison, float %c0, i32 0
421 %a1 = extractelement <4 x float> %a, i32 1
422 %b1 = extractelement <4 x float> %b, i32 1
423 %c1 = fadd float %a1, %b1
424 %v1 = insertelement <4 x float> %v0, float %c1, i32 1
425 %a2 = extractelement <4 x float> %a, i32 2
426 %b2 = extractelement <4 x float> %b, i32 2
427 %c2 = fadd float %a2, %b2
428 %v2 = insertelement <4 x float> %v1, float %c2, i32 2
429 %a3 = extractelement <4 x float> %a, i32 3
430 %b3 = extractelement <4 x float> %b, i32 3
431 %c3 = fadd float %a3, %b3
432 %v3 = insertelement <4 x float> %v2, float %c3, i32 3
436 ; Check that cost model for vectorization takes credit for
437 ; instructions that are erased.
438 define <4 x float> @take_credit(<4 x float> %a, <4 x float> %b) {
439 ; CHECK-LABEL: @take_credit(
440 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]]
441 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
443 %a0 = extractelement <4 x float> %a, i32 0
444 %b0 = extractelement <4 x float> %b, i32 0
445 %c0 = fadd float %a0, %b0
446 %a1 = extractelement <4 x float> %a, i32 1
447 %b1 = extractelement <4 x float> %b, i32 1
448 %c1 = fadd float %a1, %b1
449 %a2 = extractelement <4 x float> %a, i32 2
450 %b2 = extractelement <4 x float> %b, i32 2
451 %c2 = fadd float %a2, %b2
452 %a3 = extractelement <4 x float> %a, i32 3
453 %b3 = extractelement <4 x float> %b, i32 3
454 %c3 = fadd float %a3, %b3
455 %v0 = insertelement <4 x float> poison, float %c0, i32 0
456 %v1 = insertelement <4 x float> %v0, float %c1, i32 1
457 %v2 = insertelement <4 x float> %v1, float %c2, i32 2
458 %v3 = insertelement <4 x float> %v2, float %c3, i32 3
462 ; Make sure we handle multiple trees that feed one build vector correctly.
463 define <4 x double> @multi_tree(double %w, double %x, double %y, double %z) {
464 ; CHECK-LABEL: @multi_tree(
465 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x double> poison, double [[Z:%.*]], i32 0
466 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x double> [[TMP1]], double [[Y:%.*]], i32 1
467 ; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x double> [[TMP2]], double [[X:%.*]], i32 2
468 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <4 x double> [[TMP3]], double [[W:%.*]], i32 3
469 ; CHECK-NEXT: [[TMP5:%.*]] = fadd <4 x double> [[TMP4]], <double 3.000000e+00, double 2.000000e+00, double 1.000000e+00, double 0.000000e+00>
470 ; CHECK-NEXT: [[TMP6:%.*]] = fmul <4 x double> [[TMP5]], <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>
471 ; CHECK-NEXT: ret <4 x double> [[TMP6]]
473 %t0 = fadd double %w , 0.000000e+00
474 %t1 = fadd double %x , 1.000000e+00
475 %t2 = fadd double %y , 2.000000e+00
476 %t3 = fadd double %z , 3.000000e+00
477 %t4 = fmul double %t0, 1.000000e+00
478 %i1 = insertelement <4 x double> poison, double %t4, i32 3
479 %t5 = fmul double %t1, 1.000000e+00
480 %i2 = insertelement <4 x double> %i1, double %t5, i32 2
481 %t6 = fmul double %t2, 1.000000e+00
482 %i3 = insertelement <4 x double> %i2, double %t6, i32 1
483 %t7 = fmul double %t3, 1.000000e+00
484 %i4 = insertelement <4 x double> %i3, double %t7, i32 0
488 define <8 x float> @_vadd256(<8 x float> %a, <8 x float> %b) local_unnamed_addr #0 {
489 ; CHECK-LABEL: @_vadd256(
490 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <8 x float> [[A:%.*]], [[B:%.*]]
491 ; CHECK-NEXT: ret <8 x float> [[TMP1]]
493 %vecext = extractelement <8 x float> %a, i32 0
494 %vecext1 = extractelement <8 x float> %b, i32 0
495 %add = fadd float %vecext, %vecext1
496 %vecext2 = extractelement <8 x float> %a, i32 1
497 %vecext3 = extractelement <8 x float> %b, i32 1
498 %add4 = fadd float %vecext2, %vecext3
499 %vecext5 = extractelement <8 x float> %a, i32 2
500 %vecext6 = extractelement <8 x float> %b, i32 2
501 %add7 = fadd float %vecext5, %vecext6
502 %vecext8 = extractelement <8 x float> %a, i32 3
503 %vecext9 = extractelement <8 x float> %b, i32 3
504 %add10 = fadd float %vecext8, %vecext9
505 %vecext11 = extractelement <8 x float> %a, i32 4
506 %vecext12 = extractelement <8 x float> %b, i32 4
507 %add13 = fadd float %vecext11, %vecext12
508 %vecext14 = extractelement <8 x float> %a, i32 5
509 %vecext15 = extractelement <8 x float> %b, i32 5
510 %add16 = fadd float %vecext14, %vecext15
511 %vecext17 = extractelement <8 x float> %a, i32 6
512 %vecext18 = extractelement <8 x float> %b, i32 6
513 %add19 = fadd float %vecext17, %vecext18
514 %vecext20 = extractelement <8 x float> %a, i32 7
515 %vecext21 = extractelement <8 x float> %b, i32 7
516 %add22 = fadd float %vecext20, %vecext21
517 %vecinit.i = insertelement <8 x float> poison, float %add, i32 0
518 %vecinit1.i = insertelement <8 x float> %vecinit.i, float %add4, i32 1
519 %vecinit2.i = insertelement <8 x float> %vecinit1.i, float %add7, i32 2
520 %vecinit3.i = insertelement <8 x float> %vecinit2.i, float %add10, i32 3
521 %vecinit4.i = insertelement <8 x float> %vecinit3.i, float %add13, i32 4
522 %vecinit5.i = insertelement <8 x float> %vecinit4.i, float %add16, i32 5
523 %vecinit6.i = insertelement <8 x float> %vecinit5.i, float %add19, i32 6
524 %vecinit7.i = insertelement <8 x float> %vecinit6.i, float %add22, i32 7
525 ret <8 x float> %vecinit7.i
528 attributes #0 = { nounwind ssp uwtable "less-precise-fpmad"="false" "frame-pointer"="all" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft-float"="false" }