1 ; RUN: opt -passes=lower-expect -S -o - < %s | FileCheck %s
2 ; RUN: opt -S -passes='function(lower-expect)' < %s | FileCheck %s
4 ; if (__builtin_expect((x > goo() || y > hoo()), 1)) {
7 ; For the above case, only the second branch should be
9 ; if (__builtin_expect((x > goo() || y > hoo()), 0)) {
12 ; For the above case, two branches should be annotated.
13 ; Function Attrs: noinline nounwind uwtable
14 define void @foo(i32 %arg, i32 %arg1, i32 %arg2, i32 %arg3) {
15 ; CHECK-LABEL: void @foo
17 %tmp8 = call i32 @goo()
18 %tmp9 = icmp slt i32 %arg, %tmp8
19 br i1 %tmp9, label %bb14, label %bb10
21 ; CHECK-NOT: br i1 %tmp9{{.*}}!prof
24 %tmp12 = call i32 @hoo()
25 %tmp13 = icmp sgt i32 %arg1, %tmp12
28 bb14: ; 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]+]]
38 %tmp20 = call i32 @goo()
42 %tmp22 = call i32 @hoo()
45 bb23: ; preds = %bb21, %bb19
49 define void @foo2(i32 %arg, i32 %arg1, i32 %arg2, i32 %arg3) {
50 ; CHECK-LABEL: void @foo2
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]+]]
67 %tmp11 = load i32, ptr %tmp5, align 4
68 %tmp12 = call i32 @hoo()
69 %tmp13 = icmp sgt i32 %tmp11, %tmp12
72 bb14: ; 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]]
82 %tmp20 = call i32 @goo()
86 %tmp22 = call i32 @hoo()
89 bb23: ; preds = %bb21, %bb19
95 declare i64 @llvm.expect.i64(i64, i64)
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}