85 lines · plain
1; The raw profiles (and reduced IR if needed) could be re-generated (e.g., when2; there is a profile version bump) from script3; Inputs/update_thinlto_indirect_call_promotion_inputs.sh4;5; The script generates raw profiles. This regression test will convert it to6; indexed profiles. This way the test exercises code path where a profiled7; callee address in raw profiles is converted to function hash in index profiles.8 9; The raw profiles storesd compressed function names, so profile reader should10; be built with zlib support to decompress them.11; REQUIRES: zlib12 13; RUN: rm -rf %t && split-file %s %t && cd %t14 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 ICP18; transformation won't happen at test setup time.19; RUN: llvm-profdata merge %p/Inputs/thinlto_indirect_call_promotion.profraw -o icp.profdata20; RUN: opt -passes=pgo-instr-use -pgo-test-profile-file=icp.profdata -module-summary main.ll -o main.bc21; RUN: opt -passes=pgo-instr-use -pgo-test-profile-file=icp.profdata -module-summary lib.ll -o lib.bc22; RUN: llvm-lto -thinlto -o summary main.bc lib.bc23 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=PGOName26; 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 does29; not change with the directory), so match the full name here.30; PGOName: ![[#MD]] = !{!"lib.cc;_ZL7callee0v"}31 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=IMPORTS34; IMPORTS-DAG: Import _Z7callee1v35; IMPORTS-DAG: Import _ZL7callee0v.llvm.[[#]]36; IMPORTS-DAG: Import _Z11global_funcv37 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-REMARK42 43; PASS-REMARK: Promote indirect call to _ZL7callee0v.llvm.[[#]] with count 1 out of 144; PASS-REMARK: Promote indirect call to _Z7callee1v with count 1 out of 145 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]]48 49; ICALL-PROM: ![[#BRANCH_WEIGHT1]] = !{!"branch_weights", i32 1, i32 0}50 51;--- main.ll52target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"53target triple = "x86_64-unknown-linux-gnu"54 55define i32 @main() {56 call void @_Z11global_funcv()57 ret i32 058}59 60declare void @_Z11global_funcv()61 62;--- lib.ll63source_filename = "lib.cc"64target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"65target triple = "x86_64-unknown-linux-gnu"66 67@calleeAddrs = global [2 x ptr] [ptr @_ZL7callee0v, ptr @_Z7callee1v]68 69define void @_Z7callee1v() {70 ret void71}72 73define internal void @_ZL7callee0v() {74 ret void75}76 77define void @_Z11global_funcv() {78entry:79 %0 = load ptr, ptr @calleeAddrs80 call void %0()81 %1 = load ptr, ptr getelementptr inbounds ([2 x ptr], ptr @calleeAddrs, i64 0, i64 1)82 call void %1()83 ret void84}85