2 ; RUN: opt -passes=loop-vectorize -force-vector-interleave=1 -S -debug-only=loop-vectorize < %s 2>%t | FileCheck %s
3 ; RUN: cat %t | FileCheck %s --check-prefix=CHECK-COST
5 target triple = "aarch64-unknown-linux-gnu"
7 ; CHECK-COST: Checking a loop in 'fixed_width'
8 ; CHECK-COST: Found an estimated cost of 12 for VF 2 For instruction: store i32 2, ptr %arrayidx1, align 4
9 ; CHECK-COST: Found an estimated cost of 24 for VF 4 For instruction: store i32 2, ptr %arrayidx1, align 4
10 ; CHECK-COST: Selecting VF: 1.
12 ; We should decide this loop is not worth vectorising using fixed width vectors
13 define void @fixed_width(ptr noalias nocapture %a, ptr noalias nocapture readonly %b, i64 %n) #0 {
14 ; CHECK-LABEL: @fixed_width(
15 ; CHECK-NOT: vector.body
17 %cmp6 = icmp sgt i64 %n, 0
18 br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup
20 for.body.preheader: ; preds = %entry
23 for.cond.cleanup.loopexit: ; preds = %for.inc
24 br label %for.cond.cleanup
26 for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
29 for.body: ; preds = %for.body.preheader, %for.inc
30 %i.07 = phi i64 [ %inc, %for.inc ], [ 0, %for.body.preheader ]
31 %arrayidx = getelementptr inbounds i32, ptr %b, i64 %i.07
32 %0 = load i32, ptr %arrayidx, align 4
33 %tobool.not = icmp eq i32 %0, 0
34 br i1 %tobool.not, label %for.inc, label %if.then
36 if.then: ; preds = %for.body
37 %arrayidx1 = getelementptr inbounds i32, ptr %a, i64 %i.07
38 store i32 2, ptr %arrayidx1, align 4
41 for.inc: ; preds = %for.body, %if.then
42 %inc = add nuw nsw i64 %i.07, 1
43 %exitcond.not = icmp eq i64 %inc, %n
44 br i1 %exitcond.not, label %for.cond.cleanup.loopexit, label %for.body, !llvm.loop !5
48 ; CHECK-COST: Checking a loop in 'scalable'
49 ; CHECK-COST: Found an estimated cost of 1 for VF vscale x 4 For instruction: store i32 2, ptr %arrayidx1, align 4
51 define void @scalable(ptr noalias nocapture %a, ptr noalias nocapture readonly %b, i64 %n) #0 {
52 ; CHECK-LABEL: @scalable(
54 ; CHECK: call void @llvm.masked.store.nxv4i32.p0
56 %cmp6 = icmp sgt i64 %n, 0
57 br i1 %cmp6, label %for.body.preheader, label %for.cond.cleanup
59 for.body.preheader: ; preds = %entry
62 for.cond.cleanup.loopexit: ; preds = %for.inc
63 br label %for.cond.cleanup
65 for.cond.cleanup: ; preds = %for.cond.cleanup.loopexit, %entry
68 for.body: ; preds = %for.body.preheader, %for.inc
69 %i.07 = phi i64 [ %inc, %for.inc ], [ 0, %for.body.preheader ]
70 %arrayidx = getelementptr inbounds i32, ptr %b, i64 %i.07
71 %0 = load i32, ptr %arrayidx, align 4
72 %tobool.not = icmp eq i32 %0, 0
73 br i1 %tobool.not, label %for.inc, label %if.then
75 if.then: ; preds = %for.body
76 %arrayidx1 = getelementptr inbounds i32, ptr %a, i64 %i.07
77 store i32 2, ptr %arrayidx1, align 4
80 for.inc: ; preds = %for.body, %if.then
81 %inc = add nuw nsw i64 %i.07, 1
82 %exitcond.not = icmp eq i64 %inc, %n
83 br i1 %exitcond.not, label %for.cond.cleanup.loopexit, label %for.body, !llvm.loop !0
86 attributes #0 = { "target-features"="+neon,+sve" }
88 !0 = distinct !{!0, !1, !2, !3, !4}
89 !1 = !{!"llvm.loop.mustprogress"}
90 !2 = !{!"llvm.loop.vectorize.width", i32 4}
91 !3 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
92 !4 = !{!"llvm.loop.vectorize.enable", i1 true}
93 !5 = distinct !{!5, !6}
94 !6 = !{!"llvm.loop.vectorize.scalable.enable", i1 false}