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