1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-vectorize -force-vector-width=4 -S %s | FileCheck %s
4 ; Tests where the indices of some accesses are clamped to a small range.
6 ; FIXME: At the moment, the runtime checks require that the indices do not wrap
7 ; and runtime checks are emitted to ensure that. The clamped indices do
8 ; wrap, so the vector loops are dead at the moment. But it is still
9 ; possible to compute the bounds of the accesses and generate proper
12 ; The relevant bounds for %gep.A are [%A, %A+4).
13 define void @load_clamped_index(ptr %A, ptr %B, i32 %N) {
14 ; CHECK-LABEL: @load_clamped_index(
16 ; CHECK-NEXT: [[A2:%.*]] = ptrtoint ptr [[A:%.*]] to i64
17 ; CHECK-NEXT: [[B1:%.*]] = ptrtoint ptr [[B:%.*]] to i64
18 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[N:%.*]], 4
19 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
20 ; CHECK: vector.scevcheck:
21 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N]], -1
22 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[TMP0]], 3
23 ; CHECK-NEXT: br i1 [[TMP1]], label [[SCALAR_PH]], label [[VECTOR_MEMCHECK:%.*]]
24 ; CHECK: vector.memcheck:
25 ; CHECK-NEXT: [[TMP2:%.*]] = sub i64 [[B1]], [[A2]]
26 ; CHECK-NEXT: [[DIFF_CHECK:%.*]] = icmp ult i64 [[TMP2]], 16
27 ; CHECK-NEXT: br i1 [[DIFF_CHECK]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
29 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N]], 4
30 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N]], [[N_MOD_VF]]
31 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
33 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
34 ; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[INDEX]], 0
35 ; CHECK-NEXT: [[TMP4:%.*]] = urem i32 [[TMP3]], 4
36 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[TMP4]]
37 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[TMP5]], i32 0
38 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP6]], align 4
39 ; CHECK-NEXT: [[TMP7:%.*]] = add <4 x i32> [[WIDE_LOAD]], splat (i32 10)
40 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 [[TMP3]]
41 ; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds i32, ptr [[TMP8]], i32 0
42 ; CHECK-NEXT: store <4 x i32> [[TMP7]], ptr [[TMP9]], align 4
43 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
44 ; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
45 ; CHECK-NEXT: br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
46 ; CHECK: middle.block:
47 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[N]], [[N_VEC]]
48 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
50 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[VECTOR_MEMCHECK]] ]
51 ; CHECK-NEXT: br label [[LOOP:%.*]]
53 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
54 ; CHECK-NEXT: [[CLAMPED_INDEX:%.*]] = urem i32 [[IV]], 4
55 ; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[CLAMPED_INDEX]]
56 ; CHECK-NEXT: [[LV:%.*]] = load i32, ptr [[GEP_A]], align 4
57 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LV]], 10
58 ; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 [[IV]]
59 ; CHECK-NEXT: store i32 [[ADD]], ptr [[GEP_B]], align 4
60 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
61 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N]]
62 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP3:![0-9]+]]
64 ; CHECK-NEXT: ret void
70 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
71 %clamped.index = urem i32 %iv, 4
72 %gep.A = getelementptr inbounds i32, ptr %A, i32 %clamped.index
73 %lv = load i32, ptr %gep.A
74 %add = add i32 %lv, 10
75 %gep.B = getelementptr inbounds i32, ptr %B, i32 %iv
76 store i32 %add, ptr %gep.B
77 %iv.next = add nuw nsw i32 %iv, 1
78 %cond = icmp eq i32 %iv.next, %N
79 br i1 %cond, label %exit, label %loop
85 ; The relevant bounds for %gep.A are [%A, %A+4).
86 define void @store_clamped_index(ptr %A, ptr %B, i32 %N) {
87 ; CHECK-LABEL: @store_clamped_index(
89 ; CHECK-NEXT: [[B2:%.*]] = ptrtoint ptr [[B:%.*]] to i64
90 ; CHECK-NEXT: [[A1:%.*]] = ptrtoint ptr [[A:%.*]] to i64
91 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[N:%.*]], 4
92 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
93 ; CHECK: vector.scevcheck:
94 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N]], -1
95 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[TMP0]], 3
96 ; CHECK-NEXT: br i1 [[TMP1]], label [[SCALAR_PH]], label [[VECTOR_MEMCHECK:%.*]]
97 ; CHECK: vector.memcheck:
98 ; CHECK-NEXT: [[TMP2:%.*]] = sub i64 [[A1]], [[B2]]
99 ; CHECK-NEXT: [[DIFF_CHECK:%.*]] = icmp ult i64 [[TMP2]], 16
100 ; CHECK-NEXT: br i1 [[DIFF_CHECK]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
102 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N]], 4
103 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N]], [[N_MOD_VF]]
104 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
105 ; CHECK: vector.body:
106 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
107 ; CHECK-NEXT: [[TMP3:%.*]] = add i32 [[INDEX]], 0
108 ; CHECK-NEXT: [[TMP4:%.*]] = urem i32 [[TMP3]], 4
109 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 [[TMP3]]
110 ; CHECK-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[TMP5]], i32 0
111 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP6]], align 4
112 ; CHECK-NEXT: [[TMP7:%.*]] = add <4 x i32> [[WIDE_LOAD]], splat (i32 10)
113 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[TMP4]]
114 ; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds i32, ptr [[TMP8]], i32 0
115 ; CHECK-NEXT: store <4 x i32> [[TMP7]], ptr [[TMP9]], align 4
116 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
117 ; CHECK-NEXT: [[TMP10:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
118 ; CHECK-NEXT: br i1 [[TMP10]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
119 ; CHECK: middle.block:
120 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[N]], [[N_VEC]]
121 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
123 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_SCEVCHECK]] ], [ 0, [[VECTOR_MEMCHECK]] ]
124 ; CHECK-NEXT: br label [[LOOP:%.*]]
126 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
127 ; CHECK-NEXT: [[CLAMPED_INDEX:%.*]] = urem i32 [[IV]], 4
128 ; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 [[IV]]
129 ; CHECK-NEXT: [[LV:%.*]] = load i32, ptr [[GEP_B]], align 4
130 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LV]], 10
131 ; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[CLAMPED_INDEX]]
132 ; CHECK-NEXT: store i32 [[ADD]], ptr [[GEP_A]], align 4
133 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
134 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N]]
135 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP5:![0-9]+]]
137 ; CHECK-NEXT: ret void
143 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
144 %clamped.index = urem i32 %iv, 4
145 %gep.B = getelementptr inbounds i32, ptr %B, i32 %iv
146 %lv = load i32, ptr %gep.B
147 %add = add i32 %lv, 10
148 %gep.A = getelementptr inbounds i32, ptr %A, i32 %clamped.index
149 store i32 %add, ptr %gep.A
150 %iv.next = add nuw nsw i32 %iv, 1
151 %cond = icmp eq i32 %iv.next, %N
152 br i1 %cond, label %exit, label %loop
158 ; The relevant bounds for %gep.A are [%A, %A+4), but the access order is %A+1,
160 define void @load_clamped_index_offset_1(ptr %A, ptr %B, i32 %N) {
161 ; CHECK-LABEL: @load_clamped_index_offset_1(
163 ; CHECK-NEXT: [[A2:%.*]] = ptrtoint ptr [[A:%.*]] to i64
164 ; CHECK-NEXT: [[B1:%.*]] = ptrtoint ptr [[B:%.*]] to i64
165 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N:%.*]], -1
166 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[TMP0]], 4
167 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
168 ; CHECK: vector.scevcheck:
169 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[N]], -2
170 ; CHECK-NEXT: [[TMP2:%.*]] = trunc i32 [[TMP1]] to i2
171 ; CHECK-NEXT: [[TMP3:%.*]] = add i2 1, [[TMP2]]
172 ; CHECK-NEXT: [[TMP4:%.*]] = icmp ult i2 [[TMP3]], 1
173 ; CHECK-NEXT: [[TMP5:%.*]] = icmp ugt i32 [[TMP1]], 3
174 ; CHECK-NEXT: [[TMP6:%.*]] = or i1 [[TMP4]], [[TMP5]]
175 ; CHECK-NEXT: br i1 [[TMP6]], label [[SCALAR_PH]], label [[VECTOR_MEMCHECK:%.*]]
176 ; CHECK: vector.memcheck:
177 ; CHECK-NEXT: [[TMP7:%.*]] = sub i64 [[B1]], [[A2]]
178 ; CHECK-NEXT: [[DIFF_CHECK:%.*]] = icmp ult i64 [[TMP7]], 16
179 ; CHECK-NEXT: br i1 [[DIFF_CHECK]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
181 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[TMP0]], 4
182 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[TMP0]], [[N_MOD_VF]]
183 ; CHECK-NEXT: [[IND_END:%.*]] = add i32 1, [[N_VEC]]
184 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
185 ; CHECK: vector.body:
186 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
187 ; CHECK-NEXT: [[OFFSET_IDX:%.*]] = add i32 1, [[INDEX]]
188 ; CHECK-NEXT: [[TMP10:%.*]] = add i32 [[OFFSET_IDX]], 0
189 ; CHECK-NEXT: [[TMP11:%.*]] = urem i32 [[TMP10]], 4
190 ; CHECK-NEXT: [[TMP12:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[TMP11]]
191 ; CHECK-NEXT: [[TMP13:%.*]] = getelementptr inbounds i32, ptr [[TMP12]], i32 0
192 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP13]], align 4
193 ; CHECK-NEXT: [[TMP14:%.*]] = add <4 x i32> [[WIDE_LOAD]], splat (i32 10)
194 ; CHECK-NEXT: [[TMP15:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 [[TMP10]]
195 ; CHECK-NEXT: [[TMP16:%.*]] = getelementptr inbounds i32, ptr [[TMP15]], i32 0
196 ; CHECK-NEXT: store <4 x i32> [[TMP14]], ptr [[TMP16]], align 4
197 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
198 ; CHECK-NEXT: [[TMP17:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
199 ; CHECK-NEXT: br i1 [[TMP17]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP6:![0-9]+]]
200 ; CHECK: middle.block:
201 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[TMP0]], [[N_VEC]]
202 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
204 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[IND_END]], [[MIDDLE_BLOCK]] ], [ 1, [[ENTRY:%.*]] ], [ 1, [[VECTOR_SCEVCHECK]] ], [ 1, [[VECTOR_MEMCHECK]] ]
205 ; CHECK-NEXT: br label [[LOOP:%.*]]
207 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
208 ; CHECK-NEXT: [[CLAMPED_INDEX:%.*]] = urem i32 [[IV]], 4
209 ; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[CLAMPED_INDEX]]
210 ; CHECK-NEXT: [[LV:%.*]] = load i32, ptr [[GEP_A]], align 4
211 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LV]], 10
212 ; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr inbounds i32, ptr [[B]], i32 [[IV]]
213 ; CHECK-NEXT: store i32 [[ADD]], ptr [[GEP_B]], align 4
214 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
215 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N]]
216 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP7:![0-9]+]]
218 ; CHECK-NEXT: ret void
224 %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop ]
225 %clamped.index = urem i32 %iv, 4
226 %gep.A = getelementptr inbounds i32, ptr %A, i32 %clamped.index
227 %lv = load i32, ptr %gep.A
228 %add = add i32 %lv, 10
229 %gep.B = getelementptr inbounds i32, ptr %B, i32 %iv
230 store i32 %add, ptr %gep.B
231 %iv.next = add nuw nsw i32 %iv, 1
232 %cond = icmp eq i32 %iv.next, %N
233 br i1 %cond, label %exit, label %loop
239 ; The relevant bounds for %gep.A are [%A, %A+5).
240 define void @load_clamped_index_urem_5(ptr %A, ptr %B, i32 %N) {
241 ; CHECK-LABEL: @load_clamped_index_urem_5(
243 ; CHECK-NEXT: br label [[LOOP:%.*]]
245 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 1, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
246 ; CHECK-NEXT: [[CLAMPED_INDEX:%.*]] = urem i32 [[IV]], 5
247 ; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i32 [[CLAMPED_INDEX]]
248 ; CHECK-NEXT: [[LV:%.*]] = load i32, ptr [[GEP_A]], align 4
249 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LV]], 10
250 ; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i32 [[IV]]
251 ; CHECK-NEXT: store i32 [[ADD]], ptr [[GEP_B]], align 4
252 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
253 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N:%.*]]
254 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
256 ; CHECK-NEXT: ret void
262 %iv = phi i32 [ 1, %entry ], [ %iv.next, %loop ]
263 %clamped.index = urem i32 %iv, 5
264 %gep.A = getelementptr inbounds i32, ptr %A, i32 %clamped.index
265 %lv = load i32, ptr %gep.A
266 %add = add i32 %lv, 10
267 %gep.B = getelementptr inbounds i32, ptr %B, i32 %iv
268 store i32 %add, ptr %gep.B
269 %iv.next = add nuw nsw i32 %iv, 1
270 %cond = icmp eq i32 %iv.next, %N
271 br i1 %cond, label %exit, label %loop
276 define void @clamped_index_dependence_non_clamped(ptr %A, ptr %B, i32 %N) {
277 ; CHECK-LABEL: @clamped_index_dependence_non_clamped(
279 ; CHECK-NEXT: br label [[LOOP:%.*]]
281 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
282 ; CHECK-NEXT: [[GEP_B:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i32 [[IV]]
283 ; CHECK-NEXT: [[LV:%.*]] = load i32, ptr [[GEP_B]], align 4
284 ; CHECK-NEXT: [[GEP_A_1:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i32 [[IV]]
285 ; CHECK-NEXT: [[LV_A:%.*]] = load i32, ptr [[GEP_A_1]], align 4
286 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LV]], [[LV_A]]
287 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
288 ; CHECK-NEXT: [[CLAMPED_INDEX:%.*]] = urem i32 [[IV_NEXT]], 4
289 ; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[CLAMPED_INDEX]]
290 ; CHECK-NEXT: store i32 [[ADD]], ptr [[GEP_A]], align 4
291 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N:%.*]]
292 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
294 ; CHECK-NEXT: ret void
300 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
301 %gep.B = getelementptr inbounds i32, ptr %B, i32 %iv
302 %lv = load i32, ptr %gep.B
303 %gep.A.1 = getelementptr inbounds i32, ptr %A, i32 %iv
304 %lv.A = load i32, ptr %gep.A.1
305 %add = add i32 %lv, %lv.A
307 %iv.next = add nuw nsw i32 %iv, 1
308 %clamped.index = urem i32 %iv.next, 4
309 %gep.A = getelementptr inbounds i32, ptr %A, i32 %clamped.index
310 store i32 %add, ptr %gep.A
311 %cond = icmp eq i32 %iv.next, %N
312 br i1 %cond, label %exit, label %loop
318 define void @clamped_index_dependence_clamped_index(ptr %A, ptr %B, i32 %N) {
319 ; CHECK-LABEL: @clamped_index_dependence_clamped_index(
321 ; CHECK-NEXT: br label [[LOOP:%.*]]
323 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
324 ; CHECK-NEXT: [[CLAMPED_INDEX_1:%.*]] = urem i32 [[IV]], 4
325 ; CHECK-NEXT: [[GEP_A_1:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i32 [[CLAMPED_INDEX_1]]
326 ; CHECK-NEXT: [[LV_A:%.*]] = load i32, ptr [[GEP_A_1]], align 4
327 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LV_A]], 10
328 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
329 ; CHECK-NEXT: [[CLAMPED_INDEX:%.*]] = urem i32 [[IV_NEXT]], 4
330 ; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[CLAMPED_INDEX]]
331 ; CHECK-NEXT: store i32 [[ADD]], ptr [[GEP_A]], align 4
332 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N:%.*]]
333 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
335 ; CHECK-NEXT: ret void
341 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
342 %clamped.index.1 = urem i32 %iv, 4
343 %gep.A.1 = getelementptr inbounds i32, ptr %A, i32 %clamped.index.1
344 %lv.A = load i32, ptr %gep.A.1
345 %add = add i32 %lv.A, 10
347 %iv.next = add nuw nsw i32 %iv, 1
348 %clamped.index = urem i32 %iv.next, 4
349 %gep.A = getelementptr inbounds i32, ptr %A, i32 %clamped.index
350 store i32 %add, ptr %gep.A
351 %cond = icmp eq i32 %iv.next, %N
352 br i1 %cond, label %exit, label %loop
358 define void @clamped_index_equal_dependence(ptr %A, ptr %B, i32 %N) {
359 ; CHECK-LABEL: @clamped_index_equal_dependence(
361 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i32 [[N:%.*]], 4
362 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_SCEVCHECK:%.*]]
363 ; CHECK: vector.scevcheck:
364 ; CHECK-NEXT: [[TMP0:%.*]] = add i32 [[N]], -1
365 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[TMP0]], 3
366 ; CHECK-NEXT: br i1 [[TMP1]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
368 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i32 [[N]], 4
369 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i32 [[N]], [[N_MOD_VF]]
370 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
371 ; CHECK: vector.body:
372 ; CHECK-NEXT: [[INDEX:%.*]] = phi i32 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
373 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[INDEX]], 0
374 ; CHECK-NEXT: [[TMP3:%.*]] = urem i32 [[TMP2]], 4
375 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i32 [[TMP3]]
376 ; CHECK-NEXT: [[TMP5:%.*]] = getelementptr inbounds i32, ptr [[TMP4]], i32 0
377 ; CHECK-NEXT: [[WIDE_LOAD:%.*]] = load <4 x i32>, ptr [[TMP5]], align 4
378 ; CHECK-NEXT: [[TMP6:%.*]] = add <4 x i32> [[WIDE_LOAD]], splat (i32 10)
379 ; CHECK-NEXT: store <4 x i32> [[TMP6]], ptr [[TMP5]], align 4
380 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i32 [[INDEX]], 4
381 ; CHECK-NEXT: [[TMP7:%.*]] = icmp eq i32 [[INDEX_NEXT]], [[N_VEC]]
382 ; CHECK-NEXT: br i1 [[TMP7]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP8:![0-9]+]]
383 ; CHECK: middle.block:
384 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i32 [[N]], [[N_VEC]]
385 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
387 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i32 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ], [ 0, [[VECTOR_SCEVCHECK]] ]
388 ; CHECK-NEXT: br label [[LOOP:%.*]]
390 ; CHECK-NEXT: [[IV:%.*]] = phi i32 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[LOOP]] ]
391 ; CHECK-NEXT: [[CLAMPED_INDEX:%.*]] = urem i32 [[IV]], 4
392 ; CHECK-NEXT: [[GEP_A:%.*]] = getelementptr inbounds i32, ptr [[A]], i32 [[CLAMPED_INDEX]]
393 ; CHECK-NEXT: [[LV_A:%.*]] = load i32, ptr [[GEP_A]], align 4
394 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[LV_A]], 10
395 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i32 [[IV]], 1
396 ; CHECK-NEXT: store i32 [[ADD]], ptr [[GEP_A]], align 4
397 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[IV_NEXT]], [[N]]
398 ; CHECK-NEXT: br i1 [[COND]], label [[EXIT]], label [[LOOP]], !llvm.loop [[LOOP9:![0-9]+]]
400 ; CHECK-NEXT: ret void
406 %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
407 %clamped.index = urem i32 %iv, 4
408 %gep.A = getelementptr inbounds i32, ptr %A, i32 %clamped.index
409 %lv.A = load i32, ptr %gep.A
410 %add = add i32 %lv.A, 10
412 %iv.next = add nuw nsw i32 %iv, 1
413 store i32 %add, ptr %gep.A
414 %cond = icmp eq i32 %iv.next, %N
415 br i1 %cond, label %exit, label %loop