1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=slp-vectorizer -S | FileCheck %s
3 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-apple-macosx10.9.0"
6 @A = common global [2000 x double] zeroinitializer, align 16
7 @B = common global [2000 x double] zeroinitializer, align 16
8 @C = common global [2000 x float] zeroinitializer, align 16
9 @D = common global [2000 x float] zeroinitializer, align 16
11 ; Function Attrs: nounwind ssp uwtable
12 define void @foo_3double(i32 %u) #0 {
13 ; CHECK-LABEL: @foo_3double(
15 ; CHECK-NEXT: [[U_ADDR:%.*]] = alloca i32, align 4
16 ; CHECK-NEXT: store i32 [[U:%.*]], ptr [[U_ADDR]], align 4
17 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[U]], 3
18 ; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[MUL]] to i64
19 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 [[IDXPROM]]
20 ; CHECK-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 [[IDXPROM]]
21 ; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[ARRAYIDX]], align 8
22 ; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[ARRAYIDX4]], align 8
23 ; CHECK-NEXT: [[TMP2:%.*]] = fadd <2 x double> [[TMP0]], [[TMP1]]
24 ; CHECK-NEXT: store <2 x double> [[TMP2]], ptr [[ARRAYIDX]], align 8
25 ; CHECK-NEXT: [[ADD24:%.*]] = add nsw i32 [[MUL]], 2
26 ; CHECK-NEXT: [[IDXPROM25:%.*]] = sext i32 [[ADD24]] to i64
27 ; CHECK-NEXT: [[ARRAYIDX26:%.*]] = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 [[IDXPROM25]]
28 ; CHECK-NEXT: [[TMP3:%.*]] = load double, ptr [[ARRAYIDX26]], align 8
29 ; CHECK-NEXT: [[ARRAYIDX30:%.*]] = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 [[IDXPROM25]]
30 ; CHECK-NEXT: [[TMP4:%.*]] = load double, ptr [[ARRAYIDX30]], align 8
31 ; CHECK-NEXT: [[ADD31:%.*]] = fadd double [[TMP3]], [[TMP4]]
32 ; CHECK-NEXT: store double [[ADD31]], ptr [[ARRAYIDX26]], align 8
33 ; CHECK-NEXT: ret void
36 %u.addr = alloca i32, align 4
37 store i32 %u, ptr %u.addr, align 4
38 %mul = mul nsw i32 %u, 3
39 %idxprom = sext i32 %mul to i64
40 %arrayidx = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 %idxprom
41 %0 = load double, ptr %arrayidx, align 8
42 %arrayidx4 = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 %idxprom
43 %1 = load double, ptr %arrayidx4, align 8
44 %add5 = fadd double %0, %1
45 store double %add5, ptr %arrayidx, align 8
46 %add11 = add nsw i32 %mul, 1
47 %idxprom12 = sext i32 %add11 to i64
48 %arrayidx13 = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 %idxprom12
49 %2 = load double, ptr %arrayidx13, align 8
50 %arrayidx17 = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 %idxprom12
51 %3 = load double, ptr %arrayidx17, align 8
52 %add18 = fadd double %2, %3
53 store double %add18, ptr %arrayidx13, align 8
54 %add24 = add nsw i32 %mul, 2
55 %idxprom25 = sext i32 %add24 to i64
56 %arrayidx26 = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 %idxprom25
57 %4 = load double, ptr %arrayidx26, align 8
58 %arrayidx30 = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 %idxprom25
59 %5 = load double, ptr %arrayidx30, align 8
60 %add31 = fadd double %4, %5
61 store double %add31, ptr %arrayidx26, align 8
65 ; SCEV should be able to tell that accesses A[C1 + C2*i], A[C1 + C2*i], ...
66 ; A[C1 + C2*i] are consecutive, if C2 is a power of 2, and C2 > C1 > 0.
67 ; Thus, the following code should be vectorized.
68 ; Function Attrs: nounwind ssp uwtable
69 define void @foo_2double(i32 %u) #0 {
70 ; CHECK-LABEL: @foo_2double(
72 ; CHECK-NEXT: [[U_ADDR:%.*]] = alloca i32, align 4
73 ; CHECK-NEXT: store i32 [[U:%.*]], ptr [[U_ADDR]], align 4
74 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[U]], 2
75 ; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[MUL]] to i64
76 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 [[IDXPROM]]
77 ; CHECK-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 [[IDXPROM]]
78 ; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[ARRAYIDX]], align 8
79 ; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[ARRAYIDX4]], align 8
80 ; CHECK-NEXT: [[TMP2:%.*]] = fadd <2 x double> [[TMP0]], [[TMP1]]
81 ; CHECK-NEXT: store <2 x double> [[TMP2]], ptr [[ARRAYIDX]], align 8
82 ; CHECK-NEXT: ret void
85 %u.addr = alloca i32, align 4
86 store i32 %u, ptr %u.addr, align 4
87 %mul = mul nsw i32 %u, 2
88 %idxprom = sext i32 %mul to i64
89 %arrayidx = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 %idxprom
90 %0 = load double, ptr %arrayidx, align 8
91 %arrayidx4 = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 %idxprom
92 %1 = load double, ptr %arrayidx4, align 8
93 %add5 = fadd double %0, %1
94 store double %add5, ptr %arrayidx, align 8
95 %add11 = add nsw i32 %mul, 1
96 %idxprom12 = sext i32 %add11 to i64
97 %arrayidx13 = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 %idxprom12
98 %2 = load double, ptr %arrayidx13, align 8
99 %arrayidx17 = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 %idxprom12
100 %3 = load double, ptr %arrayidx17, align 8
101 %add18 = fadd double %2, %3
102 store double %add18, ptr %arrayidx13, align 8
106 ; Similar to the previous test, but with different datatype.
107 ; Function Attrs: nounwind ssp uwtable
108 define void @foo_4float(i32 %u) #0 {
109 ; CHECK-LABEL: @foo_4float(
111 ; CHECK-NEXT: [[U_ADDR:%.*]] = alloca i32, align 4
112 ; CHECK-NEXT: store i32 [[U:%.*]], ptr [[U_ADDR]], align 4
113 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[U]], 4
114 ; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[MUL]] to i64
115 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [2000 x float], ptr @C, i32 0, i64 [[IDXPROM]]
116 ; CHECK-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds [2000 x float], ptr @D, i32 0, i64 [[IDXPROM]]
117 ; CHECK-NEXT: [[TMP0:%.*]] = load <4 x float>, ptr [[ARRAYIDX]], align 4
118 ; CHECK-NEXT: [[TMP1:%.*]] = load <4 x float>, ptr [[ARRAYIDX4]], align 4
119 ; CHECK-NEXT: [[TMP2:%.*]] = fadd <4 x float> [[TMP0]], [[TMP1]]
120 ; CHECK-NEXT: store <4 x float> [[TMP2]], ptr [[ARRAYIDX]], align 4
121 ; CHECK-NEXT: ret void
124 %u.addr = alloca i32, align 4
125 store i32 %u, ptr %u.addr, align 4
126 %mul = mul nsw i32 %u, 4
127 %idxprom = sext i32 %mul to i64
128 %arrayidx = getelementptr inbounds [2000 x float], ptr @C, i32 0, i64 %idxprom
129 %0 = load float, ptr %arrayidx, align 4
130 %arrayidx4 = getelementptr inbounds [2000 x float], ptr @D, i32 0, i64 %idxprom
131 %1 = load float, ptr %arrayidx4, align 4
132 %add5 = fadd float %0, %1
133 store float %add5, ptr %arrayidx, align 4
134 %add11 = add nsw i32 %mul, 1
135 %idxprom12 = sext i32 %add11 to i64
136 %arrayidx13 = getelementptr inbounds [2000 x float], ptr @C, i32 0, i64 %idxprom12
137 %2 = load float, ptr %arrayidx13, align 4
138 %arrayidx17 = getelementptr inbounds [2000 x float], ptr @D, i32 0, i64 %idxprom12
139 %3 = load float, ptr %arrayidx17, align 4
140 %add18 = fadd float %2, %3
141 store float %add18, ptr %arrayidx13, align 4
142 %add24 = add nsw i32 %mul, 2
143 %idxprom25 = sext i32 %add24 to i64
144 %arrayidx26 = getelementptr inbounds [2000 x float], ptr @C, i32 0, i64 %idxprom25
145 %4 = load float, ptr %arrayidx26, align 4
146 %arrayidx30 = getelementptr inbounds [2000 x float], ptr @D, i32 0, i64 %idxprom25
147 %5 = load float, ptr %arrayidx30, align 4
148 %add31 = fadd float %4, %5
149 store float %add31, ptr %arrayidx26, align 4
150 %add37 = add nsw i32 %mul, 3
151 %idxprom38 = sext i32 %add37 to i64
152 %arrayidx39 = getelementptr inbounds [2000 x float], ptr @C, i32 0, i64 %idxprom38
153 %6 = load float, ptr %arrayidx39, align 4
154 %arrayidx43 = getelementptr inbounds [2000 x float], ptr @D, i32 0, i64 %idxprom38
155 %7 = load float, ptr %arrayidx43, align 4
156 %add44 = fadd float %6, %7
157 store float %add44, ptr %arrayidx39, align 4
161 ; Similar to the previous tests, but now we are dealing with AddRec SCEV.
162 ; Function Attrs: nounwind ssp uwtable
163 define i32 @foo_loop(ptr %A, i32 %n) #0 {
164 ; CHECK-LABEL: @foo_loop(
166 ; CHECK-NEXT: [[A_ADDR:%.*]] = alloca ptr, align 8
167 ; CHECK-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4
168 ; CHECK-NEXT: [[SUM:%.*]] = alloca double, align 8
169 ; CHECK-NEXT: [[I:%.*]] = alloca i32, align 4
170 ; CHECK-NEXT: store ptr [[A:%.*]], ptr [[A_ADDR]], align 8
171 ; CHECK-NEXT: store i32 [[N:%.*]], ptr [[N_ADDR]], align 4
172 ; CHECK-NEXT: store double 0.000000e+00, ptr [[SUM]], align 8
173 ; CHECK-NEXT: store i32 0, ptr [[I]], align 4
174 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 0, [[N]]
175 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]]
176 ; CHECK: for.body.lr.ph:
177 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
179 ; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
180 ; CHECK-NEXT: [[TMP1:%.*]] = phi double [ 0.000000e+00, [[FOR_BODY_LR_PH]] ], [ [[ADD7:%.*]], [[FOR_BODY]] ]
181 ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i32 [[TMP0]], 2
182 ; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[MUL]] to i64
183 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[A]], i64 [[IDXPROM]]
184 ; CHECK-NEXT: [[TMP2:%.*]] = load <2 x double>, ptr [[ARRAYIDX]], align 8
185 ; CHECK-NEXT: [[TMP3:%.*]] = fmul <2 x double> <double 7.000000e+00, double 7.000000e+00>, [[TMP2]]
186 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x double> [[TMP3]], i32 0
187 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <2 x double> [[TMP3]], i32 1
188 ; CHECK-NEXT: [[ADD6:%.*]] = fadd double [[TMP4]], [[TMP5]]
189 ; CHECK-NEXT: [[ADD7]] = fadd double [[TMP1]], [[ADD6]]
190 ; CHECK-NEXT: store double [[ADD7]], ptr [[SUM]], align 8
191 ; CHECK-NEXT: [[INC]] = add nsw i32 [[TMP0]], 1
192 ; CHECK-NEXT: store i32 [[INC]], ptr [[I]], align 4
193 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[N]]
194 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_FOR_END_CRIT_EDGE:%.*]]
195 ; CHECK: for.cond.for.end_crit_edge:
196 ; CHECK-NEXT: [[SPLIT:%.*]] = phi double [ [[ADD7]], [[FOR_BODY]] ]
197 ; CHECK-NEXT: br label [[FOR_END]]
199 ; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi double [ [[SPLIT]], [[FOR_COND_FOR_END_CRIT_EDGE]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
200 ; CHECK-NEXT: [[CONV:%.*]] = fptosi double [[DOTLCSSA]] to i32
201 ; CHECK-NEXT: ret i32 [[CONV]]
204 %A.addr = alloca ptr, align 8
205 %n.addr = alloca i32, align 4
206 %sum = alloca double, align 8
207 %i = alloca i32, align 4
208 store ptr %A, ptr %A.addr, align 8
209 store i32 %n, ptr %n.addr, align 4
210 store double 0.000000e+00, ptr %sum, align 8
211 store i32 0, ptr %i, align 4
212 %cmp1 = icmp slt i32 0, %n
213 br i1 %cmp1, label %for.body.lr.ph, label %for.end
215 for.body.lr.ph: ; preds = %entry
218 for.body: ; preds = %for.body.lr.ph, %for.body
219 %0 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
220 %1 = phi double [ 0.000000e+00, %for.body.lr.ph ], [ %add7, %for.body ]
221 %mul = mul nsw i32 %0, 2
222 %idxprom = sext i32 %mul to i64
223 %arrayidx = getelementptr inbounds double, ptr %A, i64 %idxprom
224 %2 = load double, ptr %arrayidx, align 8
225 %mul1 = fmul double 7.000000e+00, %2
226 %add = add nsw i32 %mul, 1
227 %idxprom3 = sext i32 %add to i64
228 %arrayidx4 = getelementptr inbounds double, ptr %A, i64 %idxprom3
229 %3 = load double, ptr %arrayidx4, align 8
230 %mul5 = fmul double 7.000000e+00, %3
231 %add6 = fadd double %mul1, %mul5
232 %add7 = fadd double %1, %add6
233 store double %add7, ptr %sum, align 8
234 %inc = add nsw i32 %0, 1
235 store i32 %inc, ptr %i, align 4
236 %cmp = icmp slt i32 %inc, %n
237 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
239 for.cond.for.end_crit_edge: ; preds = %for.body
240 %split = phi double [ %add7, %for.body ]
243 for.end: ; preds = %for.cond.for.end_crit_edge, %entry
244 %.lcssa = phi double [ %split, %for.cond.for.end_crit_edge ], [ 0.000000e+00, %entry ]
245 %conv = fptosi double %.lcssa to i32
249 ; Similar to foo_2double but with a non-power-of-2 factor and potential
250 ; wrapping (both indices wrap or both don't in the same time)
251 ; Function Attrs: nounwind ssp uwtable
252 define void @foo_2double_non_power_of_2(i32 %u) #0 {
253 ; CHECK-LABEL: @foo_2double_non_power_of_2(
255 ; CHECK-NEXT: [[U_ADDR:%.*]] = alloca i32, align 4
256 ; CHECK-NEXT: store i32 [[U:%.*]], ptr [[U_ADDR]], align 4
257 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[U]], 6
258 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[MUL]], 6
259 ; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[ADD6]] to i64
260 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 [[IDXPROM]]
261 ; CHECK-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 [[IDXPROM]]
262 ; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[ARRAYIDX]], align 8
263 ; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[ARRAYIDX4]], align 8
264 ; CHECK-NEXT: [[TMP2:%.*]] = fadd <2 x double> [[TMP0]], [[TMP1]]
265 ; CHECK-NEXT: store <2 x double> [[TMP2]], ptr [[ARRAYIDX]], align 8
266 ; CHECK-NEXT: ret void
269 %u.addr = alloca i32, align 4
270 store i32 %u, ptr %u.addr, align 4
272 %add6 = add i32 %mul, 6
273 %idxprom = sext i32 %add6 to i64
274 %arrayidx = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 %idxprom
275 %0 = load double, ptr %arrayidx, align 8
276 %arrayidx4 = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 %idxprom
277 %1 = load double, ptr %arrayidx4, align 8
278 %add5 = fadd double %0, %1
279 store double %add5, ptr %arrayidx, align 8
280 %add7 = add i32 %mul, 7
281 %idxprom12 = sext i32 %add7 to i64
282 %arrayidx13 = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 %idxprom12
283 %2 = load double, ptr %arrayidx13, align 8
284 %arrayidx17 = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 %idxprom12
285 %3 = load double, ptr %arrayidx17, align 8
286 %add18 = fadd double %2, %3
287 store double %add18, ptr %arrayidx13, align 8
291 ; Similar to foo_2double_non_power_of_2 but with zext's instead of sext's
292 ; Function Attrs: nounwind ssp uwtable
293 define void @foo_2double_non_power_of_2_zext(i32 %u) #0 {
294 ; CHECK-LABEL: @foo_2double_non_power_of_2_zext(
296 ; CHECK-NEXT: [[U_ADDR:%.*]] = alloca i32, align 4
297 ; CHECK-NEXT: store i32 [[U:%.*]], ptr [[U_ADDR]], align 4
298 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[U]], 6
299 ; CHECK-NEXT: [[ADD6:%.*]] = add i32 [[MUL]], 6
300 ; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[ADD6]] to i64
301 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 [[IDXPROM]]
302 ; CHECK-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 [[IDXPROM]]
303 ; CHECK-NEXT: [[TMP0:%.*]] = load <2 x double>, ptr [[ARRAYIDX]], align 8
304 ; CHECK-NEXT: [[TMP1:%.*]] = load <2 x double>, ptr [[ARRAYIDX4]], align 8
305 ; CHECK-NEXT: [[TMP2:%.*]] = fadd <2 x double> [[TMP0]], [[TMP1]]
306 ; CHECK-NEXT: store <2 x double> [[TMP2]], ptr [[ARRAYIDX]], align 8
307 ; CHECK-NEXT: ret void
310 %u.addr = alloca i32, align 4
311 store i32 %u, ptr %u.addr, align 4
313 %add6 = add i32 %mul, 6
314 %idxprom = zext i32 %add6 to i64
315 %arrayidx = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 %idxprom
316 %0 = load double, ptr %arrayidx, align 8
317 %arrayidx4 = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 %idxprom
318 %1 = load double, ptr %arrayidx4, align 8
319 %add5 = fadd double %0, %1
320 store double %add5, ptr %arrayidx, align 8
321 %add7 = add i32 %mul, 7
322 %idxprom12 = zext i32 %add7 to i64
323 %arrayidx13 = getelementptr inbounds [2000 x double], ptr @A, i32 0, i64 %idxprom12
324 %2 = load double, ptr %arrayidx13, align 8
325 %arrayidx17 = getelementptr inbounds [2000 x double], ptr @B, i32 0, i64 %idxprom12
326 %3 = load double, ptr %arrayidx17, align 8
327 %add18 = fadd double %2, %3
328 store double %add18, ptr %arrayidx13, align 8
332 ; Similar to foo_2double_non_power_of_2, but now we are dealing with AddRec SCEV.
333 ; Alternatively, this is like foo_loop, but with a non-power-of-2 factor and
334 ; potential wrapping (both indices wrap or both don't in the same time)
335 ; Function Attrs: nounwind ssp uwtable
336 define i32 @foo_loop_non_power_of_2(ptr %A, i32 %n) #0 {
337 ; CHECK-LABEL: @foo_loop_non_power_of_2(
339 ; CHECK-NEXT: [[A_ADDR:%.*]] = alloca ptr, align 8
340 ; CHECK-NEXT: [[N_ADDR:%.*]] = alloca i32, align 4
341 ; CHECK-NEXT: [[SUM:%.*]] = alloca double, align 8
342 ; CHECK-NEXT: [[I:%.*]] = alloca i32, align 4
343 ; CHECK-NEXT: store ptr [[A:%.*]], ptr [[A_ADDR]], align 8
344 ; CHECK-NEXT: store i32 [[N:%.*]], ptr [[N_ADDR]], align 4
345 ; CHECK-NEXT: store double 0.000000e+00, ptr [[SUM]], align 8
346 ; CHECK-NEXT: store i32 0, ptr [[I]], align 4
347 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 0, [[N]]
348 ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]]
349 ; CHECK: for.body.lr.ph:
350 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
352 ; CHECK-NEXT: [[TMP0:%.*]] = phi i32 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_BODY]] ]
353 ; CHECK-NEXT: [[TMP1:%.*]] = phi double [ 0.000000e+00, [[FOR_BODY_LR_PH]] ], [ [[ADD7:%.*]], [[FOR_BODY]] ]
354 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[TMP0]], 12
355 ; CHECK-NEXT: [[ADD_5:%.*]] = add i32 [[MUL]], 5
356 ; CHECK-NEXT: [[IDXPROM:%.*]] = sext i32 [[ADD_5]] to i64
357 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[A]], i64 [[IDXPROM]]
358 ; CHECK-NEXT: [[TMP2:%.*]] = load <2 x double>, ptr [[ARRAYIDX]], align 8
359 ; CHECK-NEXT: [[TMP3:%.*]] = fmul <2 x double> <double 7.000000e+00, double 7.000000e+00>, [[TMP2]]
360 ; CHECK-NEXT: [[TMP4:%.*]] = extractelement <2 x double> [[TMP3]], i32 0
361 ; CHECK-NEXT: [[TMP5:%.*]] = extractelement <2 x double> [[TMP3]], i32 1
362 ; CHECK-NEXT: [[ADD6:%.*]] = fadd double [[TMP4]], [[TMP5]]
363 ; CHECK-NEXT: [[ADD7]] = fadd double [[TMP1]], [[ADD6]]
364 ; CHECK-NEXT: store double [[ADD7]], ptr [[SUM]], align 8
365 ; CHECK-NEXT: [[INC]] = add i32 [[TMP0]], 1
366 ; CHECK-NEXT: store i32 [[INC]], ptr [[I]], align 4
367 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[INC]], [[N]]
368 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_FOR_END_CRIT_EDGE:%.*]]
369 ; CHECK: for.cond.for.end_crit_edge:
370 ; CHECK-NEXT: [[SPLIT:%.*]] = phi double [ [[ADD7]], [[FOR_BODY]] ]
371 ; CHECK-NEXT: br label [[FOR_END]]
373 ; CHECK-NEXT: [[DOTLCSSA:%.*]] = phi double [ [[SPLIT]], [[FOR_COND_FOR_END_CRIT_EDGE]] ], [ 0.000000e+00, [[ENTRY:%.*]] ]
374 ; CHECK-NEXT: [[CONV:%.*]] = fptosi double [[DOTLCSSA]] to i32
375 ; CHECK-NEXT: ret i32 [[CONV]]
378 %A.addr = alloca ptr, align 8
379 %n.addr = alloca i32, align 4
380 %sum = alloca double, align 8
381 %i = alloca i32, align 4
382 store ptr %A, ptr %A.addr, align 8
383 store i32 %n, ptr %n.addr, align 4
384 store double 0.000000e+00, ptr %sum, align 8
385 store i32 0, ptr %i, align 4
386 %cmp1 = icmp slt i32 0, %n
387 br i1 %cmp1, label %for.body.lr.ph, label %for.end
389 for.body.lr.ph: ; preds = %entry
392 for.body: ; preds = %for.body.lr.ph, %for.body
393 %0 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
394 %1 = phi double [ 0.000000e+00, %for.body.lr.ph ], [ %add7, %for.body ]
395 %mul = mul i32 %0, 12
396 %add.5 = add i32 %mul, 5
397 %idxprom = sext i32 %add.5 to i64
398 %arrayidx = getelementptr inbounds double, ptr %A, i64 %idxprom
399 %2 = load double, ptr %arrayidx, align 8
400 %mul1 = fmul double 7.000000e+00, %2
401 %add.6 = add i32 %mul, 6
402 %idxprom3 = sext i32 %add.6 to i64
403 %arrayidx4 = getelementptr inbounds double, ptr %A, i64 %idxprom3
404 %3 = load double, ptr %arrayidx4, align 8
405 %mul5 = fmul double 7.000000e+00, %3
406 %add6 = fadd double %mul1, %mul5
407 %add7 = fadd double %1, %add6
408 store double %add7, ptr %sum, align 8
410 store i32 %inc, ptr %i, align 4
411 %cmp = icmp slt i32 %inc, %n
412 br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge
414 for.cond.for.end_crit_edge: ; preds = %for.body
415 %split = phi double [ %add7, %for.body ]
418 for.end: ; preds = %for.cond.for.end_crit_edge, %entry
419 %.lcssa = phi double [ %split, %for.cond.for.end_crit_edge ], [ 0.000000e+00, %entry ]
420 %conv = fptosi double %.lcssa to i32
424 ; This is generated by `clang -std=c11 -Wpedantic -Wall -O3 main.c -S -o - -emit-llvm`
425 ; with !{!"clang version 7.0.0 (trunk 337339) (llvm/trunk 337344)"} and stripping off
426 ; the !tbaa metadata nodes to fit the rest of the test file, where `cat main.c` is:
428 ; double bar(ptr a, unsigned n) {
431 ; for (unsigned i = 0; i < n; i += 2) {
438 ; The resulting IR is similar to @foo_loop, but with zext's instead of sext's.
440 ; Make sure we are able to vectorize this from now on:
442 define double @bar(ptr nocapture readonly %a, i32 %n) local_unnamed_addr #0 {
445 ; CHECK-NEXT: [[CMP15:%.*]] = icmp eq i32 [[N:%.*]], 0
446 ; CHECK-NEXT: br i1 [[CMP15]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY:%.*]]
447 ; CHECK: for.cond.cleanup:
448 ; CHECK-NEXT: [[TMP0:%.*]] = phi <2 x double> [ zeroinitializer, [[ENTRY:%.*]] ], [ [[TMP5:%.*]], [[FOR_BODY]] ]
449 ; CHECK-NEXT: [[TMP1:%.*]] = extractelement <2 x double> [[TMP0]], i32 0
450 ; CHECK-NEXT: [[TMP2:%.*]] = extractelement <2 x double> [[TMP0]], i32 1
451 ; CHECK-NEXT: [[MUL:%.*]] = fmul double [[TMP1]], [[TMP2]]
452 ; CHECK-NEXT: ret double [[MUL]]
454 ; CHECK-NEXT: [[I_018:%.*]] = phi i32 [ [[ADD5:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY]] ]
455 ; CHECK-NEXT: [[TMP3:%.*]] = phi <2 x double> [ [[TMP5]], [[FOR_BODY]] ], [ zeroinitializer, [[ENTRY]] ]
456 ; CHECK-NEXT: [[IDXPROM:%.*]] = zext i32 [[I_018]] to i64
457 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds double, ptr [[A:%.*]], i64 [[IDXPROM]]
458 ; CHECK-NEXT: [[TMP4:%.*]] = load <2 x double>, ptr [[ARRAYIDX]], align 8
459 ; CHECK-NEXT: [[TMP5]] = fadd <2 x double> [[TMP3]], [[TMP4]]
460 ; CHECK-NEXT: [[ADD5]] = add i32 [[I_018]], 2
461 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[ADD5]], [[N]]
462 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_CLEANUP]]
465 %cmp15 = icmp eq i32 %n, 0
466 br i1 %cmp15, label %for.cond.cleanup, label %for.body
468 for.cond.cleanup: ; preds = %for.body, %entry
469 %x.0.lcssa = phi double [ 0.000000e+00, %entry ], [ %add, %for.body ]
470 %y.0.lcssa = phi double [ 0.000000e+00, %entry ], [ %add4, %for.body ]
471 %mul = fmul double %x.0.lcssa, %y.0.lcssa
474 for.body: ; preds = %entry, %for.body
475 %i.018 = phi i32 [ %add5, %for.body ], [ 0, %entry ]
476 %y.017 = phi double [ %add4, %for.body ], [ 0.000000e+00, %entry ]
477 %x.016 = phi double [ %add, %for.body ], [ 0.000000e+00, %entry ]
478 %idxprom = zext i32 %i.018 to i64
479 %arrayidx = getelementptr inbounds double, ptr %a, i64 %idxprom
480 %0 = load double, ptr %arrayidx, align 8
481 %add = fadd double %x.016, %0
482 %add1 = or disjoint i32 %i.018, 1
483 %idxprom2 = zext i32 %add1 to i64
484 %arrayidx3 = getelementptr inbounds double, ptr %a, i64 %idxprom2
485 %1 = load double, ptr %arrayidx3, align 8
486 %add4 = fadd double %y.017, %1
487 %add5 = add i32 %i.018, 2
488 %cmp = icmp ult i32 %add5, %n
489 br i1 %cmp, label %for.body, label %for.cond.cleanup
492 ; Globals/constant expressions are not normal constants.
493 ; They should not be treated as the usual vectorization candidates.
495 @g1 = external global i32, align 4
496 @g2 = external global i32, align 4
498 define void @PR33958(ptr nocapture %p) {
499 ; CHECK-LABEL: @PR33958(
500 ; CHECK-NEXT: store ptr @g1, ptr [[P:%.*]], align 8
501 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds ptr, ptr [[P]], i64 1
502 ; CHECK-NEXT: store ptr @g2, ptr [[ARRAYIDX1]], align 8
503 ; CHECK-NEXT: ret void
505 store ptr @g1, ptr %p, align 8
506 %arrayidx1 = getelementptr inbounds ptr, ptr %p, i64 1
507 store ptr @g2, ptr %arrayidx1, align 8
511 define void @store_constant_expression(ptr %p) {
512 ; CHECK-LABEL: @store_constant_expression(
513 ; CHECK-NEXT: store i64 ptrtoint (ptr @g1 to i64), ptr [[P:%.*]], align 8
514 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i64, ptr [[P]], i64 1
515 ; CHECK-NEXT: store i64 ptrtoint (ptr @g2 to i64), ptr [[ARRAYIDX1]], align 8
516 ; CHECK-NEXT: ret void
518 store i64 ptrtoint (ptr @g1 to i64), ptr %p, align 8
519 %arrayidx1 = getelementptr inbounds i64, ptr %p, i64 1
520 store i64 ptrtoint (ptr @g2 to i64), ptr %arrayidx1, align 8
524 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" }
528 !0 = !{!"clang version 3.5.0 "}