1 ; RUN: opt -lower-expect -S -o - < %s | FileCheck %s
2 ; RUN: opt -S -passes='function(lower-expect)' < %s | FileCheck %s
4 ; return __builtin_expect((a > b ? 1, goo(), 0);
6 ; Function Attrs: noinline nounwind uwtable
7 define i32 @foo(i32 %arg, i32 %arg1) {
8 ; CHECK-LABEL: i32 @foo
10 %tmp5 = icmp sgt i32 %arg, %arg1
11 br i1 %tmp5, label %bb9, label %bb7
12 ; CHECK: br i1 %tmp5{{.*}}!prof [[WEIGHT:![0-9]+]]
15 %tmp8 = call i32 @goo()
18 bb9: ; preds = %bb7, %bb9
19 %tmp10 = phi i32 [ 1, %bb ], [ %tmp8, %bb7 ]
20 %tmp11 = sext i32 %tmp10 to i64
21 %expect = call i64 @llvm.expect.i64(i64 %tmp11, i64 0)
22 %tmp12 = trunc i64 %expect to i32
26 define i32 @foo2(i32 %arg, i32 %arg1) {
28 %tmp5 = icmp sgt i32 %arg, %arg1
29 br i1 %tmp5, label %bb6, label %bb7
30 ; CHECK: br i1 %tmp5{{.*}}!prof [[WEIGHT:![0-9]+]]
36 %tmp8 = call i32 @goo()
39 bb9: ; preds = %bb7, %bb6
40 %tmp10 = phi i32 [ 1, %bb6 ], [ %tmp8, %bb7 ]
41 %tmp11 = sext i32 %tmp10 to i64
42 %expect = call i64 @llvm.expect.i64(i64 %tmp11, i64 0)
43 %tmp12 = trunc i64 %expect to i32
48 declare i64 @llvm.expect.i64(i64, i64)
54 !0 = !{!"clang version 5.0.0 (trunk 302965)"}
56 ; CHECK: [[WEIGHT]] = !{!"branch_weights", i32 1, i32 2000}