xref: /llvm-project/llvm/test/Transforms/LoopVectorize/AArch64/scalable-predicate-instruction.ll (revision 7d7577256b76e4293f455b8093504d5f7044ab4b)
1; RUN: opt < %s -passes=loop-vectorize -S | FileCheck %s
2; RUN: opt < %s -passes=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
14define void  @predication_in_loop(ptr %a, ptr %b, ptr %cond) #0 {
15; CHECK-LABEL: @predication_in_loop
16; CHECK:  sdiv <vscale x 4 x i32>
17;
18entry:
19  br label %for.body
20
21for.cond.cleanup:                                 ; preds = %for.inc, %entry
22  ret void
23
24for.body:                                         ; preds = %entry, %for.inc
25  %i.09 = phi i64 [ %inc, %for.inc ], [ 0, %entry ]
26  %arrayidx = getelementptr inbounds i32, ptr %cond, i64 %i.09
27  %0 = load i32, ptr %arrayidx, align 4
28  %tobool.not = icmp eq i32 %0, 0
29  br i1 %tobool.not, label %for.inc, label %if.then
30
31if.then:                                          ; preds = %for.body
32  %arrayidx1 = getelementptr inbounds i32, ptr %b, i64 %i.09
33  %1 = load i32, ptr %arrayidx1, align 4
34  %arrayidx2 = getelementptr inbounds i32, ptr %a, i64 %i.09
35  %2 = load i32, ptr %arrayidx2, align 4
36  %div = sdiv i32 %2, %1
37  store i32 %div, ptr %arrayidx2, align 4
38  br label %for.inc
39
40for.inc:                                          ; preds = %for.body, %if.then
41  %inc = add nuw nsw i64 %i.09, 1
42  %exitcond.not = icmp eq i64 %inc, 1024
43  br i1 %exitcond.not, label %for.cond.cleanup, label %for.body, !llvm.loop !0
44}
45
46
47;
48; This test unpredicated_loop_predication_through_tailfolding corresponds
49; to the following function
50;   for (long long i = 0; i < 1024; i++) {
51;      a[i] /= b[i];
52;  }
53
54; Scalarization not possible in the main loop when there is no predication and
55; epilogue should not be able to allow scalarization
56; otherwise it could  be able to vectorize, but will not because
57; "Max legal vector width too small, scalable vectorization unfeasible.."
58
59define void @unpredicated_loop_predication_through_tailfolding(ptr %a, ptr %b) #0 {
60; CHECK-LABEL: @unpredicated_loop_predication_through_tailfolding
61; CHECK-NOT:  sdiv <vscale x 4 x i32>
62
63entry:
64  br label %loop
65
66loop:
67  %iv = phi i64 [ 0, %entry ], [ %iv.next, %loop ]
68  %arrayidx = getelementptr inbounds i32, ptr %a, i64 %iv
69  %0 = load i32, ptr %arrayidx, align 4
70  %arrayidx2 = getelementptr inbounds i32, ptr %b, i64 %iv
71  %1 = load i32, ptr %arrayidx2, align 4
72  %sdiv = sdiv i32 %1, %0
73  %2 = add nuw nsw i64 %iv, 8
74  %arrayidx5 = getelementptr inbounds i32, ptr %a, i64 %2
75  store i32 %sdiv, ptr %arrayidx5, align 4
76  %iv.next = add nuw nsw i64 %iv, 1
77  %exitcond.not = icmp eq i64 %iv.next, 1024
78  br i1 %exitcond.not, label %exit, label %loop, !llvm.loop !0
79
80exit:
81  ret void
82
83}
84
85attributes #0 = { "target-features"="+sve" }
86
87!0 = distinct !{!0, !1, !2, !3, !4}
88!1 = !{!"llvm.loop.vectorize.width", i32 4}
89!2 = !{!"llvm.loop.vectorize.scalable.enable", i1 true}
90!3 = !{!"llvm.loop.interleave.count", i32 1}
91!4 = !{!"llvm.loop.vectorize.enable", i1 true}
92