1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes=loop-vectorize -mtriple=aarch64--linux-gnu -mattr=+neon -force-vector-width=2 -force-vector-interleave=1 \
3 ; RUN: -prefer-predicate-over-epilogue=scalar-epilogue -S -o - | FileCheck %s
4 ; RUN: opt < %s -passes=loop-vectorize -mtriple=aarch64--linux-gnu -mattr=+sve -force-vector-width=2 -force-vector-interleave=1 \
5 ; RUN: -prefer-predicate-over-epilogue=scalar-epilogue -scalable-vectorization=on -S -o - | FileCheck --check-prefix=SVE %s
7 define dso_local double @test(ptr nocapture noundef readonly %data, ptr nocapture noundef readonly %offset, i32 noundef %size) local_unnamed_addr {
10 ; CHECK-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[SIZE:%.*]], 0
11 ; CHECK-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
12 ; CHECK: for.body.preheader:
13 ; CHECK-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[SIZE]] to i64
14 ; CHECK-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[WIDE_TRIP_COUNT]], 2
15 ; CHECK-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
17 ; CHECK-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[WIDE_TRIP_COUNT]], 2
18 ; CHECK-NEXT: [[N_VEC:%.*]] = sub i64 [[WIDE_TRIP_COUNT]], [[N_MOD_VF]]
19 ; CHECK-NEXT: br label [[VECTOR_BODY:%.*]]
21 ; CHECK-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
22 ; CHECK-NEXT: [[VEC_PHI:%.*]] = phi <2 x double> [ <double 0.000000e+00, double -0.000000e+00>, [[VECTOR_PH]] ], [ [[TMP14:%.*]], [[VECTOR_BODY]] ]
23 ; CHECK-NEXT: [[TMP0:%.*]] = add i64 [[INDEX]], 0
24 ; CHECK-NEXT: [[TMP1:%.*]] = add i64 [[INDEX]], 1
25 ; CHECK-NEXT: [[TMP2:%.*]] = getelementptr inbounds i32, ptr [[OFFSET:%.*]], i64 [[TMP0]]
26 ; CHECK-NEXT: [[TMP3:%.*]] = getelementptr inbounds i32, ptr [[OFFSET]], i64 [[TMP1]]
27 ; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr [[TMP2]], align 4
28 ; CHECK-NEXT: [[TMP5:%.*]] = load i32, ptr [[TMP3]], align 4
29 ; CHECK-NEXT: [[TMP6:%.*]] = sext i32 [[TMP4]] to i64
30 ; CHECK-NEXT: [[TMP7:%.*]] = sext i32 [[TMP5]] to i64
31 ; CHECK-NEXT: [[TMP8:%.*]] = getelementptr inbounds double, ptr [[DATA:%.*]], i64 [[TMP6]]
32 ; CHECK-NEXT: [[TMP9:%.*]] = getelementptr inbounds double, ptr [[DATA]], i64 [[TMP7]]
33 ; CHECK-NEXT: [[TMP10:%.*]] = load double, ptr [[TMP8]], align 8
34 ; CHECK-NEXT: [[TMP11:%.*]] = load double, ptr [[TMP9]], align 8
35 ; CHECK-NEXT: [[TMP12:%.*]] = insertelement <2 x double> poison, double [[TMP10]], i32 0
36 ; CHECK-NEXT: [[TMP13:%.*]] = insertelement <2 x double> [[TMP12]], double [[TMP11]], i32 1
37 ; CHECK-NEXT: [[TMP14]] = fadd <2 x double> [[VEC_PHI]], [[TMP13]]
38 ; CHECK-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], 2
39 ; CHECK-NEXT: [[TMP15:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
40 ; CHECK-NEXT: br i1 [[TMP15]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
44 ; SVE-NEXT: [[CMP6:%.*]] = icmp sgt i32 [[SIZE:%.*]], 0
45 ; SVE-NEXT: br i1 [[CMP6]], label [[FOR_BODY_PREHEADER:%.*]], label [[FOR_COND_CLEANUP:%.*]]
46 ; SVE: for.body.preheader:
47 ; SVE-NEXT: [[WIDE_TRIP_COUNT:%.*]] = zext i32 [[SIZE]] to i64
48 ; SVE-NEXT: [[TMP0:%.*]] = call i64 @llvm.vscale.i64()
49 ; SVE-NEXT: [[TMP1:%.*]] = mul i64 [[TMP0]], 2
50 ; SVE-NEXT: [[MIN_ITERS_CHECK:%.*]] = icmp ult i64 [[WIDE_TRIP_COUNT]], [[TMP1]]
51 ; SVE-NEXT: br i1 [[MIN_ITERS_CHECK]], label [[SCALAR_PH:%.*]], label [[VECTOR_PH:%.*]]
53 ; SVE-NEXT: [[TMP2:%.*]] = call i64 @llvm.vscale.i64()
54 ; SVE-NEXT: [[TMP3:%.*]] = mul i64 [[TMP2]], 2
55 ; SVE-NEXT: [[N_MOD_VF:%.*]] = urem i64 [[WIDE_TRIP_COUNT]], [[TMP3]]
56 ; SVE-NEXT: [[N_VEC:%.*]] = sub i64 [[WIDE_TRIP_COUNT]], [[N_MOD_VF]]
57 ; SVE-NEXT: [[TMP10:%.*]] = call i64 @llvm.vscale.i64()
58 ; SVE-NEXT: [[TMP11:%.*]] = mul i64 [[TMP10]], 2
59 ; SVE-NEXT: br label [[VECTOR_BODY:%.*]]
61 ; SVE-NEXT: [[INDEX:%.*]] = phi i64 [ 0, [[VECTOR_PH]] ], [ [[INDEX_NEXT:%.*]], [[VECTOR_BODY]] ]
62 ; SVE-NEXT: [[VEC_PHI:%.*]] = phi <vscale x 2 x double> [ insertelement (<vscale x 2 x double> shufflevector (<vscale x 2 x double> insertelement (<vscale x 2 x double> poison, double -0.000000e+00, i64 0), <vscale x 2 x double> poison, <vscale x 2 x i32> zeroinitializer), double 0.000000e+00, i32 0), [[VECTOR_PH]] ], [ [[TMP9:%.*]], [[VECTOR_BODY]] ]
63 ; SVE-NEXT: [[TMP4:%.*]] = add i64 [[INDEX]], 0
64 ; SVE-NEXT: [[TMP5:%.*]] = getelementptr inbounds i32, ptr [[OFFSET:%.*]], i64 [[TMP4]]
65 ; SVE-NEXT: [[TMP6:%.*]] = getelementptr inbounds i32, ptr [[TMP5]], i32 0
66 ; SVE-NEXT: [[WIDE_LOAD:%.*]] = load <vscale x 2 x i32>, ptr [[TMP6]], align 4
67 ; SVE-NEXT: [[TMP7:%.*]] = sext <vscale x 2 x i32> [[WIDE_LOAD]] to <vscale x 2 x i64>
68 ; SVE-NEXT: [[TMP8:%.*]] = getelementptr inbounds double, ptr [[DATA:%.*]], <vscale x 2 x i64> [[TMP7]]
69 ; SVE-NEXT: [[WIDE_MASKED_GATHER:%.*]] = call <vscale x 2 x double> @llvm.masked.gather.nxv2f64.nxv2p0(<vscale x 2 x ptr> [[TMP8]], i32 8, <vscale x 2 x i1> shufflevector (<vscale x 2 x i1> insertelement (<vscale x 2 x i1> poison, i1 true, i64 0), <vscale x 2 x i1> poison, <vscale x 2 x i32> zeroinitializer), <vscale x 2 x double> poison)
70 ; SVE-NEXT: [[TMP9]] = fadd <vscale x 2 x double> [[VEC_PHI]], [[WIDE_MASKED_GATHER]]
71 ; SVE-NEXT: [[INDEX_NEXT]] = add nuw i64 [[INDEX]], [[TMP11]]
72 ; SVE-NEXT: [[TMP12:%.*]] = icmp eq i64 [[INDEX_NEXT]], [[N_VEC]]
73 ; SVE-NEXT: br i1 [[TMP12]], label [[MIDDLE_BLOCK:%.*]], label [[VECTOR_BODY]], !llvm.loop [[LOOP0:![0-9]+]]
76 %cmp6 = icmp sgt i32 %size, 0
77 br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup
79 for.body.preheader: ; preds = %entry
80 %wide.trip.count = zext i32 %size to i64
83 for.cond.cleanup.loopexit: ; preds = %for.body
84 %add.lcssa = phi double [ %add, %for.body ]
85 br label %for.cond.cleanup
87 for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
88 %res.0.lcssa = phi double [ 0.000000e+00, %entry ], [ %add.lcssa, %for.cond.cleanup.loopexit ]
89 ret double %res.0.lcssa
91 for.body: ; preds = %for.body.preheader, %for.body
92 %indvars.iv = phi i64 [ 0, %for.body.preheader ], [ %indvars.iv.next, %for.body ]
93 %res.07 = phi double [ 0.000000e+00, %for.body.preheader ], [ %add, %for.body ]
94 %arrayidx = getelementptr inbounds i32, ptr %offset, i64 %indvars.iv
95 %0 = load i32, ptr %arrayidx, align 4
96 %idxprom1 = sext i32 %0 to i64
97 %arrayidx2 = getelementptr inbounds double, ptr %data, i64 %idxprom1
98 %1 = load double, ptr %arrayidx2, align 8
99 %add = fadd double %res.07, %1
100 %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
101 %exitcond.not = icmp eq i64 %indvars.iv.next, %wide.trip.count
102 br i1 %exitcond.not, label %for.cond.cleanup.loopexit, label %for.body