Skip to content

Commit 6088e9c

Browse files
committed
[LV] Add test case for diff checks with nested AddRecs.
Add a test case where the AddRec for the pointers in the inner loop have the AddRec of the outer loop as start value. It is sufficient to subtract the start values (%dst, %src) of the outer AddRecs. This simplification will be done in a follow-up commit.
1 parent 9cd617c commit 6088e9c

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

llvm/test/Transforms/LoopVectorize/runtime-checks-difference.ll

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,3 +272,56 @@ outer.latch:
272272
exit:
273273
ret void
274274
}
275+
276+
; Test case where the AddRec for the pointers in the inner loop have the AddRec
277+
; of the outer loop as start value.
278+
; TODO: It is sufficient to subtract the start values (%dst, %src) of the outer
279+
; AddRecs.
280+
define void @nested_loop_start_of_inner_ptr_addrec_is_same_outer_addrec(ptr nocapture noundef %dst, ptr nocapture noundef readonly %src, i64 noundef %m, i64 noundef %n) {
281+
; CHECK-LABEL: @nested_loop_start_of_inner_ptr_addrec_is_same_outer_addrec(
282+
; CHECK-NEXT: entry:
283+
; CHECK-NEXT: [[SRC2:%.*]] = ptrtoint ptr [[SRC:%.*]] to i64
284+
; CHECK-NEXT: [[DST1:%.*]] = ptrtoint ptr [[DST:%.*]] to i64
285+
; CHECK-NEXT: [[TMP0:%.*]] = shl i64 [[N:%.*]], 2
286+
; CHECK-NEXT: br label [[OUTER_LOOP:%.*]]
287+
; CHECK: outer.loop:
288+
; CHECK-NEXT: [[OUTER_IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[OUTER_IV_NEXT:%.*]], [[INNER_EXIT:%.*]] ]
289+
; CHECK-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], [[OUTER_IV]]
290+
; CHECK-NEXT: [[TMP2:%.*]] = add i64 [[DST1]], [[TMP1]]
291+
; CHECK-NEXT: [[TMP3:%.*]] = add i64 [[SRC2]], [[TMP1]]
292+
; CHECK-NEXT: [[MUL:%.*]] = mul nsw i64 [[OUTER_IV]], [[N]]
293+
; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N]], 4
294+
; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_MEMCHECK:%.*]]
295+
; CHECK: vector.memcheck:
296+
; CHECK-NEXT: [[TMP4:%.*]] = sub i64 [[TMP2]], [[TMP3]]
297+
; CHECK-NEXT: [[DIFF_CHECK:%.*]] = icmp ult i64 [[TMP4]], 16
298+
; CHECK-NEXT: br i1 [[DIFF_CHECK]], label [[SCALAR_PH]], label [[VECTOR_PH:%.*]]
299+
;
300+
entry:
301+
br label %outer.loop
302+
303+
outer.loop:
304+
%outer.iv = phi i64 [ 0, %entry ], [ %outer.iv.next, %inner.exit ]
305+
%mul = mul nsw i64 %outer.iv, %n
306+
br label %inner.loop
307+
308+
inner.loop:
309+
%iv.inner = phi i64 [ 0, %outer.loop ], [ %iv.inner.next, %inner.loop ]
310+
%idx = add nuw nsw i64 %iv.inner, %mul
311+
%gep.src = getelementptr inbounds i32, ptr %src, i64 %idx
312+
%l = load i32, ptr %gep.src, align 4
313+
%gep.dst = getelementptr inbounds i32, ptr %dst, i64 %idx
314+
%add = add nsw i32 %l, 10
315+
store i32 %add, ptr %gep.dst, align 4
316+
%iv.inner.next = add nuw nsw i64 %iv.inner, 1
317+
%inner.exit.cond = icmp eq i64 %iv.inner.next, %n
318+
br i1 %inner.exit.cond, label %inner.exit, label %inner.loop
319+
320+
inner.exit:
321+
%outer.iv.next = add nuw nsw i64 %outer.iv, 1
322+
%outer.exit.cond = icmp eq i64 %outer.iv.next, %m
323+
br i1 %outer.exit.cond, label %outer.exit, label %outer.loop
324+
325+
outer.exit:
326+
ret void
327+
}

0 commit comments

Comments
 (0)