1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --replace-value-regex "!llvm.loop ![0-9]+" --version 5
2 ; RUN: opt -S -passes=loop-vectorize -force-vector-interleave=1 -force-vector-width=2 < %s | FileCheck --check-prefixes=CHECK,VEC %s
3 ; RUN: opt -S -passes=loop-vectorize -force-vector-interleave=2 -force-vector-width=1 < %s | FileCheck --check-prefixes=CHECK %s
5 define i32 @postinc(i32 %k) {
6 ; CHECK-LABEL: define i32 @postinc(
7 ; CHECK-SAME: i32 [[K:%.*]]) {
8 ; CHECK-NEXT: [[ENTRY:.*]]:
9 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[K]], 2
10 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
11 ; CHECK: [[VECTOR_PH]]:
12 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[K]], 2
13 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[K]], [[N_MOD_VF]]
14 ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
15 ; CHECK: [[VECTOR_BODY]]:
16 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
17 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
18 ; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
19 ; CHECK-NEXT: br i1 [[TMP0]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], {{!llvm.loop ![0-9]+}}
20 ; CHECK: [[MIDDLE_BLOCK]]:
21 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[K]], [[N_VEC]]
22 ; CHECK-NEXT: br i1 [[CMP_N]], label %[[FOR_END:.*]], label %[[SCALAR_PH]]
23 ; CHECK: [[SCALAR_PH]]:
24 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
25 ; CHECK-NEXT: br label %[[FOR_BODY:.*]]
26 ; CHECK: [[FOR_BODY]]:
27 ; CHECK-NEXT: [[INC_PHI:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[INC:%.*]], %[[FOR_BODY]] ]
28 ; CHECK-NEXT: [[INC]] = add nsw i32 [[INC_PHI]], 1
29 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[INC]], [[K]]
30 ; CHECK-NEXT: br i1 [[CMP]], label %[[FOR_END]], label %[[FOR_BODY]], {{!llvm.loop ![0-9]+}}
32 ; CHECK-NEXT: [[INC_LCSSA:%.*]] = phi i32 [ [[INC]], %[[FOR_BODY]] ], [ [[N_VEC]], %[[MIDDLE_BLOCK]] ]
33 ; CHECK-NEXT: ret i32 [[INC_LCSSA]]
39 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ]
40 %inc = add nsw i32 %inc.phi, 1
41 %cmp = icmp eq i32 %inc, %k
42 br i1 %cmp, label %for.end, label %for.body
48 define i32 @preinc(i32 %k) {
49 ; CHECK-LABEL: define i32 @preinc(
50 ; CHECK-SAME: i32 [[K:%.*]]) {
51 ; CHECK-NEXT: [[ENTRY:.*]]:
52 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[K]], 2
53 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
54 ; CHECK: [[VECTOR_PH]]:
55 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[K]], 2
56 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[K]], [[N_MOD_VF]]
57 ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
58 ; CHECK: [[VECTOR_BODY]]:
59 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
60 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
61 ; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
62 ; CHECK-NEXT: br i1 [[TMP0]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], {{!llvm.loop ![0-9]+}}
63 ; CHECK: [[MIDDLE_BLOCK]]:
64 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[K]], [[N_VEC]]
65 ; CHECK-NEXT: [[IND_ESCAPE:%.*]] = sub i32 [[N_VEC]], 1
66 ; CHECK-NEXT: br i1 [[CMP_N]], label %[[FOR_END:.*]], label %[[SCALAR_PH]]
67 ; CHECK: [[SCALAR_PH]]:
68 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
69 ; CHECK-NEXT: br label %[[FOR_BODY:.*]]
70 ; CHECK: [[FOR_BODY]]:
71 ; CHECK-NEXT: [[INC_PHI:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[INC:%.*]], %[[FOR_BODY]] ]
72 ; CHECK-NEXT: [[INC]] = add nsw i32 [[INC_PHI]], 1
73 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[INC]], [[K]]
74 ; CHECK-NEXT: br i1 [[CMP]], label %[[FOR_END]], label %[[FOR_BODY]], {{!llvm.loop ![0-9]+}}
76 ; CHECK-NEXT: [[INC_PHI_LCSSA:%.*]] = phi i32 [ [[INC_PHI]], %[[FOR_BODY]] ], [ [[IND_ESCAPE]], %[[MIDDLE_BLOCK]] ]
77 ; CHECK-NEXT: ret i32 [[INC_PHI_LCSSA]]
83 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ]
84 %inc = add nsw i32 %inc.phi, 1
85 %cmp = icmp eq i32 %inc, %k
86 br i1 %cmp, label %for.end, label %for.body
92 define i32 @constpre() {
93 ; CHECK-LABEL: define i32 @constpre() {
94 ; CHECK-NEXT: [[ENTRY:.*]]:
95 ; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
96 ; CHECK: [[VECTOR_PH]]:
97 ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
98 ; CHECK: [[VECTOR_BODY]]:
99 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
100 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
101 ; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[INDEX_NEXT]], 16
102 ; CHECK-NEXT: br i1 [[TMP0]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], {{!llvm.loop ![0-9]+}}
103 ; CHECK: [[MIDDLE_BLOCK]]:
104 ; CHECK-NEXT: br i1 true, label %[[FOR_END:.*]], label %[[SCALAR_PH]]
105 ; CHECK: [[SCALAR_PH]]:
106 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 0, %[[MIDDLE_BLOCK]] ], [ 32, %[[ENTRY]] ]
107 ; CHECK-NEXT: br label %[[FOR_BODY:.*]]
108 ; CHECK: [[FOR_BODY]]:
109 ; CHECK-NEXT: [[INC_PHI:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[INC:%.*]], %[[FOR_BODY]] ]
110 ; CHECK-NEXT: [[INC]] = sub nsw i32 [[INC_PHI]], 2
111 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[INC]], 0
112 ; CHECK-NEXT: br i1 [[CMP]], label %[[FOR_END]], label %[[FOR_BODY]], {{!llvm.loop ![0-9]+}}
113 ; CHECK: [[FOR_END]]:
114 ; CHECK-NEXT: [[INC_PHI_LCSSA:%.*]] = phi i32 [ [[INC_PHI]], %[[FOR_BODY]] ], [ 2, %[[MIDDLE_BLOCK]] ]
115 ; CHECK-NEXT: ret i32 [[INC_PHI_LCSSA]]
121 %inc.phi = phi i32 [ 32, %entry ], [ %inc, %for.body ]
122 %inc = sub nsw i32 %inc.phi, 2
123 %cmp = icmp eq i32 %inc, 0
124 br i1 %cmp, label %for.end, label %for.body
130 define ptr @geppre(ptr %ptr) {
131 ; CHECK-LABEL: define ptr @geppre(
132 ; CHECK-SAME: ptr [[PTR:%.*]]) {
133 ; CHECK-NEXT: [[ENTRY:.*]]:
134 ; CHECK-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
135 ; CHECK: [[VECTOR_PH]]:
136 ; CHECK-NEXT: [[IND_END:%.*]] = getelementptr i8, ptr [[PTR]], i64 512
137 ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
138 ; CHECK: [[VECTOR_BODY]]:
139 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
140 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
141 ; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i64 [[INDEX_NEXT]], 32
142 ; CHECK-NEXT: br i1 [[TMP0]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], {{!llvm.loop ![0-9]+}}
143 ; CHECK: [[MIDDLE_BLOCK]]:
144 ; CHECK-NEXT: [[IND_ESCAPE:%.*]] = getelementptr i8, ptr [[IND_END]], i64 -16
145 ; CHECK-NEXT: br i1 true, label %[[FOR_END:.*]], label %[[SCALAR_PH]]
146 ; CHECK: [[SCALAR_PH]]:
147 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ 32, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
148 ; CHECK-NEXT: [[BC_RESUME_VAL1:%.*]] = phi ptr [ [[IND_END]], %[[MIDDLE_BLOCK]] ], [ [[PTR]], %[[ENTRY]] ]
149 ; CHECK-NEXT: br label %[[FOR_BODY:.*]]
150 ; CHECK: [[FOR_BODY]]:
151 ; CHECK-NEXT: [[INC_PHI:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[INC:%.*]], %[[FOR_BODY]] ]
152 ; CHECK-NEXT: [[PTR_PHI:%.*]] = phi ptr [ [[BC_RESUME_VAL1]], %[[SCALAR_PH]] ], [ [[INC_PTR:%.*]], %[[FOR_BODY]] ]
153 ; CHECK-NEXT: [[INC]] = add nsw i32 [[INC_PHI]], 1
154 ; CHECK-NEXT: [[INC_PTR]] = getelementptr i32, ptr [[PTR_PHI]], i32 4
155 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[INC]], 32
156 ; CHECK-NEXT: br i1 [[CMP]], label %[[FOR_END]], label %[[FOR_BODY]], {{!llvm.loop ![0-9]+}}
157 ; CHECK: [[FOR_END]]:
158 ; CHECK-NEXT: [[PTR_PHI_LCSSA:%.*]] = phi ptr [ [[PTR_PHI]], %[[FOR_BODY]] ], [ [[IND_ESCAPE]], %[[MIDDLE_BLOCK]] ]
159 ; CHECK-NEXT: ret ptr [[PTR_PHI_LCSSA]]
165 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ]
166 %ptr.phi = phi ptr [ %ptr, %entry ], [ %inc.ptr, %for.body ]
167 %inc = add nsw i32 %inc.phi, 1
168 %inc.ptr = getelementptr i32, ptr %ptr.phi, i32 4
169 %cmp = icmp eq i32 %inc, 32
170 br i1 %cmp, label %for.end, label %for.body
176 define ptr @both(i32 %k) {
177 ; CHECK-LABEL: define ptr @both(
178 ; CHECK-SAME: i32 [[K:%.*]]) {
179 ; CHECK-NEXT: [[ENTRY:.*]]:
180 ; CHECK-NEXT: [[BASE:%.*]] = getelementptr inbounds i32, ptr undef, i64 1
181 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[K]], -1
182 ; CHECK-NEXT: [[TMP1:%.*]] = zext i32 [[TMP0]] to i64
183 ; CHECK-NEXT: [[TMP2:%.*]] = add nuw nsw i64 [[TMP1]], 1
184 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[TMP2]], 2
185 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
186 ; CHECK: [[VECTOR_PH]]:
187 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[TMP2]], 2
188 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[TMP2]], [[N_MOD_VF]]
189 ; CHECK-NEXT: [[IND_END:%.*]] = trunc i64 [[N_VEC]] to i32
190 ; CHECK-NEXT: [[TMP3:%.*]] = mul i64 [[N_VEC]], 4
191 ; CHECK-NEXT: [[IND_END1:%.*]] = getelementptr i8, ptr [[BASE]], i64 [[TMP3]]
192 ; CHECK-NEXT: [[TMP4:%.*]] = mul i64 [[N_VEC]], 4
193 ; CHECK-NEXT: [[IND_END2:%.*]] = getelementptr i8, ptr undef, i64 [[TMP4]]
194 ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
195 ; CHECK: [[VECTOR_BODY]]:
196 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
197 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
198 ; CHECK-NEXT: [[TMP5:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
199 ; CHECK-NEXT: br i1 [[TMP5]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], {{!llvm.loop ![0-9]+}}
200 ; CHECK: [[MIDDLE_BLOCK]]:
201 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[TMP2]], [[N_VEC]]
202 ; CHECK-NEXT: [[IND_ESCAPE:%.*]] = getelementptr i8, ptr [[IND_END1]], i64 -4
203 ; CHECK-NEXT: br i1 [[CMP_N]], label %[[FOR_END:.*]], label %[[SCALAR_PH]]
204 ; CHECK: [[SCALAR_PH]]:
205 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[IND_END]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
206 ; CHECK-NEXT: [[BC_RESUME_VAL2:%.*]] = phi ptr [ [[IND_END1]], %[[MIDDLE_BLOCK]] ], [ [[BASE]], %[[ENTRY]] ]
207 ; CHECK-NEXT: [[BC_RESUME_VAL4:%.*]] = phi ptr [ [[IND_END2]], %[[MIDDLE_BLOCK]] ], [ undef, %[[ENTRY]] ]
208 ; CHECK-NEXT: br label %[[FOR_BODY:.*]]
209 ; CHECK: [[FOR_BODY]]:
210 ; CHECK-NEXT: [[INC_PHI:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[INC:%.*]], %[[FOR_BODY]] ]
211 ; CHECK-NEXT: [[INC_LAG1:%.*]] = phi ptr [ [[BC_RESUME_VAL2]], %[[SCALAR_PH]] ], [ [[TMP:%.*]], %[[FOR_BODY]] ]
212 ; CHECK-NEXT: [[INC_LAG2:%.*]] = phi ptr [ [[BC_RESUME_VAL4]], %[[SCALAR_PH]] ], [ [[INC_LAG1]], %[[FOR_BODY]] ]
213 ; CHECK-NEXT: [[TMP]] = getelementptr inbounds i32, ptr [[INC_LAG1]], i64 1
214 ; CHECK-NEXT: [[INC]] = add nsw i32 [[INC_PHI]], 1
215 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[INC]], [[K]]
216 ; CHECK-NEXT: br i1 [[CMP]], label %[[FOR_END]], label %[[FOR_BODY]], {{!llvm.loop ![0-9]+}}
217 ; CHECK: [[FOR_END]]:
218 ; CHECK-NEXT: [[INC_LAG1_LCSSA:%.*]] = phi ptr [ [[INC_LAG1]], %[[FOR_BODY]] ], [ [[IND_ESCAPE]], %[[MIDDLE_BLOCK]] ]
219 ; CHECK-NEXT: ret ptr [[INC_LAG1_LCSSA]]
222 %base = getelementptr inbounds i32, ptr undef, i64 1
226 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ]
227 %inc.lag1 = phi ptr [ %base, %entry ], [ %tmp, %for.body]
228 %inc.lag2 = phi ptr [ undef, %entry ], [ %inc.lag1, %for.body]
229 %tmp = getelementptr inbounds i32, ptr %inc.lag1, i64 1
230 %inc = add nsw i32 %inc.phi, 1
231 %cmp = icmp eq i32 %inc, %k
232 br i1 %cmp, label %for.end, label %for.body
238 define i32 @multiphi(i32 %k, ptr %p) {
239 ; CHECK-LABEL: define i32 @multiphi(
240 ; CHECK-SAME: i32 [[K:%.*]], ptr [[P:%.*]]) {
241 ; CHECK-NEXT: [[ENTRY:.*]]:
242 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[K]], 2
243 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
244 ; CHECK: [[VECTOR_PH]]:
245 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[K]], 2
246 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[K]], [[N_MOD_VF]]
247 ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
248 ; CHECK: [[VECTOR_BODY]]:
249 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
250 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
251 ; CHECK-NEXT: [[TMP0:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
252 ; CHECK-NEXT: br i1 [[TMP0]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], {{!llvm.loop ![0-9]+}}
253 ; CHECK: [[MIDDLE_BLOCK]]:
254 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[K]], [[N_VEC]]
255 ; CHECK-NEXT: br i1 [[CMP_N]], label %[[FOR_END:.*]], label %[[SCALAR_PH]]
256 ; CHECK: [[SCALAR_PH]]:
257 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
258 ; CHECK-NEXT: br label %[[FOR_BODY:.*]]
259 ; CHECK: [[FOR_BODY]]:
260 ; CHECK-NEXT: [[INC_PHI:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[INC:%.*]], %[[FOR_BODY]] ]
261 ; CHECK-NEXT: [[INC]] = add nsw i32 [[INC_PHI]], 1
262 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[INC]], [[K]]
263 ; CHECK-NEXT: br i1 [[CMP]], label %[[FOR_END]], label %[[FOR_BODY]], {{!llvm.loop ![0-9]+}}
264 ; CHECK: [[FOR_END]]:
265 ; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[INC]], %[[FOR_BODY]] ], [ [[N_VEC]], %[[MIDDLE_BLOCK]] ]
266 ; CHECK-NEXT: [[PHI2:%.*]] = phi i32 [ [[INC]], %[[FOR_BODY]] ], [ [[N_VEC]], %[[MIDDLE_BLOCK]] ]
267 ; CHECK-NEXT: store i32 [[PHI2]], ptr [[P]], align 4
268 ; CHECK-NEXT: ret i32 [[PHI]]
274 %inc.phi = phi i32 [ 0, %entry ], [ %inc, %for.body ]
275 %inc = add nsw i32 %inc.phi, 1
276 %cmp = icmp eq i32 %inc, %k
277 br i1 %cmp, label %for.end, label %for.body
280 %phi = phi i32 [ %inc, %for.body ]
281 %phi2 = phi i32 [ %inc, %for.body ]
282 store i32 %phi2, ptr %p
286 define void @PR30742() {
287 ; CHECK-LABEL: define void @PR30742() {
288 ; CHECK-NEXT: [[BB0:.*:]]
289 ; CHECK-NEXT: br label %[[BB1:.*]]
290 ; CHECK: [[BB1_LOOPEXIT:.*]]:
291 ; CHECK-NEXT: br label %[[BB1]]
293 ; CHECK-NEXT: [[TMP00:%.*]] = load i32, ptr undef, align 16
294 ; CHECK-NEXT: [[TMP01:%.*]] = sub i32 [[TMP00]], undef
295 ; CHECK-NEXT: [[TMP02:%.*]] = icmp slt i32 [[TMP01]], 1
296 ; CHECK-NEXT: [[TMP03:%.*]] = select i1 [[TMP02]], i32 1, i32 [[TMP01]]
297 ; CHECK-NEXT: [[TMP04:%.*]] = add nsw i32 [[TMP03]], -7
298 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[TMP03]], -8
299 ; CHECK-NEXT: [[TMP1:%.*]] = add nsw i32 [[TMP03]], -15
300 ; CHECK-NEXT: [[SMIN1:%.*]] = call i32 @llvm.smin.i32(i32 [[TMP1]], i32 0)
301 ; CHECK-NEXT: [[TMP2:%.*]] = sub i32 [[TMP0]], [[SMIN1]]
302 ; CHECK-NEXT: [[TMP3:%.*]] = lshr i32 [[TMP2]], 3
303 ; CHECK-NEXT: [[TMP4:%.*]] = add nuw nsw i32 [[TMP3]], 1
304 ; CHECK-NEXT: [[MIN_ITERS_CHECK4:%.*]] = icmp ult i32 [[TMP4]], 2
305 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK4]], label %[[SCALAR_PH3:.*]], label %[[VECTOR_PH5:.*]]
306 ; CHECK: [[VECTOR_PH5]]:
307 ; CHECK-NEXT: [[N_MOD_VF6:%.*]] = urem i32 [[TMP4]], 2
308 ; CHECK-NEXT: [[N_VEC7:%.*]] = sub i32 [[TMP4]], [[N_MOD_VF6]]
309 ; CHECK-NEXT: [[TMP5:%.*]] = mul i32 [[N_VEC7]], -8
310 ; CHECK-NEXT: [[IND_END8:%.*]] = add i32 [[TMP04]], [[TMP5]]
311 ; CHECK-NEXT: br label %[[VECTOR_BODY10:.*]]
312 ; CHECK: [[VECTOR_BODY10]]:
313 ; CHECK-NEXT: [[INDEX10:%.*]] = phi i32 [ 0, %[[VECTOR_PH5]] ], [ [[INDEX_NEXT11:%.*]], %[[VECTOR_BODY10]] ]
314 ; CHECK-NEXT: [[INDEX_NEXT11]] = add nuw i32 [[INDEX10]], 2
315 ; CHECK-NEXT: [[TMP6:%.*]] = icmp eq i32 [[INDEX_NEXT11]], [[N_VEC7]]
316 ; CHECK-NEXT: br i1 [[TMP6]], label %[[MIDDLE_BLOCK2:.*]], label %[[VECTOR_BODY10]], {{!llvm.loop ![0-9]+}}
317 ; CHECK: [[MIDDLE_BLOCK2]]:
318 ; CHECK-NEXT: [[CMP_N12:%.*]] = icmp eq i32 [[TMP4]], [[N_VEC7]]
319 ; CHECK-NEXT: [[IND_ESCAPE:%.*]] = sub i32 [[IND_END8]], -8
320 ; CHECK-NEXT: br i1 [[CMP_N12]], label %[[BB3:.*]], label %[[SCALAR_PH3]]
321 ; CHECK: [[SCALAR_PH3]]:
322 ; CHECK-NEXT: [[BC_RESUME_VAL9:%.*]] = phi i32 [ [[IND_END8]], %[[MIDDLE_BLOCK2]] ], [ [[TMP04]], %[[BB1]] ]
323 ; CHECK-NEXT: br label %[[BB2:.*]]
325 ; CHECK-NEXT: [[TMP05:%.*]] = phi i32 [ [[BC_RESUME_VAL9]], %[[SCALAR_PH3]] ], [ [[TMP06:%.*]], %[[BB2]] ]
326 ; CHECK-NEXT: [[TMP06]] = add i32 [[TMP05]], -8
327 ; CHECK-NEXT: [[TMP07:%.*]] = icmp sgt i32 [[TMP06]], 0
328 ; CHECK-NEXT: br i1 [[TMP07]], label %[[BB2]], label %[[BB3]], {{!llvm.loop ![0-9]+}}
330 ; CHECK-NEXT: [[TMP08:%.*]] = phi i32 [ [[TMP05]], %[[BB2]] ], [ [[IND_ESCAPE]], %[[MIDDLE_BLOCK2]] ]
331 ; CHECK-NEXT: [[TMP09:%.*]] = sub i32 [[TMP00]], undef
332 ; CHECK-NEXT: [[TMP10:%.*]] = icmp slt i32 [[TMP09]], 1
333 ; CHECK-NEXT: [[TMP11:%.*]] = select i1 [[TMP10]], i32 1, i32 [[TMP09]]
334 ; CHECK-NEXT: [[TMP12:%.*]] = add nsw i32 [[TMP11]], -7
335 ; CHECK-NEXT: [[TMP7:%.*]] = add i32 [[TMP11]], -8
336 ; CHECK-NEXT: [[TMP8:%.*]] = add nsw i32 [[TMP11]], -15
337 ; CHECK-NEXT: [[SMIN:%.*]] = call i32 @llvm.smin.i32(i32 [[TMP8]], i32 0)
338 ; CHECK-NEXT: [[TMP9:%.*]] = sub i32 [[TMP7]], [[SMIN]]
339 ; CHECK-NEXT: [[TMP10:%.*]] = lshr i32 [[TMP9]], 3
340 ; CHECK-NEXT: [[TMP11:%.*]] = add nuw nsw i32 [[TMP10]], 1
341 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP11]], 2
342 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
343 ; CHECK: [[VECTOR_PH]]:
344 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[TMP11]], 2
345 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[TMP11]], [[N_MOD_VF]]
346 ; CHECK-NEXT: [[TMP16:%.*]] = mul i32 [[N_VEC]], -8
347 ; CHECK-NEXT: [[IND_END:%.*]] = add i32 [[TMP12]], [[TMP16]]
348 ; CHECK-NEXT: br label %[[VECTOR_BODY:.*]]
349 ; CHECK: [[VECTOR_BODY]]:
350 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
351 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 2
352 ; CHECK-NEXT: [[TMP13:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
353 ; CHECK-NEXT: br i1 [[TMP13]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], {{!llvm.loop ![0-9]+}}
354 ; CHECK: [[MIDDLE_BLOCK]]:
355 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[TMP11]], [[N_VEC]]
356 ; CHECK-NEXT: br i1 [[CMP_N]], label %[[BB1_LOOPEXIT]], label %[[SCALAR_PH]]
357 ; CHECK: [[SCALAR_PH]]:
358 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[IND_END]], %[[MIDDLE_BLOCK]] ], [ [[TMP12]], %[[BB3]] ]
359 ; CHECK-NEXT: br label %[[BB4:.*]]
361 ; CHECK-NEXT: [[TMP13:%.*]] = phi i32 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[TMP14:%.*]], %[[BB4]] ]
362 ; CHECK-NEXT: [[TMP14]] = add i32 [[TMP13]], -8
363 ; CHECK-NEXT: [[TMP15:%.*]] = icmp sgt i32 [[TMP14]], 0
364 ; CHECK-NEXT: br i1 [[TMP15]], label %[[BB4]], label %[[BB1_LOOPEXIT]], {{!llvm.loop ![0-9]+}}
370 %tmp00 = load i32, ptr undef, align 16
371 %tmp01 = sub i32 %tmp00, undef
372 %tmp02 = icmp slt i32 %tmp01, 1
373 %tmp03 = select i1 %tmp02, i32 1, i32 %tmp01
374 %tmp04 = add nsw i32 %tmp03, -7
378 %tmp05 = phi i32 [ %tmp04, %BB1 ], [ %tmp06, %BB2 ]
379 %tmp06 = add i32 %tmp05, -8
380 %tmp07 = icmp sgt i32 %tmp06, 0
381 br i1 %tmp07, label %BB2, label %BB3
384 %tmp08 = phi i32 [ %tmp05, %BB2 ]
385 %tmp09 = sub i32 %tmp00, undef
386 %tmp10 = icmp slt i32 %tmp09, 1
387 %tmp11 = select i1 %tmp10, i32 1, i32 %tmp09
388 %tmp11.inc = add nsw i32 %tmp11, -7
392 %tmp13 = phi i32 [ %tmp11.inc, %BB3 ], [ %tmp14, %BB4 ]
393 %tmp14 = add i32 %tmp13, -8
394 %tmp15 = icmp sgt i32 %tmp14, 0
395 br i1 %tmp15, label %BB4, label %BB1
399 define i64 @iv_scalar_steps_and_outside_users(ptr %ptr) {
400 ; VEC-LABEL: define i64 @iv_scalar_steps_and_outside_users(
401 ; VEC-SAME: ptr [[PTR:%.*]]) {
402 ; VEC-NEXT: [[ENTRY:.*]]:
403 ; VEC-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
404 ; VEC: [[VECTOR_PH]]:
405 ; VEC-NEXT: br label %[[VECTOR_BODY:.*]]
406 ; VEC: [[VECTOR_BODY]]:
407 ; VEC-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
408 ; VEC-NEXT: [[VEC_IND:%.*]] = phi <2 x i64> [ <i64 0, i64 1>, %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]
409 ; VEC-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
410 ; VEC-NEXT: [[TMP1:%.*]] = getelementptr inbounds i64, ptr [[PTR]], i64 [[TMP0]]
411 ; VEC-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 0
412 ; VEC-NEXT: store <2 x i64> [[VEC_IND]], ptr [[TMP2]], align 4
413 ; VEC-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
414 ; VEC-NEXT: [[VEC_IND_NEXT]] = add <2 x i64> [[VEC_IND]], splat (i64 2)
415 ; VEC-NEXT: [[TMP3:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1002
416 ; VEC-NEXT: br i1 [[TMP3]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], {{!llvm.loop ![0-9]+}}
417 ; VEC: [[MIDDLE_BLOCK]]:
418 ; VEC-NEXT: br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]]
419 ; VEC: [[SCALAR_PH]]:
420 ; VEC-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1002, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
421 ; VEC-NEXT: br label %[[LOOP:.*]]
423 ; VEC-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
424 ; VEC-NEXT: [[IV_NEXT]] = add nuw i64 [[IV]], 1
425 ; VEC-NEXT: [[GEP_PTR:%.*]] = getelementptr inbounds i64, ptr [[PTR]], i64 [[IV]]
426 ; VEC-NEXT: store i64 [[IV]], ptr [[GEP_PTR]], align 4
427 ; VEC-NEXT: [[EXITCOND:%.*]] = icmp ugt i64 [[IV]], 1000
428 ; VEC-NEXT: br i1 [[EXITCOND]], label %[[EXIT]], label %[[LOOP]], {{!llvm.loop ![0-9]+}}
430 ; VEC-NEXT: [[IV_LCSSA:%.*]] = phi i64 [ [[IV]], %[[LOOP]] ], [ 1001, %[[MIDDLE_BLOCK]] ]
431 ; VEC-NEXT: ret i64 [[IV_LCSSA]]
437 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
438 %iv.next = add nuw i64 %iv, 1
439 %gep.ptr = getelementptr inbounds i64, ptr %ptr, i64 %iv
440 store i64 %iv, ptr %gep.ptr
441 %exitcond = icmp ugt i64 %iv, 1000
442 br i1 %exitcond, label %exit, label %loop
445 %iv.lcssa = phi i64 [ %iv, %loop ]
450 ; %iv.2 is dead in the vector loop and only used outside the loop.
451 define i32 @iv_2_dead_in_loop_only_used_outside(ptr %ptr) {
452 ; VEC-LABEL: define i32 @iv_2_dead_in_loop_only_used_outside(
453 ; VEC-SAME: ptr [[PTR:%.*]]) {
454 ; VEC-NEXT: [[ENTRY:.*]]:
455 ; VEC-NEXT: br i1 false, label %[[SCALAR_PH:.*]], label %[[VECTOR_PH:.*]]
456 ; VEC: [[VECTOR_PH]]:
457 ; VEC-NEXT: br label %[[VECTOR_BODY:.*]]
458 ; VEC: [[VECTOR_BODY]]:
459 ; VEC-NEXT: [[INDEX:%.*]] = phi i64 [ 0, %[[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], %[[VECTOR_BODY]] ]
460 ; VEC-NEXT: [[VEC_IND:%.*]] = phi <2 x i64> [ <i64 0, i64 1>, %[[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], %[[VECTOR_BODY]] ]
461 ; VEC-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
462 ; VEC-NEXT: [[TMP1:%.*]] = getelementptr inbounds i64, ptr [[PTR]], i64 [[TMP0]]
463 ; VEC-NEXT: [[TMP2:%.*]] = getelementptr inbounds i64, ptr [[TMP1]], i32 0
464 ; VEC-NEXT: store <2 x i64> [[VEC_IND]], ptr [[TMP2]], align 4
465 ; VEC-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
466 ; VEC-NEXT: [[VEC_IND_NEXT]] = add <2 x i64> [[VEC_IND]], splat (i64 2)
467 ; VEC-NEXT: [[TMP3:%.*]] = icmp eq i64 [[INDEX_NEXT]], 1002
468 ; VEC-NEXT: br i1 [[TMP3]], label %[[MIDDLE_BLOCK:.*]], label %[[VECTOR_BODY]], {{!llvm.loop ![0-9]+}}
469 ; VEC: [[MIDDLE_BLOCK]]:
470 ; VEC-NEXT: br i1 true, label %[[EXIT:.*]], label %[[SCALAR_PH]]
471 ; VEC: [[SCALAR_PH]]:
472 ; VEC-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ 1002, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
473 ; VEC-NEXT: [[BC_RESUME_VAL1:%.*]] = phi i32 [ 2004, %[[MIDDLE_BLOCK]] ], [ 0, %[[ENTRY]] ]
474 ; VEC-NEXT: br label %[[LOOP:.*]]
476 ; VEC-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], %[[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], %[[LOOP]] ]
477 ; VEC-NEXT: [[IV_2:%.*]] = phi i32 [ [[BC_RESUME_VAL1]], %[[SCALAR_PH]] ], [ [[IV_2_NEXT:%.*]], %[[LOOP]] ]
478 ; VEC-NEXT: [[IV_NEXT]] = add nuw i64 [[IV]], 1
479 ; VEC-NEXT: [[IV_2_NEXT]] = add nuw i32 [[IV_2]], 2
480 ; VEC-NEXT: [[GEP_PTR:%.*]] = getelementptr inbounds i64, ptr [[PTR]], i64 [[IV]]
481 ; VEC-NEXT: store i64 [[IV]], ptr [[GEP_PTR]], align 4
482 ; VEC-NEXT: [[EXITCOND:%.*]] = icmp ugt i64 [[IV]], 1000
483 ; VEC-NEXT: br i1 [[EXITCOND]], label %[[EXIT]], label %[[LOOP]], {{!llvm.loop ![0-9]+}}
485 ; VEC-NEXT: [[IV_2_LCSSA:%.*]] = phi i32 [ [[IV_2]], %[[LOOP]] ], [ 2002, %[[MIDDLE_BLOCK]] ]
486 ; VEC-NEXT: ret i32 [[IV_2_LCSSA]]
492 %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
493 %iv.2 = phi i32 [ 0, %entry ], [ %iv.2.next, %loop ]
494 %iv.next = add nuw i64 %iv, 1
495 %iv.2.next = add nuw i32 %iv.2, 2
496 %gep.ptr = getelementptr inbounds i64, ptr %ptr, i64 %iv
497 store i64 %iv, ptr %gep.ptr
498 %exitcond = icmp ugt i64 %iv, 1000
499 br i1 %exitcond, label %exit, label %loop
502 %iv.2.lcssa = phi i32 [ %iv.2, %loop ]