; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; REQUIRES: asserts ; RUN: opt < %s -S -debug -passes=loop-idiom 2>&1 | FileCheck %s ; The C code to generate this testcase: ; void test(int *ar, int n, int m) ; { ; long i; ; for (i=0; i ; CHECK-NEXT: PositiveStrideSCEV: (4 + (4 * (sext i32 %m to i64))) ; CHECK-NEXT: Try to fold SCEV based on loop guard ; CHECK-NEXT: FoldedMemsetSize: (4 * (sext i32 %m to i64)) ; CHECK-NEXT: FoldedPositiveStride: (4 + (4 * (sext i32 %m to i64))) ; CHECK-NEXT: SCEV don't match, abort ; CHECK: loop-idiom Scanning: F[NonZeroAddressSpace] Countable Loop %for.cond1.preheader ; CHECK-NEXT: memset size is non-constant ; CHECK-NEXT: pointer is not in address space zero, abort ; CHECK: loop-idiom Scanning: F[NonAffinePointer] Countable Loop %for.body ; CHECK-NEXT: Pointer is not affine, abort define void @MemsetSize_LoopVariant(ptr %ar, i32 %n, i32 %m) { ; CHECK-LABEL: @MemsetSize_LoopVariant( ; CHECK-NEXT: entry: ; CHECK-NEXT: [[CONV:%.*]] = sext i32 [[N:%.*]] to i64 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i64 0, [[CONV]] ; CHECK-NEXT: br i1 [[CMP1]], label [[FOR_BODY_LR_PH:%.*]], label [[FOR_END:%.*]] ; CHECK: for.body.lr.ph: ; CHECK-NEXT: [[CONV1:%.*]] = sext i32 [[M:%.*]] to i64 ; CHECK-NEXT: [[CONV2:%.*]] = sext i32 [[M]] to i64 ; CHECK-NEXT: [[MUL3:%.*]] = mul i64 [[CONV2]], 4 ; CHECK-NEXT: br label [[FOR_BODY:%.*]] ; CHECK: for.body: ; CHECK-NEXT: [[I_02:%.*]] = phi i64 [ 0, [[FOR_BODY_LR_PH]] ], [ [[INC:%.*]], [[FOR_INC:%.*]] ] ; CHECK-NEXT: [[MUL:%.*]] = mul nsw i64 [[I_02]], [[CONV1]] ; CHECK-NEXT: [[ADD_PTR:%.*]] = getelementptr inbounds i32, ptr [[AR:%.*]], i64 [[MUL]] ; CHECK-NEXT: [[ADD:%.*]] = add nsw i64 [[I_02]], [[MUL3]] ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr align 4 [[ADD_PTR]], i8 0, i64 [[ADD]], i1 false) ; CHECK-NEXT: br label [[FOR_INC]] ; CHECK: for.inc: ; CHECK-NEXT: [[INC]] = add nuw nsw i64 [[I_02]], 1 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i64 [[INC]], [[CONV]] ; CHECK-NEXT: br i1 [[CMP]], label [[FOR_BODY]], label [[FOR_COND_FOR_END_CRIT_EDGE:%.*]] ; CHECK: for.cond.for.end_crit_edge: ; CHECK-NEXT: br label [[FOR_END]] ; CHECK: for.end: ; CHECK-NEXT: ret void ; entry: %conv = sext i32 %n to i64 %cmp1 = icmp slt i64 0, %conv br i1 %cmp1, label %for.body.lr.ph, label %for.end for.body.lr.ph: ; preds = %entry %conv1 = sext i32 %m to i64 %conv2 = sext i32 %m to i64 %mul3 = mul i64 %conv2, 4 br label %for.body for.body: ; preds = %for.body.lr.ph, %for.inc %i.02 = phi i64 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ] %mul = mul nsw i64 %i.02, %conv1 %add.ptr = getelementptr inbounds i32, ptr %ar, i64 %mul %add = add nsw i64 %i.02, %mul3 call void @llvm.memset.p0.i64(ptr align 4 %add.ptr, i8 0, i64 %add, i1 false) br label %for.inc for.inc: ; preds = %for.body %inc = add nuw nsw i64 %i.02, 1 %cmp = icmp slt i64 %inc, %conv br i1 %cmp, label %for.body, label %for.cond.for.end_crit_edge for.cond.for.end_crit_edge: ; preds = %for.inc br label %for.end for.end: ; preds = %for.cond.for.end_crit_edge, %entry ret void } ; void test(int *ar, int n, int m) ; { ; long i; ; for (i=0; i