1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -passes=loop-vectorize \ 3; RUN: -force-tail-folding-style=data-with-evl \ 4; RUN: -prefer-predicate-over-epilogue=predicate-dont-vectorize \ 5; RUN: -mtriple=riscv64 -mattr=+v -S < %s | FileCheck --check-prefix=IF-EVL %s 6 7; RUN: opt -passes=loop-vectorize \ 8; RUN: -force-tail-folding-style=none \ 9; RUN: -prefer-predicate-over-epilogue=predicate-else-scalar-epilogue \ 10; RUN: -mtriple=riscv64 -mattr=+v -S < %s | FileCheck --check-prefix=NO-VP %s 11 12define void @foo(ptr noalias %a, ptr noalias %b, ptr noalias %c, i64 %N) { 13; IF-EVL-LABEL: @foo( 14; IF-EVL-NEXT: entry: 15; IF-EVL-NEXT: [[TMP0:%.*]] = sub i64 -1, [[N:%.*]] 16; IF-EVL-NEXT: [[TMP1:%.*]] = call i64 @llvm.vscale.i64() 17; IF-EVL-NEXT: [[TMP2:%.*]] = mul i64 [[TMP1]], 4 18; IF-EVL-NEXT: [[TMP3:%.*]] = icmp ult i64 [[TMP0]], [[TMP2]] 19; IF-EVL-NEXT: br i1 [[TMP3]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]] 20; IF-EVL: vector.ph: 21; IF-EVL-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64() 22; IF-EVL-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 4 23; IF-EVL-NEXT: [[TMP8:%.*]] = sub i64 [[TMP5]], 1 24; IF-EVL-NEXT: [[N_RND_UP:%.*]] = add i64 [[N]], [[TMP8]] 25; IF-EVL-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N_RND_UP]], [[TMP5]] 26; IF-EVL-NEXT: [[N_VEC:%.*]] = sub i64 [[N_RND_UP]], [[N_MOD_VF]] 27; IF-EVL-NEXT: [[TMP9:%.*]] = call i64 @llvm.vscale.i64() 28; IF-EVL-NEXT: [[TMP10:%.*]] = mul i64 [[TMP9]], 4 29; IF-EVL-NEXT: br label [[VECTOR_BODY:%.*]] 30; IF-EVL: vector.body: 31; IF-EVL-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] 32; IF-EVL-NEXT: [[EVL_BASED_IV:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_EVL_NEXT:%.*]], [[VECTOR_BODY]] ] 33; IF-EVL-NEXT: [[TMP11:%.*]] = sub i64 [[N]], [[EVL_BASED_IV]] 34; IF-EVL-NEXT: [[TMP12:%.*]] = call i32 @llvm.experimental.get.vector.length.i64(i64 [[TMP11]], i32 4, i1 true) 35; IF-EVL-NEXT: [[TMP13:%.*]] = add i64 [[EVL_BASED_IV]], 0 36; IF-EVL-NEXT: [[TMP14:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i64 [[TMP13]] 37; IF-EVL-NEXT: [[TMP15:%.*]] = getelementptr inbounds i32, ptr [[TMP14]], i32 0 38; IF-EVL-NEXT: [[VP_OP_LOAD:%.*]] = call <vscale x 4 x i32> @llvm.vp.load.nxv4i32.p0(ptr align 4 [[TMP15]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP12]]) 39; IF-EVL-NEXT: [[TMP16:%.*]] = getelementptr inbounds i32, ptr [[C:%.*]], i64 [[TMP13]] 40; IF-EVL-NEXT: [[TMP17:%.*]] = getelementptr inbounds i32, ptr [[TMP16]], i32 0 41; IF-EVL-NEXT: [[VP_OP_LOAD1:%.*]] = call <vscale x 4 x i32> @llvm.vp.load.nxv4i32.p0(ptr align 4 [[TMP17]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP12]]) 42; IF-EVL-NEXT: [[VP_OP:%.*]] = call <vscale x 4 x i32> @llvm.vp.add.nxv4i32(<vscale x 4 x i32> [[VP_OP_LOAD1]], <vscale x 4 x i32> [[VP_OP_LOAD]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP12]]) 43; IF-EVL-NEXT: [[TMP18:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[TMP13]] 44; IF-EVL-NEXT: [[TMP19:%.*]] = getelementptr inbounds i32, ptr [[TMP18]], i32 0 45; IF-EVL-NEXT: call void @llvm.vp.store.nxv4i32.p0(<vscale x 4 x i32> [[VP_OP]], ptr align 4 [[TMP19]], <vscale x 4 x i1> splat (i1 true), i32 [[TMP12]]) 46; IF-EVL-NEXT: [[TMP20:%.*]] = zext i32 [[TMP12]] to i64 47; IF-EVL-NEXT: [[INDEX_EVL_NEXT]] = add i64 [[TMP20]], [[EVL_BASED_IV]] 48; IF-EVL-NEXT: [[INDEX_NEXT]] = add i64 [[INDEX]], [[TMP10]] 49; IF-EVL-NEXT: [[TMP21:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] 50; IF-EVL-NEXT: br i1 [[TMP21]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] 51; IF-EVL: middle.block: 52; IF-EVL-NEXT: br i1 true, label [[FOR_COND_CLEANUP:%.*]], label [[SCALAR_PH]] 53; IF-EVL: scalar.ph: 54; IF-EVL-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ] 55; IF-EVL-NEXT: br label [[FOR_BODY:%.*]] 56; IF-EVL: for.body: 57; IF-EVL-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ] 58; IF-EVL-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[IV]] 59; IF-EVL-NEXT: [[TMP22:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 60; IF-EVL-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[IV]] 61; IF-EVL-NEXT: [[TMP23:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4 62; IF-EVL-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP23]], [[TMP22]] 63; IF-EVL-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[IV]] 64; IF-EVL-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX4]], align 4 65; IF-EVL-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1 66; IF-EVL-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]] 67; IF-EVL-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]] 68; IF-EVL: for.cond.cleanup: 69; IF-EVL-NEXT: ret void 70; 71; NO-VP-LABEL: @foo( 72; NO-VP-NEXT: entry: 73; NO-VP-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64() 74; NO-VP-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 4 75; NO-VP-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[N:%.*]], [[TMP1]] 76; NO-VP-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]] 77; NO-VP: vector.ph: 78; NO-VP-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64() 79; NO-VP-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 4 80; NO-VP-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N]], [[TMP3]] 81; NO-VP-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]] 82; NO-VP-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64() 83; NO-VP-NEXT: [[TMP5:%.*]] = mul i64 [[TMP4]], 4 84; NO-VP-NEXT: br label [[VECTOR_BODY:%.*]] 85; NO-VP: vector.body: 86; NO-VP-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ] 87; NO-VP-NEXT: [[TMP6:%.*]] = add i64 [[INDEX]], 0 88; NO-VP-NEXT: [[TMP7:%.*]] = getelementptr inbounds i32, ptr [[B:%.*]], i64 [[TMP6]] 89; NO-VP-NEXT: [[TMP8:%.*]] = getelementptr inbounds i32, ptr [[TMP7]], i32 0 90; NO-VP-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 4 x i32>, ptr [[TMP8]], align 4 91; NO-VP-NEXT: [[TMP9:%.*]] = getelementptr inbounds i32, ptr [[C:%.*]], i64 [[TMP6]] 92; NO-VP-NEXT: [[TMP10:%.*]] = getelementptr inbounds i32, ptr [[TMP9]], i32 0 93; NO-VP-NEXT: [[WIDE_LOAD1:%.*]] = load <vscale x 4 x i32>, ptr [[TMP10]], align 4 94; NO-VP-NEXT: [[TMP11:%.*]] = add nsw <vscale x 4 x i32> [[WIDE_LOAD1]], [[WIDE_LOAD]] 95; NO-VP-NEXT: [[TMP12:%.*]] = getelementptr inbounds i32, ptr [[A:%.*]], i64 [[TMP6]] 96; NO-VP-NEXT: [[TMP13:%.*]] = getelementptr inbounds i32, ptr [[TMP12]], i32 0 97; NO-VP-NEXT: store <vscale x 4 x i32> [[TMP11]], ptr [[TMP13]], align 4 98; NO-VP-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]] 99; NO-VP-NEXT: [[TMP14:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]] 100; NO-VP-NEXT: br i1 [[TMP14]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]] 101; NO-VP: middle.block: 102; NO-VP-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N]], [[N_VEC]] 103; NO-VP-NEXT: br i1 [[CMP_N]], label [[FOR_COND_CLEANUP:%.*]], label [[SCALAR_PH]] 104; NO-VP: scalar.ph: 105; NO-VP-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ] 106; NO-VP-NEXT: br label [[FOR_BODY:%.*]] 107; NO-VP: for.body: 108; NO-VP-NEXT: [[IV:%.*]] = phi i64 [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ], [ [[IV_NEXT:%.*]], [[FOR_BODY]] ] 109; NO-VP-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[IV]] 110; NO-VP-NEXT: [[TMP15:%.*]] = load i32, ptr [[ARRAYIDX]], align 4 111; NO-VP-NEXT: [[ARRAYIDX2:%.*]] = getelementptr inbounds i32, ptr [[C]], i64 [[IV]] 112; NO-VP-NEXT: [[TMP16:%.*]] = load i32, ptr [[ARRAYIDX2]], align 4 113; NO-VP-NEXT: [[ADD:%.*]] = add nsw i32 [[TMP16]], [[TMP15]] 114; NO-VP-NEXT: [[ARRAYIDX4:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[IV]] 115; NO-VP-NEXT: store i32 [[ADD]], ptr [[ARRAYIDX4]], align 4 116; NO-VP-NEXT: [[IV_NEXT]] = add nuw nsw i64 [[IV]], 1 117; NO-VP-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[IV_NEXT]], [[N]] 118; NO-VP-NEXT: br i1 [[EXITCOND_NOT]], label [[FOR_COND_CLEANUP]], label [[FOR_BODY]], !llvm.loop [[LOOP3:![0-9]+]] 119; NO-VP: for.cond.cleanup: 120; NO-VP-NEXT: ret void 121; 122entry: 123 br label %for.body 124 125for.body: 126 %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ] 127 %arrayidx = getelementptr inbounds i32, ptr %b, i64 %iv 128 %0 = load i32, ptr %arrayidx, align 4 129 %arrayidx2 = getelementptr inbounds i32, ptr %c, i64 %iv 130 %1 = load i32, ptr %arrayidx2, align 4 131 %add = add nsw i32 %1, %0 132 %arrayidx4 = getelementptr inbounds i32, ptr %a, i64 %iv 133 store i32 %add, ptr %arrayidx4, align 4 134 %iv.next = add nuw nsw i64 %iv, 1 135 %exitcond.not = icmp eq i64 %iv.next, %N 136 br i1 %exitcond.not, label %for.cond.cleanup, label %for.body 137 138for.cond.cleanup: 139 ret void 140} 141