xref: /llvm-project/llvm/test/Transforms/LowerExpectIntrinsic/phi_or.ll (revision 294f3ce5dde916c358d8f672b4a1c706c0387154)
1; RUN: opt -passes=lower-expect  -S -o - < %s | FileCheck %s
2; RUN: opt -S -passes='function(lower-expect)' < %s | FileCheck %s
3;
4; if (__builtin_expect((x > goo() || y > hoo()), 1)) {
5;  ..
6; }
7; For the above case, only the second branch should be
8; annotated.
9; if (__builtin_expect((x > goo() || y > hoo()), 0)) {
10;  ..
11; }
12; For the above case, two branches should be annotated.
13; Function Attrs: noinline nounwind uwtable
14define void @foo(i32 %arg, i32 %arg1, i32 %arg2, i32 %arg3)  {
15; CHECK-LABEL: void @foo
16bb:
17  %tmp8 = call i32 @goo()
18  %tmp9 = icmp slt i32 %arg, %tmp8
19  br i1 %tmp9, label %bb14, label %bb10
20; CHECK: br i1 %tmp9
21; CHECK-NOT: br i1 %tmp9{{.*}}!prof
22
23bb10:                                             ; preds = %bb
24  %tmp12 = call i32  @hoo()
25  %tmp13 = icmp sgt i32 %arg1, %tmp12
26  br label %bb14
27
28bb14:                                             ; preds = %bb10, %bb
29  %tmp15 = phi i1 [ true, %bb ], [ %tmp13, %bb10 ]
30  %tmp16 = zext i1 %tmp15 to i32
31  %tmp17 = sext i32 %tmp16 to i64
32  %expect = call i64 @llvm.expect.i64(i64 %tmp17, i64 1)
33  %tmp18 = icmp ne i64 %expect, 0
34  br i1 %tmp18, label %bb19, label %bb21
35; CHECK: br i1 %tmp18{{.*}}!prof [[WEIGHT:![0-9]+]]
36
37bb19:                                             ; preds = %bb14
38  %tmp20 = call i32 @goo()
39  br label %bb23
40
41bb21:                                             ; preds = %bb14
42  %tmp22 = call i32  @hoo()
43  br label %bb23
44
45bb23:                                             ; preds = %bb21, %bb19
46  ret void
47}
48
49define void @foo2(i32 %arg, i32 %arg1, i32 %arg2, i32 %arg3)  {
50; CHECK-LABEL: void @foo2
51bb:
52  %tmp = alloca i32, align 4
53  %tmp4 = alloca i32, align 4
54  %tmp5 = alloca i32, align 4
55  %tmp6 = alloca i32, align 4
56  store i32 %arg, ptr %tmp, align 4
57  store i32 %arg1, ptr %tmp4, align 4
58  store i32 %arg2, ptr %tmp5, align 4
59  store i32 %arg3, ptr %tmp6, align 4
60  %tmp7 = load i32, ptr %tmp, align 4
61  %tmp8 = call i32  @goo()
62  %tmp9 = icmp slt i32 %tmp7, %tmp8
63  br i1 %tmp9, label %bb14, label %bb10
64; CHECK: br i1 %tmp9{{.*}}!prof [[WEIGHT2:![0-9]+]]
65
66bb10:                                             ; preds = %bb
67  %tmp11 = load i32, ptr %tmp5, align 4
68  %tmp12 = call i32 @hoo()
69  %tmp13 = icmp sgt i32 %tmp11, %tmp12
70  br label %bb14
71
72bb14:                                             ; preds = %bb10, %bb
73  %tmp15 = phi i1 [ true, %bb ], [ %tmp13, %bb10 ]
74  %tmp16 = zext i1 %tmp15 to i32
75  %tmp17 = sext i32 %tmp16 to i64
76  %expect = call i64 @llvm.expect.i64(i64 %tmp17, i64 0)
77  %tmp18 = icmp ne i64 %expect, 0
78  br i1 %tmp18, label %bb19, label %bb21
79; CHECK: br i1 %tmp18{{.*}}!prof [[WEIGHT2]]
80
81bb19:                                             ; preds = %bb14
82  %tmp20 = call i32 @goo()
83  br label %bb23
84
85bb21:                                             ; preds = %bb14
86  %tmp22 = call i32 @hoo()
87  br label %bb23
88
89bb23:                                             ; preds = %bb21, %bb19
90  ret void
91}
92
93declare i32 @goo()
94declare i32 @hoo()
95declare i64 @llvm.expect.i64(i64, i64)
96
97
98!llvm.ident = !{!0}
99
100
101!0 = !{!"clang version 5.0.0 (trunk 302965)"}
102; CHECK: [[WEIGHT]] = !{!"branch_weights", !"expected", i32 2000, i32 1}
103; CHECK: [[WEIGHT2]] = !{!"branch_weights", !"expected", i32 1, i32 2000}
104