1; RUN: opt < %s -pgo-icall-prom -S -icp-total-percent-threshold=50 | FileCheck %s --check-prefix=ICALL-PROM
2; RUN: opt < %s -pgo-icall-prom -S -icp-samplepgo -icp-total-percent-threshold=50 | FileCheck %s --check-prefix=ICALL-PROM
3; RUN: opt < %s -passes=pgo-icall-prom -S -icp-total-percent-threshold=50 | FileCheck %s --check-prefix=ICALL-PROM
4; RUN: opt < %s -pgo-icall-prom -S -pass-remarks=pgo-icall-prom -icp-remaining-percent-threshold=0 -icp-total-percent-threshold=0 -icp-max-prom=4 2>&1 | FileCheck %s --check-prefix=PASS-REMARK
5; RUN: opt < %s -passes=pgo-icall-prom -S -pass-remarks=pgo-icall-prom -icp-remaining-percent-threshold=0 -icp-total-percent-threshold=0 -icp-max-prom=4 2>&1 | FileCheck %s --check-prefix=PASS-REMARK
6; RUN: opt < %s -passes=pgo-icall-prom -S -pass-remarks=pgo-icall-prom -icp-remaining-percent-threshold=0 -icp-total-percent-threshold=20 -icp-max-prom=4 2>&1 | FileCheck %s --check-prefix=PASS2-REMARK
7
8; PASS-REMARK: remark: <unknown>:0:0: Promote indirect call to func4 with count 1030 out of 1600
9; PASS-REMARK: remark: <unknown>:0:0: Promote indirect call to func2 with count 410 out of 570
10; PASS-REMARK: remark: <unknown>:0:0: Promote indirect call to func3 with count 150 out of 160
11; PASS-REMARK: remark: <unknown>:0:0: Promote indirect call to func1 with count 10 out of 10
12
13; PASS2-REMARK: remark: <unknown>:0:0: Promote indirect call to func4 with count 1030 out of 1600
14; PASS2-REMARK: remark: <unknown>:0:0: Promote indirect call to func2 with count 410 out of 570
15; PASS2-REMARK-NOT: remark: <unknown>:0:0: Promote indirect call to func3
16; PASS2-REMARK-NOT: remark: <unknown>:0:0: Promote indirect call to func1
17
18target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
19target triple = "x86_64-unknown-linux-gnu"
20
21@foo = common global i32 ()* null, align 8
22
23define i32 @func1() {
24entry:
25  ret i32 0
26}
27
28define i32 @func2() {
29entry:
30  ret i32 1
31}
32
33define i32 @func3() {
34entry:
35  ret i32 2
36}
37
38define i32 @func4() {
39entry:
40  ret i32 3
41}
42
43define i32 @bar() {
44entry:
45  %tmp = load i32 ()*, i32 ()** @foo, align 8
46; ICALL-PROM:   [[CMP:%[0-9]+]] = icmp eq i32 ()* %tmp, @func4
47; ICALL-PROM:   br i1 [[CMP]], label %if.true.direct_targ, label %if.false.orig_indirect, !prof [[BRANCH_WEIGHT:![0-9]+]]
48; ICALL-PROM: if.true.direct_targ:
49; ICALL-PROM:   [[DIRCALL_RET:%[0-9]+]] = call i32 @func4()
50; ICALL-PROM-SAMPLEPGO: call i32 @func4(), !prof [[CALL_METADATA:![0-9]+]]
51; ICALL-PROM:   br label %if.end.icp
52  %call = call i32 %tmp(), !prof !1
53; ICALL-PROM: if.false.orig_indirect:
54; ICALL-PROM:   %call = call i32 %tmp(), !prof [[NEW_VP_METADATA:![0-9]+]]
55  ret i32 %call
56; ICALL-PROM: if.end.icp:
57; ICALL-PROM:   [[PHI_RET:%[0-9]+]] = phi i32 [ %call, %if.false.orig_indirect ], [ [[DIRCALL_RET]], %if.true.direct_targ ]
58; ICALL-PROM:   ret i32 [[PHI_RET]]
59}
60
61!1 = !{!"VP", i32 0, i64 1600, i64 7651369219802541373, i64 1030, i64 -4377547752858689819, i64 410, i64 -6929281286627296573, i64 150, i64 -2545542355363006406, i64 10}
62
63; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1030, i32 570}
64; ICALL-PROM: [[NEW_VP_METADATA]] = !{!"VP", i32 0, i64 570, i64 -4377547752858689819, i64 410}
65; ICALL-PROM-SAMPLEPGO: [[CALL_METADATA]] = !{!"branch_weights", i32 1030}
66