1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
2 ; RUN: opt -passes=loop-vectorize -force-tail-folding-style=data-with-evl \
3 ; RUN: -prefer-predicate-over-epilogue=predicate-dont-vectorize \
4 ; RUN: -mtriple=riscv64 -mattr=+v -S < %s | FileCheck %s
6 ; Make sure we do not vectorize a loop with a widened int induction.
7 define void @test_wide_integer_induction(ptr noalias %a, i64 %N) {
8 ; CHECK-LABEL: define void @test_wide_integer_induction(
9 ; CHECK-SAME: ptr noalias [[A:%.*]], i64 [[N:%.*]]) #[[ATTR0:[0-9]+]] {
11 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
13 ; CHECK-NEXT: [[IV:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ]
14 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[IV]]
15 ; CHECK-NEXT: store i64 [[IV]], ptr [[ARRAYIDX]], align 8
16 ; CHECK-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1
17 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]]
18 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP:%.*]], label [[FOR_BODY]]
19 ; CHECK: for.cond.cleanup:
20 ; CHECK-NEXT: ret void
26 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
27 %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
28 store i64 %iv, ptr %arrayidx, align 8
29 %iv.next = add nuw nsw i64 %iv, 1
30 %exitcond.not = icmp eq i64 %iv.next, %N
31 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body
37 ; Make sure we do not vectorize a loop with a widened ptr induction.
38 define void @test_wide_ptr_induction(ptr noalias %a, ptr noalias %b, i64 %N) {
39 ; CHECK-LABEL: define void @test_wide_ptr_induction(
40 ; CHECK-SAME: ptr noalias [[A:%.*]], ptr noalias [[B:%.*]], i64 [[N:%.*]]) #[[ATTR0]] {
42 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
44 ; CHECK-NEXT: [[EVL_BASED_IV:%.*]] = phi i64 [ 0, [[VECTOR_PH:%.*]] ], [ [[INDEX_EVL_NEXT:%.*]], [[VECTOR_BODY]] ]
45 ; CHECK-NEXT: [[ADDR:%.*]] = phi ptr [ [[INCDEC_PTR:%.*]], [[VECTOR_BODY]] ], [ [[B]], [[VECTOR_PH]] ]
46 ; CHECK-NEXT: [[INCDEC_PTR]] = getelementptr inbounds i8, ptr [[ADDR]], i64 8
47 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i64, ptr [[A]], i64 [[EVL_BASED_IV]]
48 ; CHECK-NEXT: store ptr [[ADDR]], ptr [[ARRAYIDX]], align 8
49 ; CHECK-NEXT: [[INDEX_EVL_NEXT]] = add nuw nsw i64 [[EVL_BASED_IV]], 1
50 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INDEX_EVL_NEXT]], [[N]]
51 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP:%.*]], label [[VECTOR_BODY]]
52 ; CHECK: for.cond.cleanup:
53 ; CHECK-NEXT: ret void
59 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
60 %addr = phi ptr [ %incdec.ptr, %for.body ], [ %b, %entry ]
61 %incdec.ptr = getelementptr inbounds i8, ptr %addr, i64 8
62 %arrayidx = getelementptr inbounds i64, ptr %a, i64 %iv
63 store ptr %addr, ptr %arrayidx, align 8
64 %iv.next = add nuw nsw i64 %iv, 1
65 %exitcond.not = icmp eq i64 %iv.next, %N
66 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body