1; RUN: opt -mtriple aarch64-linux-gnu -mattr=+sve -loop-vectorize -dce -instcombine -S \
2; RUN:   -prefer-predicate-over-epilogue=scalar-epilogue <%s | FileCheck %s
3
4define void @stride7_i32(i32* noalias nocapture %dst, i64 %n) #0 {
5; CHECK-LABEL: @stride7_i32(
6; CHECK:      vector.body
7; CHECK:        %[[VEC_IND:.*]] = phi <vscale x 4 x i64> [ %{{.*}}, %vector.ph ], [ %{{.*}}, %vector.body ]
8; CHECK-NEXT:   %[[PTR_INDICES:.*]] = mul nuw nsw <vscale x 4 x i64> %[[VEC_IND]], shufflevector (<vscale x 4 x i64> insertelement (<vscale x 4 x i64> poison, i64 7, i32 0), <vscale x 4 x i64> poison, <vscale x 4 x i32> zeroinitializer)
9; CHECK-NEXT:   %[[PTRS:.*]] = getelementptr inbounds i32, i32* %dst, <vscale x 4 x i64> %[[PTR_INDICES]]
10; CHECK-NEXT:   %[[GLOAD:.*]] = call <vscale x 4 x i32> @llvm.masked.gather.nxv4i32.nxv4p0i32(<vscale x 4 x i32*> %[[PTRS]]
11; CHECK-NEXT:   %[[VALS:.*]] = add nsw <vscale x 4 x i32> %[[GLOAD]],
12; CHECK-NEXT:   call void @llvm.masked.scatter.nxv4i32.nxv4p0i32(<vscale x 4 x i32> %[[VALS]], <vscale x 4 x i32*> %[[PTRS]]
13entry:
14  br label %for.body
15
16for.body:                                         ; preds = %entry, %for.body
17  %i.05 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
18  %mul = mul nuw nsw i64 %i.05, 7
19  %arrayidx = getelementptr inbounds i32, i32* %dst, i64 %mul
20  %0 = load i32, i32* %arrayidx, align 4
21  %add = add nsw i32 %0, 3
22  store i32 %add, i32* %arrayidx, align 4
23  %inc = add nuw nsw i64 %i.05, 1
24  %exitcond.not = icmp eq i64 %inc, %n
25  br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !0
26
27for.end:                                          ; preds = %for.end.loopexit, %entry
28  ret void
29}
30
31define void @stride7_f64(double* noalias nocapture %dst, i64 %n) #0 {
32; CHECK-LABEL: @stride7_f64(
33; CHECK:      vector.body
34; CHECK:        %[[VEC_IND:.*]] = phi <vscale x 2 x i64> [ %{{.*}}, %vector.ph ], [ %{{.*}}, %vector.body ]
35; CHECK-NEXT:   %[[PTR_INDICES:.*]] = mul nuw nsw <vscale x 2 x i64> %[[VEC_IND]], shufflevector (<vscale x 2 x i64> insertelement (<vscale x 2 x i64> poison, i64 7, i32 0), <vscale x 2 x i64> poison, <vscale x 2 x i32> zeroinitializer)
36; CHECK-NEXT:   %[[PTRS:.*]] = getelementptr inbounds double, double* %dst, <vscale x 2 x i64> %[[PTR_INDICES]]
37; CHECK-NEXT:   %[[GLOAD:.*]] = call <vscale x 2 x double> @llvm.masked.gather.nxv2f64.nxv2p0f64(<vscale x 2 x double*> %[[PTRS]],
38; CHECK-NEXT:   %[[VALS:.*]] = fadd <vscale x 2 x double> %[[GLOAD]],
39; CHECK-NEXT:  call void @llvm.masked.scatter.nxv2f64.nxv2p0f64(<vscale x 2 x double> %[[VALS]], <vscale x 2 x double*> %[[PTRS]],
40entry:
41  br label %for.body
42
43for.body:                                         ; preds = %entry, %for.body
44  %i.05 = phi i64 [ %inc, %for.body ], [ 0, %entry ]
45  %mul = mul nuw nsw i64 %i.05, 7
46  %arrayidx = getelementptr inbounds double, double* %dst, i64 %mul
47  %0 = load double, double* %arrayidx, align 8
48  %add = fadd double %0, 1.000000e+00
49  store double %add, double* %arrayidx, align 8
50  %inc = add nuw nsw i64 %i.05, 1
51  %exitcond.not = icmp eq i64 %inc, %n
52  br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !6
53
54for.end:                                          ; preds = %for.end.loopexit, %entry
55  ret void
56}
57
58
59define void @cond_stride7_f64(double* noalias nocapture %dst, i64* noalias nocapture readonly %cond, i64 %n) #0 {
60; CHECK-LABEL: @cond_stride7_f64(
61; CHECK:      vector.body
62; CHECK:        %[[MASK:.*]] = icmp ne <vscale x 2 x i64>
63; CHECK:        %[[PTRS:.*]] = getelementptr inbounds double, double* %dst, <vscale x 2 x i64> %{{.*}}
64; CHECK-NEXT:   %[[GLOAD:.*]] = call <vscale x 2 x double> @llvm.masked.gather.nxv2f64.nxv2p0f64(<vscale x 2 x double*> %[[PTRS]], i32 8, <vscale x 2 x i1> %[[MASK]]
65; CHECK-NEXT:   %[[VALS:.*]] = fadd <vscale x 2 x double> %[[GLOAD]],
66; CHECK-NEXT:  call void @llvm.masked.scatter.nxv2f64.nxv2p0f64(<vscale x 2 x double> %[[VALS]], <vscale x 2 x double*> %[[PTRS]], i32 8, <vscale x 2 x i1> %[[MASK]])
67entry:
68  br label %for.body
69
70for.body:                                         ; preds = %entry, %for.inc
71  %i.07 = phi i64 [ %inc, %for.inc ], [ 0, %entry ]
72  %arrayidx = getelementptr inbounds i64, i64* %cond, i64 %i.07
73  %0 = load i64, i64* %arrayidx, align 8
74  %tobool.not = icmp eq i64 %0, 0
75  br i1 %tobool.not, label %for.inc, label %if.then
76
77if.then:                                          ; preds = %for.body
78  %mul = mul nsw i64 %i.07, 7
79  %arrayidx1 = getelementptr inbounds double, double* %dst, i64 %mul
80  %1 = load double, double* %arrayidx1, align 8
81  %add = fadd double %1, 1.000000e+00
82  store double %add, double* %arrayidx1, align 8
83  br label %for.inc
84
85for.inc:                                          ; preds = %for.body, %if.then
86  %inc = add nuw nsw i64 %i.07, 1
87  %exitcond.not = icmp eq i64 %inc, %n
88  br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !6
89
90for.end:                                          ; preds = %for.end.loopexit, %entry
91  ret void
92}
93
94attributes #0 = { vscale_range(1, 16) }
95!0 = distinct !{!0, !1, !2, !3, !4, !5}
96!1 = !{!"llvm.loop.mustprogress"}
97!2 = !{!"llvm.loop.vectorize.width", i32 4}
98!3 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
99!4 = !{!"llvm.loop.interleave.count", i32 1}
100!5 = !{!"llvm.loop.vectorize.enable", i1 true}
101!6 = distinct !{!6, !1, !7, !3, !4, !5}
102!7 = !{!"llvm.loop.vectorize.width", i32 2}
103