1; RUN: opt < %s -loop-vectorize -S | FileCheck %s
2; RUN: opt < %s -loop-vectorize -prefer-predicate-over-epilogue=predicate-dont-vectorize -S | FileCheck %s
3
4target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
5target triple = "aarch64-unknown-linux-gnu"
6
7; The test predication_in_loop corresponds
8; to the following function
9;   for (long long i = 0; i < 1024; i++) {
10;    if (cond[i])
11;      a[i] /= b[i];
12;  }
13
14; Scalarizing the division cannot be done for scalable vectors at the moment
15; when the loop needs predication
16; Future implementation of llvm.vp could allow this to happen
17
18define void  @predication_in_loop(i32* %a, i32* %b, i32* %cond) #0 {
19; CHECK-LABEL: @predication_in_loop
20; CHECK-NOT:  sdiv <vscale x 4 x i32>
21;
22entry:
23  br label %for.body
24
25for.cond.cleanup:                                 ; preds = %for.inc, %entry
26  ret void
27
28for.body:                                         ; preds = %entry, %for.inc
29  %i.09 = phi i64 [ %inc, %for.inc ], [ 0, %entry ]
30  %arrayidx = getelementptr inbounds i32, i32* %cond, i64 %i.09
31  %0 = load i32, i32* %arrayidx, align 4
32  %tobool.not = icmp eq i32 %0, 0
33  br i1 %tobool.not, label %for.inc, label %if.then
34
35if.then:                                          ; preds = %for.body
36  %arrayidx1 = getelementptr inbounds i32, i32* %b, i64 %i.09
37  %1 = load i32, i32* %arrayidx1, align 4
38  %arrayidx2 = getelementptr inbounds i32, i32* %a, i64 %i.09
39  %2 = load i32, i32* %arrayidx2, align 4
40  %div = sdiv i32 %2, %1
41  store i32 %div, i32* %arrayidx2, align 4
42  br label %for.inc
43
44for.inc:                                          ; preds = %for.body, %if.then
45  %inc = add nuw nsw i64 %i.09, 1
46  %exitcond.not = icmp eq i64 %inc, 1024
47  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body, !llvm.loop !0
48}
49
50
51;
52; This test unpredicated_loop_predication_through_tailfolding corresponds
53; to the following function
54;   for (long long i = 0; i < 1024; i++) {
55;      a[i] /= b[i];
56;  }
57
58; Scalarization not possible in the main loop when there is no predication and
59; epilogue should not be able to allow scalarization
60; otherwise it could  be able to vectorize, but will not because
61; "Max legal vector width too small, scalable vectorization unfeasible.."
62
63define void @unpredicated_loop_predication_through_tailfolding(i32* %a, i32* %b) #0 {
64; CHECK-LABEL: @unpredicated_loop_predication_through_tailfolding
65; CHECK-NOT:  sdiv <vscale x 4 x i32>
66
67entry:
68  br label %loop
69
70loop:
71  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
72  %arrayidx = getelementptr inbounds i32, i32* %a, i64 %iv
73  %0 = load i32, i32* %arrayidx, align 4
74  %arrayidx2 = getelementptr inbounds i32, i32* %b, i64 %iv
75  %1 = load i32, i32* %arrayidx2, align 4
76  %sdiv = sdiv i32 %1, %0
77  %2 = add nuw nsw i64 %iv, 8
78  %arrayidx5 = getelementptr inbounds i32, i32* %a, i64 %2
79  store i32 %sdiv, i32* %arrayidx5, align 4
80  %iv.next = add nuw nsw i64 %iv, 1
81  %exitcond.not = icmp eq i64 %iv.next, 1024
82  br i1 %exitcond.not, label %exit, label %loop, !llvm.loop !0
83
84exit:
85  ret void
86
87}
88
89attributes #0 = { "target-features"="+sve" }
90
91!0 = distinct !{!0, !1, !2, !3, !4}
92!1 = !{!"llvm.loop.vectorize.width", i32 4}
93!2 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
94!3 = !{!"llvm.loop.interleave.count", i32 1}
95!4 = !{!"llvm.loop.vectorize.enable", i1 true}
96