1 ; RUN: opt -passes=lower-expect -S -o - < %s | FileCheck %s
2 ; RUN: opt -S -passes='function(lower-expect)' < %s | FileCheck %s
4 define i32 @foo(i32 %arg) #0 {
5 ; CHECK-LABEL: @foo(i32{{.*}})
7 %tmp = sext i32 %arg to i64
8 %tmp1 = call i64 @llvm.expect.i64(i64 %tmp, i64 4)
9 %tmp2 = icmp ne i64 %tmp1, 0
10 br i1 %tmp2, label %bb3, label %bb5
11 ; CHECK: br i1 %tmp2{{.*}}!prof [[LIKELY:![0-9]+]]
14 %tmp4 = call i32 (...) @bar()
17 bb5: ; preds = %bb3, %bb
21 define i32 @foo2(i32 %arg) #0 {
24 %tmp = sext i32 %arg to i64
25 %tmp1 = call i64 @llvm.expect.i64(i64 %tmp, i64 4)
26 %tmp2 = icmp eq i64 %tmp1, 2
27 br i1 %tmp2, label %bb3, label %bb5
28 ; CHECK: br i1 %tmp2{{.*}}!prof [[UNLIKELY:![0-9]+]]
31 %tmp4 = call i32 (...) @bar()
34 bb5: ; preds = %bb3, %bb
38 define i32 @foo3(i32 %arg) #0 {
41 %tmp = sext i32 %arg to i64
42 %tmp1 = call i64 @llvm.expect.i64(i64 %tmp, i64 4)
43 %tmp2 = icmp eq i64 %tmp1, 4
44 br i1 %tmp2, label %bb3, label %bb5
45 ; CHECK: br i1 %tmp2{{.*}}!prof [[LIKELY]]
48 %tmp4 = call i32 (...) @bar()
51 bb5: ; preds = %bb3, %bb
55 define i32 @foo4(i32 %arg) #0 {
58 %tmp = sext i32 %arg to i64
59 %tmp1 = call i64 @llvm.expect.i64(i64 %tmp, i64 4)
60 %tmp2 = icmp ne i64 %tmp1, 2
61 br i1 %tmp2, label %bb3, label %bb5
62 ; CHECK: br i1 %tmp2{{.*}}!prof [[LIKELY]]
65 %tmp4 = call i32 (...) @bar()
68 bb5: ; preds = %bb3, %bb
72 define i32 @foo5(i32 %arg, i32 %arg1) #0 {
75 %tmp = sext i32 %arg1 to i64
76 %tmp2 = call i64 @llvm.expect.i64(i64 %tmp, i64 4)
77 %tmp3 = sext i32 %arg to i64
78 %tmp4 = icmp ne i64 %tmp2, %tmp3
79 br i1 %tmp4, label %bb5, label %bb7
83 %tmp6 = call i32 (...) @bar()
86 bb7: ; preds = %bb5, %bb
90 declare i64 @llvm.expect.i64(i64, i64) #1
92 declare i32 @bar(...) local_unnamed_addr #0
94 attributes #0 = { nounwind uwtable }
95 attributes #1 = { nounwind readnone }
97 !llvm.module.flags = !{!0}
100 !0 = !{i32 1, !"wchar_size", i32 4}
101 !1 = !{!"clang version 5.0.0 (trunk 304373)"}
102 ; CHECK: [[LIKELY]] = !{!"branch_weights", !"expected", i32 2000, i32 1}
103 ; CHECK: [[UNLIKELY]] = !{!"branch_weights", !"expected", i32 1, i32 2000}