1; RUN: opt -S -loop-vectorize -mattr=+sve -mtriple aarch64-linux-gnu \
2; RUN:   -prefer-predicate-over-epilogue=scalar-epilogue < %s | FileCheck %s
3
4define void @invariant_load(i64 %n, i32* noalias nocapture %a, i32* nocapture readonly %b) {
5; CHECK-LABEL: @invariant_load
6; CHECK: vector.body:
7; CHECK: %[[GEP:.*]] = getelementptr inbounds i32, i32* %b, i64 42
8; CHECK-NEXT: %[[INVLOAD:.*]] = load i32, i32* %[[GEP]]
9; CHECK-NEXT: %[[SPLATINS:.*]] = insertelement <vscale x 4 x i32> poison, i32 %[[INVLOAD]], i32 0
10; CHECK-NEXT: %[[SPLAT:.*]] = shufflevector <vscale x 4 x i32> %[[SPLATINS]], <vscale x 4 x i32> poison, <vscale x 4 x i32> zeroinitializer
11; CHECK: %[[LOAD:.*]] = load <vscale x 4 x i32>, <vscale x 4 x i32>*
12; CHECK-NEXT: %[[ADD:.*]] = add nsw <vscale x 4 x i32> %[[SPLAT]], %[[LOAD]]
13; CHECK: store <vscale x 4 x i32> %[[ADD]], <vscale x 4 x i32>*
14entry:
15  br label %for.body
16
17for.body:                                         ; preds = %for.body.lr.ph, %for.body
18  %iv = phi i64 [ 0, %entry ], [ %iv.next, %for.body ]
19  %arrayidx = getelementptr inbounds i32, i32* %b, i64 42
20  %0 = load i32, i32* %arrayidx, align 4
21  %arrayidx1 = getelementptr inbounds i32, i32* %b, i64 %iv
22  %1 = load i32, i32* %arrayidx1, align 4
23  %add = add nsw i32 %0, %1
24  %arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %iv
25  store i32 %add, i32* %arrayidx2, align 4
26  %iv.next = add nuw nsw i64 %iv, 1
27  %exitcond.not = icmp eq i64 %iv.next, %n
28  br i1 %exitcond.not, label %for.end, label %for.body, !llvm.loop !1
29
30for.end:                                          ; preds = %for.body
31  ret void
32}
33
34!1 = distinct !{!1, !2, !3, !4}
35!2 = !{!"llvm.loop.vectorize.width", i32 4}
36!3 = !{!"llvm.loop.interleave.count", i32 1}
37!4 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
38