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