1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
2 ; RUN: opt -passes='default<O2>' -S %s | FileCheck %s
4 ; Slightly reduced test case for a loop iterating over a std::span with libc++ hardening.
5 ; TODO: The runtime check in the loop should be removed.
10 ; void use(unsigned&);
12 ; void fill_with_foreach(std::span<unsigned> elems) {
13 ; for (unsigned& x : elems)
17 %"class.std::__1::span" = type { ptr, i64 }
18 %"struct.std::__1::__bounded_iter" = type { ptr, ptr, ptr }
20 define void @test_fill_with_foreach([2 x i64] %elems.coerce) {
21 ; CHECK-LABEL: define void @test_fill_with_foreach
22 ; CHECK-SAME: ([2 x i64] [[ELEMS_COERCE:%.*]]) local_unnamed_addr {
24 ; CHECK-NEXT: [[ELEMS_COERCE_FCA_0_EXTRACT:%.*]] = extractvalue [2 x i64] [[ELEMS_COERCE]], 0
25 ; CHECK-NEXT: [[TMP0:%.*]] = inttoptr i64 [[ELEMS_COERCE_FCA_0_EXTRACT]] to ptr
26 ; CHECK-NEXT: [[ELEMS_COERCE_FCA_1_EXTRACT:%.*]] = extractvalue [2 x i64] [[ELEMS_COERCE]], 1
27 ; CHECK-NEXT: [[ADD_PTR_I:%.*]] = getelementptr inbounds i32, ptr [[TMP0]], i64 [[ELEMS_COERCE_FCA_1_EXTRACT]]
28 ; CHECK-NEXT: [[CMP_NOT_I_I_I_I:%.*]] = icmp slt i64 [[ELEMS_COERCE_FCA_1_EXTRACT]], 0
29 ; CHECK-NEXT: br i1 [[CMP_NOT_I_I_I_I]], label [[ERROR:%.*]], label [[FOR_COND_PREHEADER_SPLIT:%.*]]
30 ; CHECK: for.cond.preheader.split:
31 ; CHECK-NEXT: [[CMP_I_NOT2:%.*]] = icmp eq i64 [[ELEMS_COERCE_FCA_1_EXTRACT]], 0
32 ; CHECK-NEXT: br i1 [[CMP_I_NOT2]], label [[COMMON_RET:%.*]], label [[FOR_BODY:%.*]]
34 ; CHECK-NEXT: ret void
36 ; CHECK-NEXT: tail call void @error()
37 ; CHECK-NEXT: br label [[COMMON_RET]]
39 ; CHECK-NEXT: [[__BEGIN1_SROA_0_03:%.*]] = phi ptr [ [[INCDEC_PTR_I:%.*]], [[FOR_BODY]] ], [ [[TMP0]], [[FOR_COND_PREHEADER_SPLIT]] ]
40 ; CHECK-NEXT: tail call void @use(ptr noundef nonnull align 4 dereferenceable(4) [[__BEGIN1_SROA_0_03]])
41 ; CHECK-NEXT: [[INCDEC_PTR_I]] = getelementptr inbounds i8, ptr [[__BEGIN1_SROA_0_03]], i64 4
42 ; CHECK-NEXT: [[CMP_I_NOT:%.*]] = icmp eq ptr [[INCDEC_PTR_I]], [[ADD_PTR_I]]
43 ; CHECK-NEXT: br i1 [[CMP_I_NOT]], label [[COMMON_RET]], label [[FOR_BODY]]
46 %elems = alloca %"class.std::__1::span", align 8
47 %__begin1 = alloca %"struct.std::__1::__bounded_iter", align 8
48 %__end1 = alloca %"struct.std::__1::__bounded_iter", align 8
49 %elems.coerce.fca.0.extract = extractvalue [2 x i64] %elems.coerce, 0
50 store i64 %elems.coerce.fca.0.extract, ptr %elems, align 8
51 %elems.coerce.fca.1.extract = extractvalue [2 x i64] %elems.coerce, 1
52 %elems.coerce.fca.1.gep = getelementptr inbounds [2 x i64], ptr %elems, i64 0, i64 1
53 store i64 %elems.coerce.fca.1.extract, ptr %elems.coerce.fca.1.gep, align 8
54 call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %__begin1) #6
55 %0 = load ptr, ptr %elems, align 8
56 %__size_.i.i = getelementptr inbounds %"class.std::__1::span", ptr %elems, i64 0, i32 1
57 %1 = load i64, ptr %__size_.i.i, align 8
58 %add.ptr.i = getelementptr inbounds i32, ptr %0, i64 %1
59 store ptr %0, ptr %__begin1, align 8
60 %__begin_.i.i.i.i = getelementptr inbounds %"struct.std::__1::__bounded_iter", ptr %__begin1, i64 0, i32 1
61 store ptr %0, ptr %__begin_.i.i.i.i, align 8
62 %__end_.i.i.i.i = getelementptr inbounds %"struct.std::__1::__bounded_iter", ptr %__begin1, i64 0, i32 2
63 store ptr %add.ptr.i, ptr %__end_.i.i.i.i, align 8
64 %cmp.not.i.i.i.i = icmp slt i64 %1, 0
65 br i1 %cmp.not.i.i.i.i, label %error, label %check.2
68 call void @llvm.lifetime.start.p0(i64 24, ptr nonnull %__end1) #6
69 %l4 = load ptr, ptr %elems, align 8
70 %__size_.i.i4 = getelementptr inbounds %"class.std::__1::span", ptr %elems, i64 0, i32 1
71 %l5 = load i64, ptr %__size_.i.i4, align 8
72 %add.ptr.i5 = getelementptr inbounds i32, ptr %l4, i64 %l5
73 store ptr %add.ptr.i5, ptr %__end1, align 8
74 %__begin_.i.i.i.i6 = getelementptr inbounds %"struct.std::__1::__bounded_iter", ptr %__end1, i64 0, i32 1
75 store ptr %l4, ptr %__begin_.i.i.i.i6, align 8
76 %__end_.i.i.i.i7 = getelementptr inbounds %"struct.std::__1::__bounded_iter", ptr %__end1, i64 0, i32 2
77 store ptr %add.ptr.i5, ptr %__end_.i.i.i.i7, align 8
78 %cmp.not.i.i.i.i8 = icmp slt i64 %l5, 0
79 br i1 %cmp.not.i.i.i.i8, label %error, label %for.cond
86 %l8 = load ptr, ptr %__begin1, align 8
87 %l9 = load ptr, ptr %__end1, align 8
88 %cmp.i = icmp ne ptr %l8, %l9
89 br i1 %cmp.i, label %for.body, label %for.cond.cleanup
91 for.cond.cleanup: ; preds = %for.cond
92 call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %__end1)
93 call void @llvm.lifetime.end.p0(i64 24, ptr nonnull %__begin1)
96 for.body: ; preds = %for.cond
97 %l10 = load ptr, ptr %__begin1, align 8
98 %__begin_.i.i = getelementptr inbounds %"struct.std::__1::__bounded_iter", ptr %__begin1, i64 0, i32 1
99 %l11 = load ptr, ptr %__begin_.i.i, align 8
100 %cmp.not.i.i = icmp uge ptr %l10, %l11
101 %__end_.i.i = getelementptr inbounds %"struct.std::__1::__bounded_iter", ptr %__begin1, i64 0, i32 2
102 %l12 = load ptr, ptr %__end_.i.i, align 8
103 %cmp2.i.i = icmp ult ptr %l10, %l12
104 %sel = select i1 %cmp.not.i.i, i1 %cmp2.i.i, i1 false
105 br i1 %sel, label %for.latch, label %error
108 call void @use(ptr noundef nonnull align 4 dereferenceable(4) %l10)
109 %l = load ptr, ptr %__begin1, align 8
110 %incdec.ptr.i = getelementptr inbounds i32, ptr %l, i64 1
111 store ptr %incdec.ptr.i, ptr %__begin1, align 8
115 declare void @error()
117 declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture)
119 declare void @use(ptr noundef nonnull align 4 dereferenceable(4))
121 declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture)
124 ; -------------------------------------------------------------------------
125 ; Test case for runtime check removal when accessing vector elements with
126 ; hardened glibc++ (PR63125)
128 %Vector_base = type { %Vector_impl }
129 %Vector_impl = type { %Vector_impl_data }
130 %Vector_impl_data = type { ptr, ptr, ptr }
132 define void @foo(ptr noundef nonnull align 8 dereferenceable(24) noalias %vec) #0 {
133 ; CHECK-LABEL: define void @foo
134 ; CHECK-SAME: (ptr noalias nocapture noundef nonnull readonly align 8 dereferenceable(24) [[VEC:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] {
136 ; CHECK-NEXT: [[_M_FINISH_I_I:%.*]] = getelementptr inbounds i8, ptr [[VEC]], i64 8
137 ; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[_M_FINISH_I_I]], align 8, !tbaa [[TBAA0:![0-9]+]]
138 ; CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[VEC]], align 8, !tbaa [[TBAA5:![0-9]+]]
139 ; CHECK-NEXT: [[SUB_PTR_LHS_CAST_I_I:%.*]] = ptrtoint ptr [[TMP0]] to i64
140 ; CHECK-NEXT: [[SUB_PTR_RHS_CAST_I_I:%.*]] = ptrtoint ptr [[TMP1]] to i64
141 ; CHECK-NEXT: [[SUB_PTR_SUB_I_I:%.*]] = sub i64 [[SUB_PTR_LHS_CAST_I_I]], [[SUB_PTR_RHS_CAST_I_I]]
142 ; CHECK-NEXT: [[SUB_PTR_DIV_I_I:%.*]] = ashr exact i64 [[SUB_PTR_SUB_I_I]], 3
143 ; CHECK-NEXT: [[CMP_NOT9:%.*]] = icmp eq ptr [[TMP0]], [[TMP1]]
144 ; CHECK-NEXT: br i1 [[CMP_NOT9]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY:%.*]]
145 ; CHECK: for.cond.cleanup:
146 ; CHECK-NEXT: ret void
148 ; CHECK-NEXT: [[I_010:%.*]] = phi i64 [ [[INC:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ]
149 ; CHECK-NEXT: [[ADD_PTR_I:%.*]] = getelementptr inbounds double, ptr [[TMP1]], i64 [[I_010]]
150 ; CHECK-NEXT: [[TMP2:%.*]] = load double, ptr [[ADD_PTR_I]], align 8
151 ; CHECK-NEXT: [[ADD:%.*]] = fadd double [[TMP2]], 1.000000e+00
152 ; CHECK-NEXT: store double [[ADD]], ptr [[ADD_PTR_I]], align 8
153 ; CHECK-NEXT: [[INC]] = add nuw i64 [[I_010]], 1
154 ; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i64 [[INC]], [[SUB_PTR_DIV_I_I]]
155 ; CHECK-NEXT: br i1 [[CMP_NOT]], label [[FOR_COND_CLEANUP]], label [[FOR_BODY]]
158 %vec.addr = alloca ptr, align 8
159 %count = alloca i64, align 8
160 %i = alloca i64, align 8
161 store ptr %vec, ptr %vec.addr, align 8
162 call void @llvm.lifetime.start.p0(i64 8, ptr %count)
163 %0 = load ptr, ptr %vec.addr, align 8
164 %call = call noundef i64 @alloc(ptr noundef nonnull align 8 dereferenceable(24) %0)
165 store i64 %call, ptr %count, align 8
166 call void @llvm.lifetime.start.p0(i64 8, ptr %i)
167 store i64 0, ptr %i, align 8
171 %1 = load i64, ptr %i, align 8
172 %2 = load i64, ptr %count, align 8
173 %cmp = icmp ne i64 %1, %2
174 br i1 %cmp, label %for.body, label %for.cond.cleanup
177 call void @llvm.lifetime.end.p0(i64 8, ptr %i)
181 %3 = load ptr, ptr %vec.addr, align 8
182 %4 = load i64, ptr %i, align 8
183 %call1 = call noundef nonnull align 8 dereferenceable(8) ptr @operator_acc(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %4)
184 %5 = load double, ptr %call1, align 8
185 %add = fadd double %5, 1.000000e+00
186 store double %add, ptr %call1, align 8
190 %6 = load i64, ptr %i, align 8
192 store i64 %inc, ptr %i, align 8
196 call void @llvm.lifetime.end.p0(i64 8, ptr %count) #5
200 define internal noundef i64 @alloc(ptr noundef nonnull align 8 dereferenceable(24) %__cont) {
202 %__cont.addr = alloca ptr, align 8
203 store ptr %__cont, ptr %__cont.addr, align 8
204 %0 = load ptr, ptr %__cont.addr, align 8
205 %call = call noundef i64 @size(ptr noundef nonnull align 8 dereferenceable(24) %0) #5
209 define internal noundef nonnull align 8 dereferenceable(8) ptr @operator_acc(ptr noundef nonnull align 8 dereferenceable(24) %this, i64 noundef %__n) {
211 %this.addr = alloca ptr, align 8
212 %__n.addr = alloca i64, align 8
213 store ptr %this, ptr %this.addr, align 8
214 store i64 %__n, ptr %__n.addr, align 8
215 %this1 = load ptr, ptr %this.addr, align 8
219 %0 = load i64, ptr %__n.addr, align 8
220 %call = call noundef i64 @size(ptr noundef nonnull align 8 dereferenceable(24) %this1)
221 %cmp = icmp ult i64 %0, %call
222 %lnot = xor i1 %cmp, true
223 %conv = zext i1 %lnot to i64
224 %tobool = icmp ne i64 %conv, 0
225 br i1 %tobool, label %if.then, label %if.end
228 call void @abort() readnone
238 %_M_impl = getelementptr inbounds %Vector_base, ptr %this1, i32 0, i32 0
239 %_M_start = getelementptr inbounds %Vector_impl_data, ptr %_M_impl, i32 0, i32 0
240 %1 = load ptr, ptr %_M_start, align 8, !tbaa !0
241 %2 = load i64, ptr %__n.addr, align 8, !tbaa !5
242 %add.ptr = getelementptr inbounds double, ptr %1, i64 %2
246 define internal noundef i64 @size(ptr noundef nonnull align 8 dereferenceable(24) %this) {
248 %this.addr = alloca ptr, align 8
249 store ptr %this, ptr %this.addr, align 8
250 %this1 = load ptr, ptr %this.addr, align 8
251 %_M_impl = getelementptr inbounds %Vector_base, ptr %this1, i32 0, i32 0
252 %_M_finish = getelementptr inbounds %Vector_impl_data, ptr %_M_impl, i32 0, i32 1
253 %0 = load ptr, ptr %_M_finish, align 8, !tbaa !7
254 %_M_impl2 = getelementptr inbounds %Vector_base, ptr %this1, i32 0, i32 0
255 %_M_start = getelementptr inbounds %Vector_impl_data, ptr %_M_impl2, i32 0, i32 0
256 %1 = load ptr, ptr %_M_start, align 8, !tbaa !0
257 %sub.ptr.lhs.cast = ptrtoint ptr %0 to i64
258 %sub.ptr.rhs.cast = ptrtoint ptr %1 to i64
259 %sub.ptr.sub = sub i64 %sub.ptr.lhs.cast, %sub.ptr.rhs.cast
260 %sub.ptr.div = sdiv exact i64 %sub.ptr.sub, 8
264 declare void @abort()
266 ; -------------------------------------------------------------------------
267 ; Test case for runtime check removal when accessing vector elements with
268 ; hardened glibc++ and a signed induction variable.
269 ; https://github.com/llvm/llvm-project/issues/63126
271 define void @loop_with_signed_induction(ptr noundef nonnull align 8 dereferenceable(24) %vec) {
272 ; CHECK-LABEL: define void @loop_with_signed_induction
273 ; CHECK-SAME: (ptr nocapture noundef nonnull readonly align 8 dereferenceable(24) [[VEC:%.*]]) local_unnamed_addr #[[ATTR0]] {
275 ; CHECK-NEXT: [[_M_FINISH_I_I:%.*]] = getelementptr inbounds i8, ptr [[VEC]], i64 8
276 ; CHECK-NEXT: [[TMP0:%.*]] = load ptr, ptr [[_M_FINISH_I_I]], align 8, !tbaa [[TBAA0]]
277 ; CHECK-NEXT: [[TMP1:%.*]] = load ptr, ptr [[VEC]], align 8, !tbaa [[TBAA5]]
278 ; CHECK-NEXT: [[SUB_PTR_LHS_CAST_I_I:%.*]] = ptrtoint ptr [[TMP0]] to i64
279 ; CHECK-NEXT: [[SUB_PTR_RHS_CAST_I_I:%.*]] = ptrtoint ptr [[TMP1]] to i64
280 ; CHECK-NEXT: [[SUB_PTR_SUB_I_I:%.*]] = sub i64 [[SUB_PTR_LHS_CAST_I_I]], [[SUB_PTR_RHS_CAST_I_I]]
281 ; CHECK-NEXT: [[SUB_PTR_DIV_I_I:%.*]] = ashr exact i64 [[SUB_PTR_SUB_I_I]], 3
282 ; CHECK-NEXT: [[CMP9:%.*]] = icmp sgt i64 [[SUB_PTR_DIV_I_I]], 0
283 ; CHECK-NEXT: br i1 [[CMP9]], label [[FOR_BODY:%.*]], label [[FOR_COND_CLEANUP:%.*]]
284 ; CHECK: for.cond.cleanup:
285 ; CHECK-NEXT: ret void
287 ; CHECK-NEXT: [[I_010:%.*]] = phi i64 [ [[INC:%.*]], [[FOR_BODY]] ], [ 0, [[ENTRY:%.*]] ]
288 ; CHECK-NEXT: [[ADD_PTR_I:%.*]] = getelementptr inbounds double, ptr [[TMP1]], i64 [[I_010]]
289 ; CHECK-NEXT: [[TMP2:%.*]] = load double, ptr [[ADD_PTR_I]], align 8, !tbaa [[TBAA6:![0-9]+]]
290 ; CHECK-NEXT: [[ADD:%.*]] = fadd double [[TMP2]], 1.000000e+00
291 ; CHECK-NEXT: store double [[ADD]], ptr [[ADD_PTR_I]], align 8, !tbaa [[TBAA6]]
292 ; CHECK-NEXT: [[INC]] = add nuw nsw i64 [[I_010]], 1
293 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[INC]], [[SUB_PTR_DIV_I_I]]
294 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_CLEANUP]]
297 %vec.addr = alloca ptr, align 8
298 %count = alloca i64, align 8
299 %i = alloca i64, align 8
300 store ptr %vec, ptr %vec.addr, align 8
301 call void @llvm.lifetime.start.p0(i64 8, ptr %count)
302 %0 = load ptr, ptr %vec.addr, align 8
303 %call = call noundef i64 @alloc(ptr noundef nonnull align 8 dereferenceable(24) %0)
304 store i64 %call, ptr %count, align 8
305 call void @llvm.lifetime.start.p0(i64 8, ptr %i)
306 store i64 0, ptr %i, align 8
310 %1 = load i64, ptr %i, align 8
311 %2 = load i64, ptr %count, align 8
312 %cmp = icmp slt i64 %1, %2
313 br i1 %cmp, label %for.body, label %for.cond.cleanup
316 call void @llvm.lifetime.end.p0(i64 8, ptr %i)
320 %3 = load ptr, ptr %vec.addr, align 8
321 %4 = load i64, ptr %i, align 8
322 %call1 = call noundef nonnull align 8 dereferenceable(8) ptr @operator_acc(ptr noundef nonnull align 8 dereferenceable(24) %3, i64 noundef %4)
323 %5 = load double, ptr %call1, align 8, !tbaa !8
324 %add = fadd double %5, 1.000000e+00
325 store double %add, ptr %call1, align 8, !tbaa !8
329 %6 = load i64, ptr %i, align 8
330 %inc = add nsw i64 %6, 1
331 store i64 %inc, ptr %i, align 8
335 call void @llvm.lifetime.end.p0(i64 8, ptr %count)
339 ; -------------------------------------------------------------------------
340 ; Test case for runtime check removal when accessing elements in a nested loop
344 define void @monkey(ptr noundef %arr, i32 noundef %len) {
345 ; CHECK-LABEL: define void @monkey
346 ; CHECK-SAME: (ptr nocapture noundef [[ARR:%.*]], i32 noundef [[LEN:%.*]]) local_unnamed_addr #[[ATTR1:[0-9]+]] {
348 ; CHECK-NEXT: [[CMP8:%.*]] = icmp ugt i32 [[LEN]], 1
349 ; CHECK-NEXT: br i1 [[CMP8]], label [[FOR_BODY4_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
350 ; CHECK: for.body4.preheader:
351 ; CHECK-NEXT: [[I_09:%.*]] = phi i32 [ [[INC:%.*]], [[FOR_COND_CLEANUP3:%.*]] ], [ 1, [[ENTRY:%.*]] ]
352 ; CHECK-NEXT: br label [[FOR_BODY4:%.*]]
353 ; CHECK: for.cond.cleanup:
354 ; CHECK-NEXT: ret void
355 ; CHECK: for.cond.cleanup3:
356 ; CHECK-NEXT: [[INC]] = add nuw i32 [[I_09]], 1
357 ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[INC]], [[LEN]]
358 ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY4_PREHEADER]], label [[FOR_COND_CLEANUP]]
360 ; CHECK-NEXT: [[K_07:%.*]] = phi i32 [ [[DEC:%.*]], [[FOR_BODY4]] ], [ [[I_09]], [[FOR_BODY4_PREHEADER]] ]
361 ; CHECK-NEXT: [[IDX_EXT_I:%.*]] = zext i32 [[K_07]] to i64
362 ; CHECK-NEXT: [[ADD_PTR_I:%.*]] = getelementptr inbounds i32, ptr [[ARR]], i64 [[IDX_EXT_I]]
363 ; CHECK-NEXT: [[TMP0:%.*]] = load i32, ptr [[ADD_PTR_I]], align 4
364 ; CHECK-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP0]], 1
365 ; CHECK-NEXT: store i32 [[ADD]], ptr [[ADD_PTR_I]], align 4
366 ; CHECK-NEXT: [[DEC]] = add i32 [[K_07]], -1
367 ; CHECK-NEXT: [[CMP2_NOT:%.*]] = icmp eq i32 [[DEC]], 0
368 ; CHECK-NEXT: br i1 [[CMP2_NOT]], label [[FOR_COND_CLEANUP3]], label [[FOR_BODY4]]
371 %arr.addr = alloca ptr, align 8
372 %len.addr = alloca i32, align 4
373 %i = alloca i32, align 4
374 %cleanup.dest.slot = alloca i32, align 4
375 %k = alloca i32, align 4
376 store ptr %arr, ptr %arr.addr, align 8
377 store i32 %len, ptr %len.addr, align 4
378 call void @llvm.lifetime.start.p0(i64 4, ptr %i) #3
379 store i32 1, ptr %i, align 4
382 for.cond: ; preds = %for.inc5, %entry
383 %0 = load i32, ptr %i, align 4
384 %1 = load i32, ptr %len.addr, align 4
385 %cmp = icmp ult i32 %0, %1
386 br i1 %cmp, label %for.body, label %for.cond.cleanup
388 for.cond.cleanup: ; preds = %for.cond
389 store i32 2, ptr %cleanup.dest.slot, align 4
390 call void @llvm.lifetime.end.p0(i64 4, ptr %i) #3
393 for.body: ; preds = %for.cond
394 call void @llvm.lifetime.start.p0(i64 4, ptr %k) #3
395 %2 = load i32, ptr %i, align 4
396 store i32 %2, ptr %k, align 4
399 for.cond1: ; preds = %for.inc, %for.body
400 %3 = load i32, ptr %k, align 4
401 %cmp2 = icmp ugt i32 %3, 0
402 br i1 %cmp2, label %for.body4, label %for.cond.cleanup3
404 for.cond.cleanup3: ; preds = %for.cond1
405 store i32 5, ptr %cleanup.dest.slot, align 4
406 call void @llvm.lifetime.end.p0(i64 4, ptr %k) #3
409 for.body4: ; preds = %for.cond1
410 %4 = load ptr, ptr %arr.addr, align 8
411 %5 = load i32, ptr %len.addr, align 4
412 %6 = load i32, ptr %k, align 4
413 %call = call noundef ptr @at(ptr noundef %4, i32 noundef %5, i32 noundef %6)
414 %7 = load i32, ptr %call, align 4
415 %add = add nsw i32 %7, 1
416 store i32 %add, ptr %call, align 4
419 for.inc: ; preds = %for.body4
420 %8 = load i32, ptr %k, align 4
421 %dec = add i32 %8, -1
422 store i32 %dec, ptr %k, align 4
425 for.end: ; preds = %for.cond.cleanup3
428 for.inc5: ; preds = %for.end
429 %9 = load i32, ptr %i, align 4
431 store i32 %inc, ptr %i, align 4
434 for.end6: ; preds = %for.cond.cleanup
438 define internal noundef ptr @at(ptr noundef %arr, i32 noundef %len, i32 noundef %idx) {
440 %arr.addr = alloca ptr, align 8
441 %len.addr = alloca i32, align 4
442 %idx.addr = alloca i32, align 4
443 store ptr %arr, ptr %arr.addr, align 8
444 store i32 %len, ptr %len.addr, align 4
445 store i32 %idx, ptr %idx.addr, align 4
446 %0 = load i32, ptr %idx.addr, align 4
447 %1 = load i32, ptr %len.addr, align 4
448 %cmp = icmp uge i32 %0, %1
449 br i1 %cmp, label %if.then, label %if.end
451 if.then: ; preds = %entry
455 if.end: ; preds = %entry
456 %2 = load ptr, ptr %arr.addr, align 8
457 %3 = load i32, ptr %idx.addr, align 4
458 %idx.ext = zext i32 %3 to i64
459 %add.ptr = getelementptr inbounds i32, ptr %2, i64 %idx.ext
464 !0 = !{!1, !2, i64 0}
465 !1 = !{!"_ZTSNSt12_Vector_baseIdSaIdEE17_Vector_impl_dataE", !2, i64 0, !2, i64 8, !2, i64 16}
466 !2 = !{!"any pointer", !3, i64 0}
467 !3 = !{!"omnipotent char", !4, i64 0}
468 !4 = !{!"Simple C++ TBAA"}
469 !5 = !{!6, !6, i64 0}
470 !6 = !{!"long", !3, i64 0}
471 !7 = !{!1, !2, i64 8}
472 !8 = !{!9, !9, i64 0}
473 !9 = !{!"double", !3, i64 0}