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
4 target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
5 target triple = "aarch64-unknown-linux-gnu"
7 ; The test predication_in_loop corresponds
8 ; to the following function
9 ; for (long long i = 0; i < 1024; i++) {
14 define 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>
21 for.cond.cleanup: ; preds = %for.inc, %entry
24 for.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
31 if.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
40 for.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
48 ; This test unpredicated_loop_predication_through_tailfolding corresponds
49 ; to the following function
50 ; for (long long i = 0; i < 1024; i++) {
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.."
59 define 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>
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
85 attributes #0 = { "target-features"="+sve" }
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}