1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt -passes=loop-vectorize,dce,instcombine -force-target-instruction-cost=1 \
3 ; RUN: -prefer-predicate-over-epilogue=scalar-epilogue < %s -S | FileCheck %s
5 target triple = "aarch64-linux-gnu"
7 ; Test a case where the vectorised induction variable is used to
9 ; for (long long i = 0; i < n; i++) {
14 define void @cond_ind64(ptr noalias nocapture %a, ptr noalias nocapture readonly %b, i64 %n) #0 {
15 ; CHECK-LABEL: @cond_ind64(
17 ; CHECK-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
18 ; CHECK-NEXT: [[TMP1:%.*]] = shl i64 [[TMP0]], 2
19 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ugt i64 [[TMP1]], [[N:%.*]]
20 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
22 ; CHECK-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
23 ; CHECK-NEXT: [[TMP3:%.*]] = shl i64 [[TMP2]], 2
24 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[N]], [[TMP3]]
25 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[N]], [[N_MOD_VF]]
26 ; CHECK-NEXT: [[TMP4:%.*]] = call i64 @llvm.vscale.i64()
27 ; CHECK-NEXT: [[TMP5:%.*]] = shl i64 [[TMP4]], 2
28 ; CHECK-NEXT: [[TMP6:%.*]] = call <vscale x 4 x i64> @llvm.experimental.stepvector.nxv4i64()
29 ; CHECK-NEXT: [[TMP7:%.*]] = call i64 @llvm.vscale.i64()
30 ; CHECK-NEXT: [[TMP8:%.*]] = shl i64 [[TMP7]], 2
31 ; CHECK-NEXT: [[DOTSPLATINSERT:%.*]] = insertelement <vscale x 4 x i64> poison, i64 [[TMP8]], i64 0
32 ; CHECK-NEXT: [[DOTSPLAT:%.*]] = shufflevector <vscale x 4 x i64> [[DOTSPLATINSERT]], <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer
33 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
35 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
36 ; CHECK-NEXT: [[VEC_IND:%.*]] = phi <vscale x 4 x i64> [ [[TMP6]], [[VECTOR_PH]] ], [ [[VEC_IND_NEXT:%.*]], [[VECTOR_BODY]] ]
37 ; CHECK-NEXT: [[TMP9:%.*]] = trunc <vscale x 4 x i64> [[VEC_IND]] to <vscale x 4 x i1>
38 ; CHECK-NEXT: [[TMP10:%.*]] = getelementptr i32, ptr [[B:%.*]], i64 [[INDEX]]
39 ; CHECK-NEXT: [[WIDE_MASKED_LOAD:%.*]] = call <vscale x 4 x i32> @llvm.masked.load.nxv4i32.p0(ptr [[TMP10]], i32 4, <vscale x 4 x i1> [[TMP9]], <vscale x 4 x i32> poison)
40 ; CHECK-NEXT: [[TMP11:%.*]] = getelementptr i32, ptr [[A:%.*]], i64 [[INDEX]]
41 ; CHECK-NEXT: call void @llvm.masked.store.nxv4i32.p0(<vscale x 4 x i32> [[WIDE_MASKED_LOAD]], ptr [[TMP11]], i32 4, <vscale x 4 x i1> [[TMP9]])
42 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP5]]
43 ; CHECK-NEXT: [[VEC_IND_NEXT]] = add <vscale x 4 x i64> [[VEC_IND]], [[DOTSPLAT]]
44 ; CHECK-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
45 ; CHECK-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
46 ; CHECK: middle.block:
47 ; CHECK-NEXT: [[CMP_N:%.*]] = icmp eq i64 [[N_MOD_VF]], 0
48 ; CHECK-NEXT: br i1 [[CMP_N]], label [[EXIT:%.*]], label [[SCALAR_PH]]
50 ; CHECK-NEXT: [[BC_RESUME_VAL:%.*]] = phi i64 [ [[N_VEC]], [[MIDDLE_BLOCK]] ], [ 0, [[ENTRY:%.*]] ]
51 ; CHECK-NEXT: br label [[FOR_BODY:%.*]]
53 ; CHECK-NEXT: [[I_08:%.*]] = phi i64 [ [[INC:%.*]], [[FOR_INC:%.*]] ], [ [[BC_RESUME_VAL]], [[SCALAR_PH]] ]
54 ; CHECK-NEXT: [[AND:%.*]] = and i64 [[I_08]], 1
55 ; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i64 [[AND]], 0
56 ; CHECK-NEXT: br i1 [[TOBOOL_NOT]], label [[FOR_INC]], label [[IF_THEN:%.*]]
58 ; CHECK-NEXT: [[ARRAYIDX:%.*]] = getelementptr inbounds i32, ptr [[B]], i64 [[I_08]]
59 ; CHECK-NEXT: [[TMP13:%.*]] = load i32, ptr [[ARRAYIDX]], align 4
60 ; CHECK-NEXT: [[ARRAYIDX1:%.*]] = getelementptr inbounds i32, ptr [[A]], i64 [[I_08]]
61 ; CHECK-NEXT: store i32 [[TMP13]], ptr [[ARRAYIDX1]], align 4
62 ; CHECK-NEXT: br label [[FOR_INC]]
64 ; CHECK-NEXT: [[INC]] = add nuw nsw i64 [[I_08]], 1
65 ; CHECK-NEXT: [[EXITCOND_NOT:%.*]] = icmp eq i64 [[INC]], [[N]]
66 ; CHECK-NEXT: br i1 [[EXITCOND_NOT]], label [[EXIT]], label [[FOR_BODY]], !llvm.loop [[LOOP4:![0-9]+]]
68 ; CHECK-NEXT: ret void
73 for.body: ; preds = %entry, %for.inc
74 %i.08 = phi i64 [ %inc, %for.inc ], [ 0, %entry ]
75 %and = and i64 %i.08, 1
76 %tobool.not = icmp eq i64 %and, 0
77 br i1 %tobool.not, label %for.inc, label %if.then
79 if.then: ; preds = %for.body
80 %arrayidx = getelementptr inbounds i32, ptr %b, i64 %i.08
81 %0 = load i32, ptr %arrayidx, align 4
82 %arrayidx1 = getelementptr inbounds i32, ptr %a, i64 %i.08
83 store i32 %0, ptr %arrayidx1, align 4
86 for.inc: ; preds = %for.body, %if.then
87 %inc = add nuw nsw i64 %i.08, 1
88 %exitcond.not = icmp eq i64 %inc, %n
89 br i1 %exitcond.not, label %exit, label %for.body, !llvm.loop !0
91 exit: ; preds = %for.inc
95 attributes #0 = { "target-features"="+sve" }
97 !0 = distinct !{!0, !1, !2, !3, !4, !5}
98 !1 = !{!"llvm.loop.mustprogress"}
99 !2 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
100 !3 = !{!"llvm.loop.vectorize.enable", i1 true}
101 !4 = !{!"llvm.loop.vectorize.width", i32 4}
102 !5 = !{!"llvm.loop.interleave.count", i32 1}