1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -aa-pipeline=basic-aa -passes=loop-vectorize,dce,instcombine -force-vector-interleave=1 -force-vector-width=4 -S | FileCheck %s
3 ; RUN: opt < %s -aa-pipeline= -passes=loop-vectorize -S -pass-remarks-analysis='loop-vectorize' 2>&1 | FileCheck %s -check-prefix=FORCED_OPTSIZE
5 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-f80:128:128-n8:16:32:64-S128"
7 ; Make sure we vectorize this loop:
8 ; int foo(float *a, float *b, int n) {
9 ; for (int i=0; i<n; ++i)
13 define i32 @foo(ptr nocapture %a, ptr nocapture %b, i32 %n) nounwind uwtable ssp {
16 ; CHECK-NEXT: [[B2:%.*]] = ptrtoint ptr [[B:%.*]] to i64, !dbg [[DBG4:![0-9]+]]
17 ; CHECK-NEXT: [[A1:%.*]] = ptrtoint ptr [[A:%.*]] to i64, !dbg [[DBG4]]
18 ; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[N:%.*]], 0, !dbg [[DBG4]]
19 ; CHECK-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]], !dbg [[DBG4]]
20 ; CHECK: for.body.preheader:
21 ; CHECK-NEXT: [[TMP0:%.*]] = zext nneg i32 [[N]] to i64, !dbg [[DBG9:![0-9]+]]
22 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[N]], 4, !dbg [[DBG9]]
23 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]], !dbg [[DBG9]]
24 ; CHECK: vector.memcheck:
25 ; CHECK-NEXT: [[TMP1:%.*]] = sub i64 [[A1]], [[B2]], !dbg [[DBG9]]
26 ; CHECK-NEXT: [[DIFF_CHECK:%.*]] = icmp ult i64 [[TMP1]], 16, !dbg [[DBG9]]
27 ; CHECK-NEXT: br i1 [[DIFF_CHECK]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]], !dbg [[DBG9]]
29 ; CHECK-NEXT: [[N_VEC:%.*]] = and i64 [[TMP0]], 2147483644, !dbg [[DBG9]]
30 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]], !dbg [[DBG9]]
32 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ], !dbg [[DBG9]]
33 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[INDEX]], !dbg [[DBG9]]
34 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP2]], align 4, !dbg [[DBG9]]
35 ; CHECK-NEXT: [[TMP3:%.*]] = fmul <4 x float> [[WIDE_LOAD]], splat (float 3.000000e+00), !dbg [[DBG9]]
36 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[INDEX]], !dbg [[DBG9]]
37 ; CHECK-NEXT: store <4 x float> [[TMP3]], ptr [[TMP4]], align 4, !dbg [[DBG9]]
38 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4, !dbg [[DBG9]]
39 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]], !dbg [[DBG9]]
40 ; CHECK-NEXT: br i1 [[TMP5]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !dbg [[DBG9]], !llvm.loop [[LOOP10:![0-9]+]]
41 ; CHECK: middle.block:
42 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N_VEC]], [[TMP0]], !dbg [[DBG9]]
43 ; CHECK-NEXT: br i1 [[CMP_N]], label [[FOR_END_LOOPEXIT:%.*]], label [[SCALAR_PH]], !dbg [[DBG9]]
45 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[FOR_BODY_PREHEADER]] ], [ 0, [[VECTOR_MEMCHECK]] ], !dbg [[DBG9]]
46 ; CHECK-NEXT: br label [[FOR_BODY:%.*]], !dbg [[DBG9]]
48 ; CHECK-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], !dbg [[DBG9]]
49 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[B]], i64 [[INDVARS_IV]], !dbg [[DBG9]]
50 ; CHECK-NEXT: [[TMP6:%.*]] = load float, ptr [[ARRAYIDX]], align 4, !dbg [[DBG9]]
51 ; CHECK-NEXT: [[MUL:%.*]] = fmul float [[TMP6]], 3.000000e+00, !dbg [[DBG9]]
52 ; CHECK-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[INDVARS_IV]], !dbg [[DBG9]]
53 ; CHECK-NEXT: store float [[MUL]], ptr [[ARRAYIDX2]], align 4, !dbg [[DBG9]]
54 ; CHECK-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1, !dbg [[DBG9]]
55 ; CHECK-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32, !dbg [[DBG9]]
56 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[N]], [[LFTR_WIDEIV]], !dbg [[DBG9]]
57 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[FOR_END_LOOPEXIT]], label [[FOR_BODY]], !dbg [[DBG9]], !llvm.loop [[LOOP13:![0-9]+]]
58 ; CHECK: for.end.loopexit:
59 ; CHECK-NEXT: br label [[FOR_END]], !dbg [[DBG14:![0-9]+]]
61 ; CHECK-NEXT: ret i32 undef, !dbg [[DBG14]]
63 ; FORCED_OPTSIZE-LABEL: @foo(
64 ; FORCED_OPTSIZE-NEXT: entry:
65 ; FORCED_OPTSIZE-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[N:%.*]], 0, !dbg [[DBG4:![0-9]+]]
66 ; FORCED_OPTSIZE-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_END:%.*]], !dbg [[DBG4]]
67 ; FORCED_OPTSIZE: for.body.preheader:
68 ; FORCED_OPTSIZE-NEXT: br label [[FOR_BODY:%.*]], !dbg [[DBG9:![0-9]+]]
69 ; FORCED_OPTSIZE: for.body:
70 ; FORCED_OPTSIZE-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ], [ 0, [[FOR_BODY_PREHEADER]] ], !dbg [[DBG9]]
71 ; FORCED_OPTSIZE-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds float, ptr [[B:%.*]], i64 [[INDVARS_IV]], !dbg [[DBG9]]
72 ; FORCED_OPTSIZE-NEXT: [[TMP0:%.*]] = load float, ptr [[ARRAYIDX]], align 4, !dbg [[DBG9]]
73 ; FORCED_OPTSIZE-NEXT: [[MUL:%.*]] = fmul float [[TMP0]], 3.000000e+00, !dbg [[DBG9]]
74 ; FORCED_OPTSIZE-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds float, ptr [[A:%.*]], i64 [[INDVARS_IV]], !dbg [[DBG9]]
75 ; FORCED_OPTSIZE-NEXT: store float [[MUL]], ptr [[ARRAYIDX2]], align 4, !dbg [[DBG9]]
76 ; FORCED_OPTSIZE-NEXT: [[INDVARS_IV_NEXT]] = add i64 [[INDVARS_IV]], 1, !dbg [[DBG9]]
77 ; FORCED_OPTSIZE-NEXT: [[LFTR_WIDEIV:%.*]] = trunc i64 [[INDVARS_IV_NEXT]] to i32, !dbg [[DBG9]]
78 ; FORCED_OPTSIZE-NEXT: [[EXITCOND:%.*]] = icmp eq i32 [[LFTR_WIDEIV]], [[N]], !dbg [[DBG9]]
79 ; FORCED_OPTSIZE-NEXT: br i1 [[EXITCOND]], label [[FOR_END_LOOPEXIT:%.*]], label [[FOR_BODY]], !dbg [[DBG9]]
80 ; FORCED_OPTSIZE: for.end.loopexit:
81 ; FORCED_OPTSIZE-NEXT: br label [[FOR_END]], !dbg [[DBG10:![0-9]+]]
82 ; FORCED_OPTSIZE: for.end:
83 ; FORCED_OPTSIZE-NEXT: ret i32 undef, !dbg [[DBG10]]
86 %cmp6 = icmp sgt i32 %n, 0, !dbg !6
87 br i1 %cmp6, label %for.body, label %for.end, !dbg !6
89 for.body: ; preds = %entry, %for.body
90 %indvars.iv = phi i64 [ %indvars.iv.next, %for.body ], [ 0, %entry ], !dbg !7
91 %arrayidx = getelementptr inbounds float, ptr %b, i64 %indvars.iv, !dbg !7
92 %0 = load float, ptr %arrayidx, align 4, !dbg !7
93 %mul = fmul float %0, 3.000000e+00, !dbg !7
94 %arrayidx2 = getelementptr inbounds float, ptr %a, i64 %indvars.iv, !dbg !7
95 store float %mul, ptr %arrayidx2, align 4, !dbg !7
96 %indvars.iv.next = add i64 %indvars.iv, 1, !dbg !7
97 %lftr.wideiv = trunc i64 %indvars.iv.next to i32, !dbg !7
98 %exitcond = icmp eq i32 %lftr.wideiv, %n, !dbg !7
99 br i1 %exitcond, label %for.end, label %for.body, !dbg !7
101 for.end: ; preds = %for.body, %entry
102 ret i32 undef, !dbg !8
105 ; Make sure that we try to vectorize loops with a runtime check if the
106 ; dependency check fails.
108 define void @test_runtime_check(ptr %a, float %b, i64 %offset, i64 %offset2, i64 %n) {
109 ; CHECK-LABEL: @test_runtime_check(
111 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], 4
112 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
113 ; CHECK: vector.memcheck:
114 ; CHECK-NEXT: [[TMP0:%.*]] = shl i64 [[OFFSET:%.*]], 2
115 ; CHECK-NEXT: [[SCEVGEP:%.*]] = getelementptr i8, ptr [[A:%.*]], i64 [[TMP0]]
116 ; CHECK-NEXT: [[TMP1:%.*]] = shl i64 [[N]], 2
117 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr i8, ptr [[A]], i64 [[TMP1]]
118 ; CHECK-NEXT: [[SCEVGEP1:%.*]] = getelementptr i8, ptr [[TMP2]], i64 [[TMP0]]
119 ; CHECK-NEXT: [[TMP3:%.*]] = shl i64 [[OFFSET2:%.*]], 2
120 ; CHECK-NEXT: [[SCEVGEP2:%.*]] = getelementptr i8, ptr [[A]], i64 [[TMP3]]
121 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr i8, ptr [[A]], i64 [[TMP1]]
122 ; CHECK-NEXT: [[SCEVGEP3:%.*]] = getelementptr i8, ptr [[TMP4]], i64 [[TMP3]]
123 ; CHECK-NEXT: [[BOUND0:%.*]] = icmp ult ptr [[SCEVGEP]], [[SCEVGEP3]]
124 ; CHECK-NEXT: [[BOUND1:%.*]] = icmp ult ptr [[SCEVGEP2]], [[SCEVGEP1]]
125 ; CHECK-NEXT: [[FOUND_CONFLICT:%.*]] = and i1 [[BOUND0]], [[BOUND1]]
126 ; CHECK-NEXT: br i1 [[FOUND_CONFLICT]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
128 ; CHECK-NEXT: [[N_VEC:%.*]] = and i64 [[N]], -4
129 ; CHECK-NEXT: [[BROADCAST_SPLATINSERT:%.*]] = insertelement <4 x float> poison, float [[B:%.*]], i64 0
130 ; CHECK-NEXT: [[BROADCAST_SPLAT:%.*]] = shufflevector <4 x float> [[BROADCAST_SPLATINSERT]], <4 x float> poison, <4 x i32> zeroinitializer
131 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
132 ; CHECK: vector.body:
133 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
134 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr float, ptr [[A]], i64 [[INDEX]]
135 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr float, ptr [[TMP5]], i64 [[OFFSET]]
136 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x float>, ptr [[TMP6]], align 4, !alias.scope [[META15:![0-9]+]], !noalias [[META18:![0-9]+]]
137 ; CHECK-NEXT: [[TMP7:%.*]] = getelementptr float, ptr [[A]], i64 [[INDEX]]
138 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr float, ptr [[TMP7]], i64 [[OFFSET2]]
139 ; CHECK-NEXT: [[WIDE_LOAD4:%.*]] = load <4 x float>, ptr [[TMP8]], align 4, !alias.scope [[META18]]
140 ; CHECK-NEXT: [[TMP9:%.*]] = fmul fast <4 x float> [[BROADCAST_SPLAT]], [[WIDE_LOAD4]]
141 ; CHECK-NEXT: [[TMP10:%.*]] = fadd fast <4 x float> [[WIDE_LOAD]], [[TMP9]]
142 ; CHECK-NEXT: store <4 x float> [[TMP10]], ptr [[TMP6]], align 4, !alias.scope [[META15]], !noalias [[META18]]
143 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 4
144 ; CHECK-NEXT: [[TMP11:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
145 ; CHECK-NEXT: br i1 [[TMP11]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP20:![0-9]+]]
146 ; CHECK: middle.block:
147 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]]
148 ; CHECK-NEXT: br i1 [[CMP_N]], label [[LOOPEXIT:%.*]], label [[SCALAR_PH]]
150 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_MEMCHECK]] ]
151 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
153 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
154 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr float, ptr [[A]], i64 [[IV]]
155 ; CHECK-NEXT: [[ARR_IDX:%.*]] = getelementptr float, ptr [[TMP12]], i64 [[OFFSET]]
156 ; CHECK-NEXT: [[L1:%.*]] = load float, ptr [[ARR_IDX]], align 4
157 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr float, ptr [[A]], i64 [[IV]]
158 ; CHECK-NEXT: [[ARR_IDX2:%.*]] = getelementptr float, ptr [[TMP13]], i64 [[OFFSET2]]
159 ; CHECK-NEXT: [[L2:%.*]] = load float, ptr [[ARR_IDX2]], align 4
160 ; CHECK-NEXT: [[M:%.*]] = fmul fast float [[B]], [[L2]]
161 ; CHECK-NEXT: [[AD:%.*]] = fadd fast float [[L1]], [[M]]
162 ; CHECK-NEXT: store float [[AD]], ptr [[ARR_IDX]], align 4
163 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
164 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
165 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP21:![0-9]+]]
167 ; CHECK-NEXT: ret void
169 ; FORCED_OPTSIZE-LABEL: @test_runtime_check(
170 ; FORCED_OPTSIZE-NEXT: entry:
171 ; FORCED_OPTSIZE-NEXT: br label [[FOR_BODY:%.*]]
172 ; FORCED_OPTSIZE: for.body:
173 ; FORCED_OPTSIZE-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
174 ; FORCED_OPTSIZE-NEXT: [[IND_SUM:%.*]] = add i64 [[IV]], [[OFFSET:%.*]]
175 ; FORCED_OPTSIZE-NEXT: [[ARR_IDX:%.*]] = getelementptr inbounds float, ptr [[A:%.*]], i64 [[IND_SUM]]
176 ; FORCED_OPTSIZE-NEXT: [[L1:%.*]] = load float, ptr [[ARR_IDX]], align 4
177 ; FORCED_OPTSIZE-NEXT: [[IND_SUM2:%.*]] = add i64 [[IV]], [[OFFSET2:%.*]]
178 ; FORCED_OPTSIZE-NEXT: [[ARR_IDX2:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[IND_SUM2]]
179 ; FORCED_OPTSIZE-NEXT: [[L2:%.*]] = load float, ptr [[ARR_IDX2]], align 4
180 ; FORCED_OPTSIZE-NEXT: [[M:%.*]] = fmul fast float [[B:%.*]], [[L2]]
181 ; FORCED_OPTSIZE-NEXT: [[AD:%.*]] = fadd fast float [[L1]], [[M]]
182 ; FORCED_OPTSIZE-NEXT: store float [[AD]], ptr [[ARR_IDX]], align 4
183 ; FORCED_OPTSIZE-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
184 ; FORCED_OPTSIZE-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N:%.*]]
185 ; FORCED_OPTSIZE-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT:%.*]], label [[FOR_BODY]]
186 ; FORCED_OPTSIZE: loopexit:
187 ; FORCED_OPTSIZE-NEXT: ret void
193 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
194 %ind.sum = add i64 %iv, %offset
195 %arr.idx = getelementptr inbounds float, ptr %a, i64 %ind.sum
196 %l1 = load float, ptr %arr.idx, align 4
197 %ind.sum2 = add i64 %iv, %offset2
198 %arr.idx2 = getelementptr inbounds float, ptr %a, i64 %ind.sum2
199 %l2 = load float, ptr %arr.idx2, align 4
200 %m = fmul fast float %b, %l2
201 %ad = fadd fast float %l1, %m
202 store float %ad, ptr %arr.idx, align 4
203 %iv.next = add nuw nsw i64 %iv, 1
204 %exitcond = icmp eq i64 %iv.next, %n
205 br i1 %exitcond, label %loopexit, label %for.body
211 ; Check we do not generate runtime checks if we found a known dependence preventing
212 ; vectorization. In this case, it is a read of c[i-1] followed by a write of c[i].
213 ; The runtime checks would always fail.
215 ; void test_runtime_check2(float *a, float b, unsigned offset, unsigned offset2, unsigned n, float *c) {
216 ; for (unsigned i = 1; i < n; i++) {
217 ; a[i+o1] += a[i+o2] + b;
222 define void @test_runtime_check2(ptr %a, float %b, i64 %offset, i64 %offset2, i64 %n, ptr %c) {
223 ; CHECK-LABEL: @test_runtime_check2(
225 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
227 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
228 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr float, ptr [[A:%.*]], i64 [[IV]]
229 ; CHECK-NEXT: [[ARR_IDX:%.*]] = getelementptr float, ptr [[TMP0]], i64 [[OFFSET:%.*]]
230 ; CHECK-NEXT: [[L1:%.*]] = load float, ptr [[ARR_IDX]], align 4
231 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr float, ptr [[A]], i64 [[IV]]
232 ; CHECK-NEXT: [[ARR_IDX2:%.*]] = getelementptr float, ptr [[TMP1]], i64 [[OFFSET2:%.*]]
233 ; CHECK-NEXT: [[L2:%.*]] = load float, ptr [[ARR_IDX2]], align 4
234 ; CHECK-NEXT: [[M:%.*]] = fmul fast float [[B:%.*]], [[L2]]
235 ; CHECK-NEXT: [[AD:%.*]] = fadd fast float [[L1]], [[M]]
236 ; CHECK-NEXT: store float [[AD]], ptr [[ARR_IDX]], align 4
237 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr float, ptr [[C:%.*]], i64 [[IV]]
238 ; CHECK-NEXT: [[C_IDX:%.*]] = getelementptr i8, ptr [[TMP2]], i64 -4
239 ; CHECK-NEXT: [[LC:%.*]] = load float, ptr [[C_IDX]], align 4
240 ; CHECK-NEXT: [[VC:%.*]] = fadd float [[LC]], 1.000000e+00
241 ; CHECK-NEXT: [[C_IDX2:%.*]] = getelementptr inbounds nuw float, ptr [[C]], i64 [[IV]]
242 ; CHECK-NEXT: store float [[VC]], ptr [[C_IDX2]], align 4
243 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
244 ; CHECK-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N:%.*]]
245 ; CHECK-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT:%.*]], label [[FOR_BODY]]
247 ; CHECK-NEXT: ret void
249 ; FORCED_OPTSIZE-LABEL: @test_runtime_check2(
250 ; FORCED_OPTSIZE-NEXT: entry:
251 ; FORCED_OPTSIZE-NEXT: br label [[FOR_BODY:%.*]]
252 ; FORCED_OPTSIZE: for.body:
253 ; FORCED_OPTSIZE-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
254 ; FORCED_OPTSIZE-NEXT: [[IND_SUM:%.*]] = add i64 [[IV]], [[OFFSET:%.*]]
255 ; FORCED_OPTSIZE-NEXT: [[ARR_IDX:%.*]] = getelementptr inbounds float, ptr [[A:%.*]], i64 [[IND_SUM]]
256 ; FORCED_OPTSIZE-NEXT: [[L1:%.*]] = load float, ptr [[ARR_IDX]], align 4
257 ; FORCED_OPTSIZE-NEXT: [[IND_SUM2:%.*]] = add i64 [[IV]], [[OFFSET2:%.*]]
258 ; FORCED_OPTSIZE-NEXT: [[ARR_IDX2:%.*]] = getelementptr inbounds float, ptr [[A]], i64 [[IND_SUM2]]
259 ; FORCED_OPTSIZE-NEXT: [[L2:%.*]] = load float, ptr [[ARR_IDX2]], align 4
260 ; FORCED_OPTSIZE-NEXT: [[M:%.*]] = fmul fast float [[B:%.*]], [[L2]]
261 ; FORCED_OPTSIZE-NEXT: [[AD:%.*]] = fadd fast float [[L1]], [[M]]
262 ; FORCED_OPTSIZE-NEXT: store float [[AD]], ptr [[ARR_IDX]], align 4
263 ; FORCED_OPTSIZE-NEXT: [[C_IND:%.*]] = add i64 [[IV]], -1
264 ; FORCED_OPTSIZE-NEXT: [[C_IDX:%.*]] = getelementptr inbounds float, ptr [[C:%.*]], i64 [[C_IND]]
265 ; FORCED_OPTSIZE-NEXT: [[LC:%.*]] = load float, ptr [[C_IDX]], align 4
266 ; FORCED_OPTSIZE-NEXT: [[VC:%.*]] = fadd float [[LC]], 1.000000e+00
267 ; FORCED_OPTSIZE-NEXT: [[C_IDX2:%.*]] = getelementptr inbounds float, ptr [[C]], i64 [[IV]]
268 ; FORCED_OPTSIZE-NEXT: store float [[VC]], ptr [[C_IDX2]], align 4
269 ; FORCED_OPTSIZE-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
270 ; FORCED_OPTSIZE-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[IV_NEXT]], [[N:%.*]]
271 ; FORCED_OPTSIZE-NEXT: br i1 [[EXITCOND]], label [[LOOPEXIT:%.*]], label [[FOR_BODY]]
272 ; FORCED_OPTSIZE: loopexit:
273 ; FORCED_OPTSIZE-NEXT: ret void
279 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
280 %ind.sum = add i64 %iv, %offset
281 %arr.idx = getelementptr inbounds float, ptr %a, i64 %ind.sum
282 %l1 = load float, ptr %arr.idx, align 4
283 %ind.sum2 = add i64 %iv, %offset2
284 %arr.idx2 = getelementptr inbounds float, ptr %a, i64 %ind.sum2
285 %l2 = load float, ptr %arr.idx2, align 4
286 %m = fmul fast float %b, %l2
287 %ad = fadd fast float %l1, %m
288 store float %ad, ptr %arr.idx, align 4
289 %c.ind = add i64 %iv, -1
290 %c.idx = getelementptr inbounds float, ptr %c, i64 %c.ind
291 %lc = load float, ptr %c.idx, align 4
292 %vc = fadd float %lc, 1.0
293 %c.idx2 = getelementptr inbounds float, ptr %c, i64 %iv
294 store float %vc, ptr %c.idx2
295 %iv.next = add nuw nsw i64 %iv, 1
296 %exitcond = icmp eq i64 %iv.next, %n
297 br i1 %exitcond, label %loopexit, label %for.body
304 define dso_local void @forced_optsize(ptr noalias nocapture readonly %x_p, ptr noalias nocapture readonly %y_p, ptr noalias nocapture %z_p) minsize optsize {
305 ; CHECK-LABEL: @forced_optsize(
307 ; CHECK-NEXT: br i1 false, label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
309 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
310 ; CHECK: vector.body:
311 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
312 ; CHECK-NEXT: [[TMP0:%.*]] = getelementptr inbounds i64, ptr [[X_P:%.*]], i64 [[INDEX]]
313 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <2 x i64>, ptr [[TMP0]], align 8
314 ; CHECK-NEXT: [[TMP1:%.*]] = getelementptr inbounds i64, ptr [[Y_P:%.*]], i64 [[INDEX]]
315 ; CHECK-NEXT: [[WIDE_LOAD1:%.*]] = load <2 x i64>, ptr [[TMP1]], align 8
316 ; CHECK-NEXT: [[TMP2:%.*]] = add nsw <2 x i64> [[WIDE_LOAD1]], [[WIDE_LOAD]]
317 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds i64, ptr [[Z_P:%.*]], i64 [[INDEX]]
318 ; CHECK-NEXT: store <2 x i64> [[TMP2]], ptr [[TMP3]], align 8
319 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
320 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i64 [[INDEX_NEXT]], 128
321 ; CHECK-NEXT: br i1 [[TMP4]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP22:![0-9]+]]
322 ; CHECK: middle.block:
323 ; CHECK-NEXT: br i1 true, label [[FOR_COND_CLEANUP:%.*]], label [[SCALAR_PH]]
325 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
326 ; CHECK: for.cond.cleanup:
327 ; CHECK-NEXT: ret void
329 ; CHECK-NEXT: br i1 poison, label [[FOR_COND_CLEANUP]], label [[FOR_BODY]], !llvm.loop [[LOOP23:![0-9]+]]
331 ; FORCED_OPTSIZE-LABEL: @forced_optsize(
332 ; FORCED_OPTSIZE-NEXT: entry:
333 ; FORCED_OPTSIZE-NEXT: br label [[FOR_BODY:%.*]]
334 ; FORCED_OPTSIZE: for.cond.cleanup:
335 ; FORCED_OPTSIZE-NEXT: ret void
336 ; FORCED_OPTSIZE: for.body:
337 ; FORCED_OPTSIZE-NEXT: [[INDVARS_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[INDVARS_IV_NEXT:%.*]], [[FOR_BODY]] ]
338 ; FORCED_OPTSIZE-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[X_P:%.*]], i64 [[INDVARS_IV]]
339 ; FORCED_OPTSIZE-NEXT: [[TMP0:%.*]] = load i64, ptr [[ARRAYIDX]], align 8
340 ; FORCED_OPTSIZE-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i64, ptr [[Y_P:%.*]], i64 [[INDVARS_IV]]
341 ; FORCED_OPTSIZE-NEXT: [[TMP1:%.*]] = load i64, ptr [[ARRAYIDX2]], align 8
342 ; FORCED_OPTSIZE-NEXT: [[ADD:%.*]] = add nsw i64 [[TMP1]], [[TMP0]]
343 ; FORCED_OPTSIZE-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds i64, ptr [[Z_P:%.*]], i64 [[INDVARS_IV]]
344 ; FORCED_OPTSIZE-NEXT: store i64 [[ADD]], ptr [[ARRAYIDX4]], align 8
345 ; FORCED_OPTSIZE-NEXT: [[INDVARS_IV_NEXT]] = add nuw nsw i64 [[INDVARS_IV]], 1
346 ; FORCED_OPTSIZE-NEXT: [[EXITCOND:%.*]] = icmp eq i64 [[INDVARS_IV_NEXT]], 128
347 ; FORCED_OPTSIZE-NEXT: br i1 [[EXITCOND]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]], !llvm.loop [[LOOP11:![0-9]+]]
356 %indvars.iv = phi i64 [ 0, %entry ], [ %indvars.iv.next, %for.body ]
357 %arrayidx = getelementptr inbounds i64, ptr %x_p, i64 %indvars.iv
358 %0 = load i64, ptr %arrayidx, align 8
359 %arrayidx2 = getelementptr inbounds i64, ptr %y_p, i64 %indvars.iv
360 %1 = load i64, ptr %arrayidx2, align 8
361 %add = add nsw i64 %1, %0
362 %arrayidx4 = getelementptr inbounds i64, ptr %z_p, i64 %indvars.iv
363 store i64 %add, ptr %arrayidx4, align 8
364 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
365 %exitcond = icmp eq i64 %indvars.iv.next, 128
366 br i1 %exitcond, label %for.cond.cleanup, label %for.body, !llvm.loop !12
369 ; CHECK: !9 = !DILocation(line: 101, column: 1, scope: !{{.*}})
371 !llvm.module.flags = !{!0, !1}
373 !0 = !{i32 2, !"Dwarf Version", i32 4}
374 !1 = !{i32 2, !"Debug Info Version", i32 3}
377 !3 = !DISubroutineType(types: !2)
378 !4 = !DIFile(filename: "test.cpp", directory: "/tmp")
379 !5 = distinct !DISubprogram(name: "foo", scope: !4, file: !4, line: 99, type: !3, isLocal: false, isDefinition: true, scopeLine: 100, flags: DIFlagPrototyped, isOptimized: false, unit: !9, retainedNodes: !2)
380 !6 = !DILocation(line: 100, column: 1, scope: !5)
381 !7 = !DILocation(line: 101, column: 1, scope: !5)
382 !8 = !DILocation(line: 102, column: 1, scope: !5)
383 !9 = distinct !DICompileUnit(language: DW_LANG_C99, producer: "clang",
385 isOptimized: true, flags: "-O2",
386 splitDebugFilename: "abc.debug", emissionKind: 2)
387 !10 = !DIFile(filename: "path/to/file", directory: "/path/to/dir")
388 !11 = !{i32 2, !"Debug Info Version", i32 3}
389 !12 = distinct !{!12, !13, !14}
390 !13 = !{!"llvm.loop.vectorize.width", i32 2}
391 !14 = !{!"llvm.loop.vectorize.enable", i1 true}