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> undef, 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 define <8 x float> @simple_select2(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
43 ; CHECK-LABEL: @simple_select2(
44 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
45 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
46 ; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x float> [[TMP2]], <4 x float> undef, <8 x i32> <i32 0, i32 4, i32 1, i32 5, i32 2, i32 6, i32 7, i32 3>
47 ; CHECK-NEXT: ret <8 x float> [[TMP3]]
49 %c0 = extractelement <4 x i32> %c, i32 0
50 %c1 = extractelement <4 x i32> %c, i32 1
51 %c2 = extractelement <4 x i32> %c, i32 2
52 %c3 = extractelement <4 x i32> %c, i32 3
53 %a0 = extractelement <4 x float> %a, i32 0
54 %a1 = extractelement <4 x float> %a, i32 1
55 %a2 = extractelement <4 x float> %a, i32 2
56 %a3 = extractelement <4 x float> %a, i32 3
57 %b0 = extractelement <4 x float> %b, i32 0
58 %b1 = extractelement <4 x float> %b, i32 1
59 %b2 = extractelement <4 x float> %b, i32 2
60 %b3 = extractelement <4 x float> %b, i32 3
61 %cmp0 = icmp ne i32 %c0, 0
62 %cmp1 = icmp ne i32 %c1, 0
63 %cmp2 = icmp ne i32 %c2, 0
64 %cmp3 = icmp ne i32 %c3, 0
65 %s0 = select i1 %cmp0, float %a0, float %b0
66 %s1 = select i1 %cmp1, float %a1, float %b1
67 %s2 = select i1 %cmp2, float %a2, float %b2
68 %s3 = select i1 %cmp3, float %a3, float %b3
69 %ra = insertelement <8 x float> undef, float %s0, i32 0
70 %rb = insertelement <8 x float> %ra, float %s1, i32 2
71 %rc = insertelement <8 x float> %rb, float %s2, i32 4
72 %rd = insertelement <8 x float> %rc, float %s3, i32 7
76 declare void @llvm.assume(i1) nounwind
78 ; This entire tree is ephemeral, don't vectorize any of it.
79 define <4 x float> @simple_select_eph(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
80 ; THRESHOLD-LABEL: @simple_select_eph(
81 ; THRESHOLD-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
82 ; THRESHOLD-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
83 ; THRESHOLD-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
84 ; THRESHOLD-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
85 ; THRESHOLD-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
86 ; THRESHOLD-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
87 ; THRESHOLD-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2
88 ; THRESHOLD-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3
89 ; THRESHOLD-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
90 ; THRESHOLD-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
91 ; THRESHOLD-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2
92 ; THRESHOLD-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3
93 ; THRESHOLD-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0
94 ; THRESHOLD-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0
95 ; THRESHOLD-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0
96 ; THRESHOLD-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0
97 ; THRESHOLD-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]]
98 ; THRESHOLD-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]]
99 ; THRESHOLD-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]]
100 ; THRESHOLD-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]]
101 ; THRESHOLD-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[S0]], i32 0
102 ; THRESHOLD-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1
103 ; THRESHOLD-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2
104 ; THRESHOLD-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3
105 ; THRESHOLD-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0
106 ; THRESHOLD-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1
107 ; THRESHOLD-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2
108 ; THRESHOLD-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3
109 ; THRESHOLD-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]]
110 ; THRESHOLD-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]]
111 ; THRESHOLD-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]]
112 ; THRESHOLD-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]]
113 ; THRESHOLD-NEXT: call void @llvm.assume(i1 [[QI]])
114 ; THRESHOLD-NEXT: ret <4 x float> undef
116 ; NOTHRESHOLD-LABEL: @simple_select_eph(
117 ; NOTHRESHOLD-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
118 ; NOTHRESHOLD-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
119 ; NOTHRESHOLD-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
120 ; NOTHRESHOLD-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
121 ; NOTHRESHOLD-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
122 ; NOTHRESHOLD-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
123 ; NOTHRESHOLD-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2
124 ; NOTHRESHOLD-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3
125 ; NOTHRESHOLD-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
126 ; NOTHRESHOLD-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
127 ; NOTHRESHOLD-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2
128 ; NOTHRESHOLD-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3
129 ; NOTHRESHOLD-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0
130 ; NOTHRESHOLD-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0
131 ; NOTHRESHOLD-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0
132 ; NOTHRESHOLD-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0
133 ; NOTHRESHOLD-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]]
134 ; NOTHRESHOLD-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]]
135 ; NOTHRESHOLD-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]]
136 ; NOTHRESHOLD-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]]
137 ; NOTHRESHOLD-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[S0]], i32 0
138 ; NOTHRESHOLD-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1
139 ; NOTHRESHOLD-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2
140 ; NOTHRESHOLD-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3
141 ; NOTHRESHOLD-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0
142 ; NOTHRESHOLD-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1
143 ; NOTHRESHOLD-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2
144 ; NOTHRESHOLD-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3
145 ; NOTHRESHOLD-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]]
146 ; NOTHRESHOLD-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]]
147 ; NOTHRESHOLD-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]]
148 ; NOTHRESHOLD-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]]
149 ; NOTHRESHOLD-NEXT: call void @llvm.assume(i1 [[QI]])
150 ; NOTHRESHOLD-NEXT: ret <4 x float> undef
152 ; MINTREESIZE-LABEL: @simple_select_eph(
153 ; MINTREESIZE-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
154 ; MINTREESIZE-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
155 ; MINTREESIZE-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
156 ; MINTREESIZE-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
157 ; MINTREESIZE-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
158 ; MINTREESIZE-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
159 ; MINTREESIZE-NEXT: [[A2:%.*]] = extractelement <4 x float> [[A]], i32 2
160 ; MINTREESIZE-NEXT: [[A3:%.*]] = extractelement <4 x float> [[A]], i32 3
161 ; MINTREESIZE-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
162 ; MINTREESIZE-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
163 ; MINTREESIZE-NEXT: [[B2:%.*]] = extractelement <4 x float> [[B]], i32 2
164 ; MINTREESIZE-NEXT: [[B3:%.*]] = extractelement <4 x float> [[B]], i32 3
165 ; MINTREESIZE-NEXT: [[CMP0:%.*]] = icmp ne i32 [[C0]], 0
166 ; MINTREESIZE-NEXT: [[CMP1:%.*]] = icmp ne i32 [[C1]], 0
167 ; MINTREESIZE-NEXT: [[CMP2:%.*]] = icmp ne i32 [[C2]], 0
168 ; MINTREESIZE-NEXT: [[CMP3:%.*]] = icmp ne i32 [[C3]], 0
169 ; MINTREESIZE-NEXT: [[TMP1:%.*]] = insertelement <4 x i1> poison, i1 [[CMP3]], i32 0
170 ; MINTREESIZE-NEXT: [[TMP2:%.*]] = insertelement <4 x i1> [[TMP1]], i1 [[CMP2]], i32 1
171 ; MINTREESIZE-NEXT: [[TMP3:%.*]] = insertelement <4 x i1> [[TMP2]], i1 [[CMP1]], i32 2
172 ; MINTREESIZE-NEXT: [[TMP4:%.*]] = insertelement <4 x i1> [[TMP3]], i1 [[CMP0]], i32 3
173 ; MINTREESIZE-NEXT: [[S0:%.*]] = select i1 [[CMP0]], float [[A0]], float [[B0]]
174 ; MINTREESIZE-NEXT: [[S1:%.*]] = select i1 [[CMP1]], float [[A1]], float [[B1]]
175 ; MINTREESIZE-NEXT: [[S2:%.*]] = select i1 [[CMP2]], float [[A2]], float [[B2]]
176 ; MINTREESIZE-NEXT: [[S3:%.*]] = select i1 [[CMP3]], float [[A3]], float [[B3]]
177 ; MINTREESIZE-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[S0]], i32 0
178 ; MINTREESIZE-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[S1]], i32 1
179 ; MINTREESIZE-NEXT: [[RC:%.*]] = insertelement <4 x float> [[RB]], float [[S2]], i32 2
180 ; MINTREESIZE-NEXT: [[RD:%.*]] = insertelement <4 x float> [[RC]], float [[S3]], i32 3
181 ; MINTREESIZE-NEXT: [[Q0:%.*]] = extractelement <4 x float> [[RD]], i32 0
182 ; MINTREESIZE-NEXT: [[Q1:%.*]] = extractelement <4 x float> [[RD]], i32 1
183 ; MINTREESIZE-NEXT: [[TMP5:%.*]] = shufflevector <4 x float> [[RD]], <4 x float> poison, <2 x i32> <i32 0, i32 1>
184 ; MINTREESIZE-NEXT: [[Q2:%.*]] = extractelement <4 x float> [[RD]], i32 2
185 ; MINTREESIZE-NEXT: [[Q3:%.*]] = extractelement <4 x float> [[RD]], i32 3
186 ; MINTREESIZE-NEXT: [[TMP6:%.*]] = shufflevector <4 x float> [[RD]], <4 x float> poison, <2 x i32> <i32 2, i32 3>
187 ; MINTREESIZE-NEXT: [[Q4:%.*]] = fadd float [[Q0]], [[Q1]]
188 ; MINTREESIZE-NEXT: [[Q5:%.*]] = fadd float [[Q2]], [[Q3]]
189 ; MINTREESIZE-NEXT: [[TMP7:%.*]] = insertelement <2 x float> poison, float [[Q4]], i32 0
190 ; MINTREESIZE-NEXT: [[TMP8:%.*]] = insertelement <2 x float> [[TMP7]], float [[Q5]], i32 1
191 ; MINTREESIZE-NEXT: [[Q6:%.*]] = fadd float [[Q4]], [[Q5]]
192 ; MINTREESIZE-NEXT: [[QI:%.*]] = fcmp olt float [[Q6]], [[Q5]]
193 ; MINTREESIZE-NEXT: call void @llvm.assume(i1 [[QI]])
194 ; MINTREESIZE-NEXT: ret <4 x float> undef
196 %c0 = extractelement <4 x i32> %c, i32 0
197 %c1 = extractelement <4 x i32> %c, i32 1
198 %c2 = extractelement <4 x i32> %c, i32 2
199 %c3 = extractelement <4 x i32> %c, i32 3
200 %a0 = extractelement <4 x float> %a, i32 0
201 %a1 = extractelement <4 x float> %a, i32 1
202 %a2 = extractelement <4 x float> %a, i32 2
203 %a3 = extractelement <4 x float> %a, i32 3
204 %b0 = extractelement <4 x float> %b, i32 0
205 %b1 = extractelement <4 x float> %b, i32 1
206 %b2 = extractelement <4 x float> %b, i32 2
207 %b3 = extractelement <4 x float> %b, i32 3
208 %cmp0 = icmp ne i32 %c0, 0
209 %cmp1 = icmp ne i32 %c1, 0
210 %cmp2 = icmp ne i32 %c2, 0
211 %cmp3 = icmp ne i32 %c3, 0
212 %s0 = select i1 %cmp0, float %a0, float %b0
213 %s1 = select i1 %cmp1, float %a1, float %b1
214 %s2 = select i1 %cmp2, float %a2, float %b2
215 %s3 = select i1 %cmp3, float %a3, float %b3
216 %ra = insertelement <4 x float> undef, float %s0, i32 0
217 %rb = insertelement <4 x float> %ra, float %s1, i32 1
218 %rc = insertelement <4 x float> %rb, float %s2, i32 2
219 %rd = insertelement <4 x float> %rc, float %s3, i32 3
220 %q0 = extractelement <4 x float> %rd, i32 0
221 %q1 = extractelement <4 x float> %rd, i32 1
222 %q2 = extractelement <4 x float> %rd, i32 2
223 %q3 = extractelement <4 x float> %rd, i32 3
224 %q4 = fadd float %q0, %q1
225 %q5 = fadd float %q2, %q3
226 %q6 = fadd float %q4, %q5
227 %qi = fcmp olt float %q6, %q5
228 call void @llvm.assume(i1 %qi)
229 ret <4 x float> undef
232 ; Insert in an order different from the vector indices to make sure it
234 define <4 x float> @simple_select_insert_out_of_order(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
235 ; CHECK-LABEL: @simple_select_insert_out_of_order(
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:%.*]] = shufflevector <4 x float> [[TMP2]], <4 x float> poison, <4 x i32> <i32 2, i32 1, i32 0, i32 3>
239 ; CHECK-NEXT: ret <4 x float> [[TMP3]]
241 %c0 = extractelement <4 x i32> %c, i32 0
242 %c1 = extractelement <4 x i32> %c, i32 1
243 %c2 = extractelement <4 x i32> %c, i32 2
244 %c3 = extractelement <4 x i32> %c, i32 3
245 %a0 = extractelement <4 x float> %a, i32 0
246 %a1 = extractelement <4 x float> %a, i32 1
247 %a2 = extractelement <4 x float> %a, i32 2
248 %a3 = extractelement <4 x float> %a, i32 3
249 %b0 = extractelement <4 x float> %b, i32 0
250 %b1 = extractelement <4 x float> %b, i32 1
251 %b2 = extractelement <4 x float> %b, i32 2
252 %b3 = extractelement <4 x float> %b, i32 3
253 %cmp0 = icmp ne i32 %c0, 0
254 %cmp1 = icmp ne i32 %c1, 0
255 %cmp2 = icmp ne i32 %c2, 0
256 %cmp3 = icmp ne i32 %c3, 0
257 %s0 = select i1 %cmp0, float %a0, float %b0
258 %s1 = select i1 %cmp1, float %a1, float %b1
259 %s2 = select i1 %cmp2, float %a2, float %b2
260 %s3 = select i1 %cmp3, float %a3, float %b3
261 %ra = insertelement <4 x float> undef, float %s0, i32 2
262 %rb = insertelement <4 x float> %ra, float %s1, i32 1
263 %rc = insertelement <4 x float> %rb, float %s2, i32 0
264 %rd = insertelement <4 x float> %rc, float %s3, i32 3
268 declare void @v4f32_user(<4 x float>) #0
269 declare void @f32_user(float) #0
271 ; Multiple users of the final constructed vector
272 define <4 x float> @simple_select_users(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
273 ; CHECK-LABEL: @simple_select_users(
274 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <4 x i32> [[C:%.*]], zeroinitializer
275 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x float> [[A:%.*]], <4 x float> [[B:%.*]]
276 ; CHECK-NEXT: call void @v4f32_user(<4 x float> [[TMP2]]) #[[ATTR0:[0-9]+]]
277 ; CHECK-NEXT: ret <4 x float> [[TMP2]]
279 %c0 = extractelement <4 x i32> %c, i32 0
280 %c1 = extractelement <4 x i32> %c, i32 1
281 %c2 = extractelement <4 x i32> %c, i32 2
282 %c3 = extractelement <4 x i32> %c, i32 3
283 %a0 = extractelement <4 x float> %a, i32 0
284 %a1 = extractelement <4 x float> %a, i32 1
285 %a2 = extractelement <4 x float> %a, i32 2
286 %a3 = extractelement <4 x float> %a, i32 3
287 %b0 = extractelement <4 x float> %b, i32 0
288 %b1 = extractelement <4 x float> %b, i32 1
289 %b2 = extractelement <4 x float> %b, i32 2
290 %b3 = extractelement <4 x float> %b, i32 3
291 %cmp0 = icmp ne i32 %c0, 0
292 %cmp1 = icmp ne i32 %c1, 0
293 %cmp2 = icmp ne i32 %c2, 0
294 %cmp3 = icmp ne i32 %c3, 0
295 %s0 = select i1 %cmp0, float %a0, float %b0
296 %s1 = select i1 %cmp1, float %a1, float %b1
297 %s2 = select i1 %cmp2, float %a2, float %b2
298 %s3 = select i1 %cmp3, float %a3, float %b3
299 %ra = insertelement <4 x float> undef, float %s0, i32 0
300 %rb = insertelement <4 x float> %ra, float %s1, i32 1
301 %rc = insertelement <4 x float> %rb, float %s2, i32 2
302 %rd = insertelement <4 x float> %rc, float %s3, i32 3
303 call void @v4f32_user(<4 x float> %rd) #0
307 ; Unused insertelement
308 define <4 x float> @simple_select_no_users(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
309 ; CHECK-LABEL: @simple_select_no_users(
310 ; CHECK-NEXT: [[TMP1:%.*]] = shufflevector <4 x i32> [[C:%.*]], <4 x i32> poison, <2 x i32> <i32 0, i32 1>
311 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ne <2 x i32> [[TMP1]], zeroinitializer
312 ; CHECK-NEXT: [[TMP3:%.*]] = shufflevector <4 x float> [[A:%.*]], <4 x float> poison, <2 x i32> <i32 0, i32 1>
313 ; CHECK-NEXT: [[TMP4:%.*]] = shufflevector <4 x float> [[B:%.*]], <4 x float> poison, <2 x i32> <i32 0, i32 1>
314 ; CHECK-NEXT: [[TMP5:%.*]] = select <2 x i1> [[TMP2]], <2 x float> [[TMP3]], <2 x float> [[TMP4]]
315 ; CHECK-NEXT: [[TMP6:%.*]] = shufflevector <4 x i32> [[C]], <4 x i32> poison, <2 x i32> <i32 2, i32 3>
316 ; CHECK-NEXT: [[TMP7:%.*]] = icmp ne <2 x i32> [[TMP6]], zeroinitializer
317 ; CHECK-NEXT: [[TMP8:%.*]] = shufflevector <4 x float> [[A]], <4 x float> poison, <2 x i32> <i32 2, i32 3>
318 ; CHECK-NEXT: [[TMP9:%.*]] = shufflevector <4 x float> [[B]], <4 x float> poison, <2 x i32> <i32 2, i32 3>
319 ; CHECK-NEXT: [[TMP10:%.*]] = select <2 x i1> [[TMP7]], <2 x float> [[TMP8]], <2 x float> [[TMP9]]
320 ; CHECK-NEXT: [[TMP11:%.*]] = shufflevector <2 x float> [[TMP5]], <2 x float> undef, <4 x i32> <i32 0, i32 1, i32 2, i32 3>
321 ; CHECK-NEXT: [[TMP12:%.*]] = shufflevector <2 x float> [[TMP10]], <2 x float> poison, <4 x i32> <i32 0, i32 1, i32 poison, i32 poison>
322 ; CHECK-NEXT: [[RD1:%.*]] = shufflevector <4 x float> [[TMP12]], <4 x float> undef, <4 x i32> <i32 4, i32 5, i32 0, i32 1>
323 ; CHECK-NEXT: ret <4 x float> [[RD1]]
325 %c0 = extractelement <4 x i32> %c, i32 0
326 %c1 = extractelement <4 x i32> %c, i32 1
327 %c2 = extractelement <4 x i32> %c, i32 2
328 %c3 = extractelement <4 x i32> %c, i32 3
329 %a0 = extractelement <4 x float> %a, i32 0
330 %a1 = extractelement <4 x float> %a, i32 1
331 %a2 = extractelement <4 x float> %a, i32 2
332 %a3 = extractelement <4 x float> %a, i32 3
333 %b0 = extractelement <4 x float> %b, i32 0
334 %b1 = extractelement <4 x float> %b, i32 1
335 %b2 = extractelement <4 x float> %b, i32 2
336 %b3 = extractelement <4 x float> %b, i32 3
337 %cmp0 = icmp ne i32 %c0, 0
338 %cmp1 = icmp ne i32 %c1, 0
339 %cmp2 = icmp ne i32 %c2, 0
340 %cmp3 = icmp ne i32 %c3, 0
341 %s0 = select i1 %cmp0, float %a0, float %b0
342 %s1 = select i1 %cmp1, float %a1, float %b1
343 %s2 = select i1 %cmp2, float %a2, float %b2
344 %s3 = select i1 %cmp3, float %a3, float %b3
345 %ra = insertelement <4 x float> undef, float %s0, i32 0
346 %rb = insertelement <4 x float> %ra, float %s1, i32 1
347 %rc = insertelement <4 x float> undef, float %s2, i32 2
348 %rd = insertelement <4 x float> %rc, float %s3, i32 3
352 ; Make sure infinite loop doesn't happen which I ran into when trying
353 ; to do this backwards this backwards
354 define <4 x i32> @reconstruct(<4 x i32> %c) #0 {
355 ; CHECK-LABEL: @reconstruct(
356 ; CHECK-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
357 ; CHECK-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
358 ; CHECK-NEXT: [[C2:%.*]] = extractelement <4 x i32> [[C]], i32 2
359 ; CHECK-NEXT: [[C3:%.*]] = extractelement <4 x i32> [[C]], i32 3
360 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x i32> undef, i32 [[C0]], i32 0
361 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x i32> [[RA]], i32 [[C1]], i32 1
362 ; CHECK-NEXT: [[RC:%.*]] = insertelement <4 x i32> [[RB]], i32 [[C2]], i32 2
363 ; CHECK-NEXT: [[RD:%.*]] = insertelement <4 x i32> [[RC]], i32 [[C3]], i32 3
364 ; CHECK-NEXT: ret <4 x i32> [[RD]]
366 %c0 = extractelement <4 x i32> %c, i32 0
367 %c1 = extractelement <4 x i32> %c, i32 1
368 %c2 = extractelement <4 x i32> %c, i32 2
369 %c3 = extractelement <4 x i32> %c, i32 3
370 %ra = insertelement <4 x i32> undef, i32 %c0, i32 0
371 %rb = insertelement <4 x i32> %ra, i32 %c1, i32 1
372 %rc = insertelement <4 x i32> %rb, i32 %c2, i32 2
373 %rd = insertelement <4 x i32> %rc, i32 %c3, i32 3
377 define <2 x float> @simple_select_v2(<2 x float> %a, <2 x float> %b, <2 x i32> %c) #0 {
378 ; CHECK-LABEL: @simple_select_v2(
379 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne <2 x i32> [[C:%.*]], zeroinitializer
380 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[TMP1]], <2 x float> [[A:%.*]], <2 x float> [[B:%.*]]
381 ; CHECK-NEXT: ret <2 x float> [[TMP2]]
383 %c0 = extractelement <2 x i32> %c, i32 0
384 %c1 = extractelement <2 x i32> %c, i32 1
385 %a0 = extractelement <2 x float> %a, i32 0
386 %a1 = extractelement <2 x float> %a, i32 1
387 %b0 = extractelement <2 x float> %b, i32 0
388 %b1 = extractelement <2 x float> %b, i32 1
389 %cmp0 = icmp ne i32 %c0, 0
390 %cmp1 = icmp ne i32 %c1, 0
391 %s0 = select i1 %cmp0, float %a0, float %b0
392 %s1 = select i1 %cmp1, float %a1, float %b1
393 %ra = insertelement <2 x float> undef, float %s0, i32 0
394 %rb = insertelement <2 x float> %ra, float %s1, i32 1
398 ; Make sure when we construct partial vectors, we don't keep
399 ; re-visiting the insertelement chains starting with undef
400 ; (low cost threshold needed to force this to happen)
401 define <4 x float> @simple_select_partial_vector(<4 x float> %a, <4 x float> %b, <4 x i32> %c) #0 {
402 ; CHECK-LABEL: @simple_select_partial_vector(
403 ; CHECK-NEXT: [[C0:%.*]] = extractelement <4 x i32> [[C:%.*]], i32 0
404 ; CHECK-NEXT: [[C1:%.*]] = extractelement <4 x i32> [[C]], i32 1
405 ; CHECK-NEXT: [[A0:%.*]] = extractelement <4 x float> [[A:%.*]], i32 0
406 ; CHECK-NEXT: [[A1:%.*]] = extractelement <4 x float> [[A]], i32 1
407 ; CHECK-NEXT: [[B0:%.*]] = extractelement <4 x float> [[B:%.*]], i32 0
408 ; CHECK-NEXT: [[B1:%.*]] = extractelement <4 x float> [[B]], i32 1
409 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <2 x i32> undef, i32 [[C0]], i32 0
410 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <2 x i32> [[TMP1]], i32 [[C1]], i32 1
411 ; CHECK-NEXT: [[TMP3:%.*]] = icmp ne <2 x i32> [[TMP2]], zeroinitializer
412 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <2 x float> undef, float [[A0]], i32 0
413 ; CHECK-NEXT: [[TMP5:%.*]] = insertelement <2 x float> [[TMP4]], float [[A1]], i32 1
414 ; CHECK-NEXT: [[TMP6:%.*]] = insertelement <2 x float> undef, float [[B0]], i32 0
415 ; CHECK-NEXT: [[TMP7:%.*]] = insertelement <2 x float> [[TMP6]], float [[B1]], i32 1
416 ; CHECK-NEXT: [[TMP8:%.*]] = select <2 x i1> [[TMP3]], <2 x float> [[TMP5]], <2 x float> [[TMP7]]
417 ; CHECK-NEXT: [[TMP9:%.*]] = extractelement <2 x float> [[TMP8]], i32 0
418 ; CHECK-NEXT: [[RA:%.*]] = insertelement <4 x float> undef, float [[TMP9]], i32 0
419 ; CHECK-NEXT: [[TMP10:%.*]] = extractelement <2 x float> [[TMP8]], i32 1
420 ; CHECK-NEXT: [[RB:%.*]] = insertelement <4 x float> [[RA]], float [[TMP10]], i32 1
421 ; CHECK-NEXT: ret <4 x float> [[RB]]
423 %c0 = extractelement <4 x i32> %c, i32 0
424 %c1 = extractelement <4 x i32> %c, i32 1
425 %a0 = extractelement <4 x float> %a, i32 0
426 %a1 = extractelement <4 x float> %a, i32 1
427 %b0 = extractelement <4 x float> %b, i32 0
428 %b1 = extractelement <4 x float> %b, i32 1
429 %1 = insertelement <2 x i32> undef, i32 %c0, i32 0
430 %2 = insertelement <2 x i32> %1, i32 %c1, i32 1
431 %3 = icmp ne <2 x i32> %2, zeroinitializer
432 %4 = insertelement <2 x float> undef, float %a0, i32 0
433 %5 = insertelement <2 x float> %4, float %a1, i32 1
434 %6 = insertelement <2 x float> undef, float %b0, i32 0
435 %7 = insertelement <2 x float> %6, float %b1, i32 1
436 %8 = select <2 x i1> %3, <2 x float> %5, <2 x float> %7
437 %9 = extractelement <2 x float> %8, i32 0
438 %ra = insertelement <4 x float> undef, float %9, i32 0
439 %10 = extractelement <2 x float> %8, i32 1
440 %rb = insertelement <4 x float> %ra, float %10, i32 1
444 ; Make sure that vectorization happens even if insertelements operations
445 ; must be rescheduled. The case here is from compiling Julia.
446 define <4 x float> @reschedule_extract(<4 x float> %a, <4 x float> %b) {
447 ; CHECK-LABEL: @reschedule_extract(
448 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]]
449 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
451 %a0 = extractelement <4 x float> %a, i32 0
452 %b0 = extractelement <4 x float> %b, i32 0
453 %c0 = fadd float %a0, %b0
454 %v0 = insertelement <4 x float> undef, float %c0, i32 0
455 %a1 = extractelement <4 x float> %a, i32 1
456 %b1 = extractelement <4 x float> %b, i32 1
457 %c1 = fadd float %a1, %b1
458 %v1 = insertelement <4 x float> %v0, float %c1, i32 1
459 %a2 = extractelement <4 x float> %a, i32 2
460 %b2 = extractelement <4 x float> %b, i32 2
461 %c2 = fadd float %a2, %b2
462 %v2 = insertelement <4 x float> %v1, float %c2, i32 2
463 %a3 = extractelement <4 x float> %a, i32 3
464 %b3 = extractelement <4 x float> %b, i32 3
465 %c3 = fadd float %a3, %b3
466 %v3 = insertelement <4 x float> %v2, float %c3, i32 3
470 ; Check that cost model for vectorization takes credit for
471 ; instructions that are erased.
472 define <4 x float> @take_credit(<4 x float> %a, <4 x float> %b) {
473 ; CHECK-LABEL: @take_credit(
474 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <4 x float> [[A:%.*]], [[B:%.*]]
475 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
477 %a0 = extractelement <4 x float> %a, i32 0
478 %b0 = extractelement <4 x float> %b, i32 0
479 %c0 = fadd float %a0, %b0
480 %a1 = extractelement <4 x float> %a, i32 1
481 %b1 = extractelement <4 x float> %b, i32 1
482 %c1 = fadd float %a1, %b1
483 %a2 = extractelement <4 x float> %a, i32 2
484 %b2 = extractelement <4 x float> %b, i32 2
485 %c2 = fadd float %a2, %b2
486 %a3 = extractelement <4 x float> %a, i32 3
487 %b3 = extractelement <4 x float> %b, i32 3
488 %c3 = fadd float %a3, %b3
489 %v0 = insertelement <4 x float> undef, float %c0, i32 0
490 %v1 = insertelement <4 x float> %v0, float %c1, i32 1
491 %v2 = insertelement <4 x float> %v1, float %c2, i32 2
492 %v3 = insertelement <4 x float> %v2, float %c3, i32 3
496 ; Make sure we handle multiple trees that feed one build vector correctly.
497 define <4 x double> @multi_tree(double %w, double %x, double %y, double %z) {
498 ; CHECK-LABEL: @multi_tree(
499 ; CHECK-NEXT: [[TMP1:%.*]] = insertelement <4 x double> poison, double [[Z:%.*]], i32 0
500 ; CHECK-NEXT: [[TMP2:%.*]] = insertelement <4 x double> [[TMP1]], double [[Y:%.*]], i32 1
501 ; CHECK-NEXT: [[TMP3:%.*]] = insertelement <4 x double> [[TMP2]], double [[X:%.*]], i32 2
502 ; CHECK-NEXT: [[TMP4:%.*]] = insertelement <4 x double> [[TMP3]], double [[W:%.*]], i32 3
503 ; CHECK-NEXT: [[TMP5:%.*]] = fadd <4 x double> [[TMP4]], <double 3.000000e+00, double 2.000000e+00, double 1.000000e+00, double 0.000000e+00>
504 ; CHECK-NEXT: [[TMP6:%.*]] = fmul <4 x double> [[TMP5]], <double 1.000000e+00, double 1.000000e+00, double 1.000000e+00, double 1.000000e+00>
505 ; CHECK-NEXT: ret <4 x double> [[TMP6]]
507 %t0 = fadd double %w , 0.000000e+00
508 %t1 = fadd double %x , 1.000000e+00
509 %t2 = fadd double %y , 2.000000e+00
510 %t3 = fadd double %z , 3.000000e+00
511 %t4 = fmul double %t0, 1.000000e+00
512 %i1 = insertelement <4 x double> undef, double %t4, i32 3
513 %t5 = fmul double %t1, 1.000000e+00
514 %i2 = insertelement <4 x double> %i1, double %t5, i32 2
515 %t6 = fmul double %t2, 1.000000e+00
516 %i3 = insertelement <4 x double> %i2, double %t6, i32 1
517 %t7 = fmul double %t3, 1.000000e+00
518 %i4 = insertelement <4 x double> %i3, double %t7, i32 0
522 define <8 x float> @_vadd256(<8 x float> %a, <8 x float> %b) local_unnamed_addr #0 {
523 ; CHECK-LABEL: @_vadd256(
524 ; CHECK-NEXT: [[TMP1:%.*]] = fadd <8 x float> [[A:%.*]], [[B:%.*]]
525 ; CHECK-NEXT: ret <8 x float> [[TMP1]]
527 %vecext = extractelement <8 x float> %a, i32 0
528 %vecext1 = extractelement <8 x float> %b, i32 0
529 %add = fadd float %vecext, %vecext1
530 %vecext2 = extractelement <8 x float> %a, i32 1
531 %vecext3 = extractelement <8 x float> %b, i32 1
532 %add4 = fadd float %vecext2, %vecext3
533 %vecext5 = extractelement <8 x float> %a, i32 2
534 %vecext6 = extractelement <8 x float> %b, i32 2
535 %add7 = fadd float %vecext5, %vecext6
536 %vecext8 = extractelement <8 x float> %a, i32 3
537 %vecext9 = extractelement <8 x float> %b, i32 3
538 %add10 = fadd float %vecext8, %vecext9
539 %vecext11 = extractelement <8 x float> %a, i32 4
540 %vecext12 = extractelement <8 x float> %b, i32 4
541 %add13 = fadd float %vecext11, %vecext12
542 %vecext14 = extractelement <8 x float> %a, i32 5
543 %vecext15 = extractelement <8 x float> %b, i32 5
544 %add16 = fadd float %vecext14, %vecext15
545 %vecext17 = extractelement <8 x float> %a, i32 6
546 %vecext18 = extractelement <8 x float> %b, i32 6
547 %add19 = fadd float %vecext17, %vecext18
548 %vecext20 = extractelement <8 x float> %a, i32 7
549 %vecext21 = extractelement <8 x float> %b, i32 7
550 %add22 = fadd float %vecext20, %vecext21
551 %vecinit.i = insertelement <8 x float> undef, float %add, i32 0
552 %vecinit1.i = insertelement <8 x float> %vecinit.i, float %add4, i32 1
553 %vecinit2.i = insertelement <8 x float> %vecinit1.i, float %add7, i32 2
554 %vecinit3.i = insertelement <8 x float> %vecinit2.i, float %add10, i32 3
555 %vecinit4.i = insertelement <8 x float> %vecinit3.i, float %add13, i32 4
556 %vecinit5.i = insertelement <8 x float> %vecinit4.i, float %add16, i32 5
557 %vecinit6.i = insertelement <8 x float> %vecinit5.i, float %add19, i32 6
558 %vecinit7.i = insertelement <8 x float> %vecinit6.i, float %add22, i32 7
559 ret <8 x float> %vecinit7.i
562 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" }