1; REQUIRES: asserts
2; RUN: opt < %s -force-vector-width=2 -enable-cond-stores-vec -loop-vectorize -debug-only=loop-vectorize -disable-output 2>&1 | FileCheck %s
3
4target datalayout = "e-m:e-i64:64-i128:128-n32:64-S128"
5target triple = "aarch64--linux-gnu"
6
7; Check predication-related cost calculations, including scalarization overhead
8; and block probability scaling. Note that the functionality being tested is
9; not specific to AArch64. We specify a target to get actual values for the
10; instruction costs.
11
12; CHECK-LABEL: predicated_udiv
13;
14; This test checks that we correctly compute the cost of the predicated udiv
15; instruction. If we assume the block probability is 50%, we compute the cost
16; as:
17;
18; Cost for vector lane zero:
19;   (udiv(1) + 2 * extractelement(0) + insertelement(0)) / 2 = 0
20; Cost for vector lane one:
21;   (udiv(1) + 2 * extractelement(3) + insertelement(3)) / 2 = 5
22;
23; CHECK: Found an estimated cost of 5 for VF 2 For instruction: %tmp4 = udiv i32 %tmp2, %tmp3
24; CHECK: Scalarizing and predicating: %tmp4 = udiv i32 %tmp2, %tmp3
25;
26define i32 @predicated_udiv(i32* %a, i32* %b, i1 %c, i64 %n) {
27entry:
28  br label %for.body
29
30for.body:
31  %i = phi i64 [ 0, %entry ], [ %i.next, %for.inc ]
32  %r = phi i32 [ 0, %entry ], [ %tmp6, %for.inc ]
33  %tmp0 = getelementptr inbounds i32, i32* %a, i64 %i
34  %tmp1 = getelementptr inbounds i32, i32* %b, i64 %i
35  %tmp2 = load i32, i32* %tmp0, align 4
36  %tmp3 = load i32, i32* %tmp1, align 4
37  br i1 %c, label %if.then, label %for.inc
38
39if.then:
40  %tmp4 = udiv i32 %tmp2, %tmp3
41  br label %for.inc
42
43for.inc:
44  %tmp5 = phi i32 [ %tmp3, %for.body ], [ %tmp4, %if.then]
45  %tmp6 = add i32 %r, %tmp5
46  %i.next = add nuw nsw i64 %i, 1
47  %cond = icmp slt i64 %i.next, %n
48  br i1 %cond, label %for.body, label %for.end
49
50for.end:
51  %tmp7 = phi i32 [ %tmp6, %for.inc ]
52  ret i32 %tmp7
53}
54
55; CHECK-LABEL: predicated_store
56;
57; This test checks that we correctly compute the cost of the predicated store
58; instruction. If we assume the block probability is 50%, we compute the cost
59; as:
60;
61; Cost for vector lane zero:
62;   (store(2) + 2 * extractelement(0)) / 2 = 1
63; Cost for vector lane one:
64;   (store(2) + 2 * extractelement(3)) / 2 = 4
65;
66; CHECK: Found an estimated cost of 5 for VF 2 For instruction: store i32 %tmp2, i32* %tmp0, align 4
67; CHECK: Scalarizing and predicating: store i32 %tmp2, i32* %tmp0, align 4
68;
69define void @predicated_store(i32* %a, i1 %c, i32 %x, i64 %n) {
70entry:
71  br label %for.body
72
73for.body:
74  %i = phi i64 [ 0, %entry ], [ %i.next, %for.inc ]
75  %tmp0 = getelementptr inbounds i32, i32* %a, i64 %i
76  %tmp1 = load i32, i32* %tmp0, align 4
77  br i1 %c, label %if.then, label %for.inc
78
79if.then:
80  %tmp2 = add nsw i32 %tmp1, %x
81  store i32 %tmp2, i32* %tmp0, align 4
82  br label %for.inc
83
84for.inc:
85  %i.next = add nuw nsw i64 %i, 1
86  %cond = icmp slt i64 %i.next, %n
87  br i1 %cond, label %for.body, label %for.end
88
89for.end:
90  ret void
91}
92