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