1 ; The raw profiles (and reduced IR if needed) could be re-generated (e.g., when
2 ; there is a profile version bump) from script
3 ; Inputs/update_thinlto_indirect_call_promotion_inputs.sh
5 ; The script generates raw profiles. This regression test will convert it to
6 ; indexed profiles. This way the test exercises code path where a profiled
7 ; callee address in raw profiles is converted to function hash in index profiles.
9 ; The raw profiles storesd compressed function names, so profile reader should
10 ; be built with zlib support to decompress them.
13 ; RUN: rm -rf %t && split-file %s %t && cd %t
15 ; Do setup work for all below tests: convert raw profiles to indexed profiles,
16 ; run profile-use pass, generate bitcode and combined ThinLTO index.
17 ; Note `pgo-instr-use` pass runs without `pgo-icall-prom` pass. As a result ICP
18 ; transformation won't happen at test setup time.
19 ; RUN: llvm-profdata merge %p/Inputs/thinlto_indirect_call_promotion.profraw -o icp.profdata
20 ; RUN: opt -passes=pgo-instr-use -pgo-test-profile-file=icp.profdata -module-summary main.ll -o main.bc
21 ; RUN: opt -passes=pgo-instr-use -pgo-test-profile-file=icp.profdata -module-summary lib.ll -o lib.bc
22 ; RUN: llvm-lto -thinlto -o summary main.bc lib.bc
24 ; Test that callee with local linkage has `PGOFuncName` metadata while callee with external doesn't have it.
25 ; RUN: llvm-dis lib.bc -o - | FileCheck %s --check-prefix=PGOName
26 ; PGOName-DAG: define void @_Z7callee1v() {{.*}} !prof ![[#]] {
27 ; PGOName-DAG: define internal void @_ZL7callee0v() {{.*}} !prof ![[#]] !PGOFuncName ![[#MD:]] {
28 ; The source filename of `lib.ll` is specified as "lib.cc" (i.e., the name does
29 ; not change with the directory), so match the full name here.
30 ; PGOName: ![[#MD]] = !{!"lib.cc;_ZL7callee0v"}
32 ; Tests that both external and internal callees are correctly imported.
33 ; RUN: opt -passes=function-import -summary-file summary.thinlto.bc main.bc -o main.import.bc -print-imports 2>&1 | FileCheck %s --check-prefix=IMPORTS
34 ; IMPORTS-DAG: Import _Z7callee1v
35 ; IMPORTS-DAG: Import _ZL7callee0v.llvm.[[#]]
36 ; IMPORTS-DAG: Import _Z11global_funcv
38 ; Tests that ICP transformations happen.
39 ; Both candidates are ICP'ed, check there is no `!VP` in the IR.
40 ; RUN: opt main.import.bc -icp-lto -passes=pgo-icall-prom -S | FileCheck %s --check-prefix=ICALL-PROM --implicit-check-not="!VP"
41 ; RUN: opt main.import.bc -icp-lto -passes=pgo-icall-prom -S -pass-remarks=pgo-icall-prom 2>&1 | FileCheck %s --check-prefix=PASS-REMARK
43 ; PASS-REMARK: Promote indirect call to _ZL7callee0v.llvm.[[#]] with count 1 out of 1
44 ; PASS-REMARK: Promote indirect call to _Z7callee1v with count 1 out of 1
46 ; ICALL-PROM: br i1 %[[#]], label %if.true.direct_targ, label %if.false.orig_indirect, !prof ![[#BRANCH_WEIGHT1:]]
47 ; ICALL-PROM: br i1 %[[#]], label %if.true.direct_targ1, label %if.false.orig_indirect2, !prof ![[#BRANCH_WEIGHT1]]
49 ; ICALL-PROM: ![[#BRANCH_WEIGHT1]] = !{!"branch_weights", i32 1, i32 0}
52 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
53 target triple = "x86_64-unknown-linux-gnu"
56 call void @_Z11global_funcv()
60 declare void @_Z11global_funcv()
63 source_filename = "lib.cc"
64 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
65 target triple = "x86_64-unknown-linux-gnu"
67 @calleeAddrs = global [2 x ptr] [ptr @_ZL7callee0v, ptr @_Z7callee1v]
69 define void @_Z7callee1v() {
73 define internal void @_ZL7callee0v() {
77 define void @_Z11global_funcv() {
79 %0 = load ptr, ptr @calleeAddrs
81 %1 = load ptr, ptr getelementptr inbounds ([2 x ptr], ptr @calleeAddrs, i64 0, i64 1)