1cee313d2SEric Christopher; Do setup work for all below tests: generate bitcode and combined index
2cee313d2SEric Christopher; RUN: opt -module-summary %s -o %t.bc
3cee313d2SEric Christopher; RUN: opt -module-summary %p/Inputs/thinlto_indirect_call_promotion.ll -o %t2.bc
4cee313d2SEric Christopher; RUN: llvm-lto -thinlto -o %t3 %t.bc %t2.bc
5cee313d2SEric Christopher
6*a9af1b9aSFangrui Song; RUN: opt -passes=function-import -summary-file %t3.thinlto.bc %t.bc -o %t4.bc -print-imports 2>&1 | FileCheck %s --check-prefix=IMPORTS
7cee313d2SEric Christopher; IMPORTS-DAG: Import a
8cee313d2SEric Christopher; IMPORTS-DAG: Import c
9cee313d2SEric Christopher
10b5d884a3SFangrui Song; RUN: opt %t4.bc -icp-lto -passes=pgo-icall-prom -S | FileCheck %s --check-prefix=ICALL-PROM
11b5d884a3SFangrui Song; RUN: opt %t4.bc -icp-lto -passes=pgo-icall-prom -S -pass-remarks=pgo-icall-prom 2>&1 | FileCheck %s --check-prefix=PASS-REMARK
12cee313d2SEric Christopher; PASS-REMARK: Promote indirect call to a with count 1 out of 1
13cee313d2SEric Christopher; PASS-REMARK: Promote indirect call to c.llvm.0 with count 1 out of 1
14cee313d2SEric Christopher
157b1d7937SAmy Huangtarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
16cee313d2SEric Christophertarget triple = "x86_64-unknown-linux-gnu"
17cee313d2SEric Christopher
1841d5033eSNikita Popov@foo = external local_unnamed_addr global ptr, align 8
1941d5033eSNikita Popov@bar = external local_unnamed_addr global ptr, align 8
20cee313d2SEric Christopher
21cee313d2SEric Christopherdefine i32 @main() local_unnamed_addr {
22cee313d2SEric Christopherentry:
2341d5033eSNikita Popov  %0 = load ptr, ptr @foo, align 8
24cee313d2SEric Christopher; ICALL-PROM:   br i1 %{{[0-9]+}}, label %if.true.direct_targ, label %if.false.orig_indirect, !prof [[BRANCH_WEIGHT:![0-9]+]]
25cee313d2SEric Christopher  tail call void %0(), !prof !1
2641d5033eSNikita Popov  %1 = load ptr, ptr @bar, align 8
27cee313d2SEric Christopher; ICALL-PROM:   br i1 %{{[0-9]+}}, label %if.true.direct_targ1, label %if.false.orig_indirect2, !prof [[BRANCH_WEIGHT:![0-9]+]]
28cee313d2SEric Christopher  tail call void %1(), !prof !2
29cee313d2SEric Christopher  ret i32 0
30cee313d2SEric Christopher}
31cee313d2SEric Christopher
32cee313d2SEric Christopher!1 = !{!"VP", i32 0, i64 1, i64 -6289574019528802036, i64 1}
33cee313d2SEric Christopher!2 = !{!"VP", i32 0, i64 1, i64 591260329866125152, i64 1}
34cee313d2SEric Christopher
35cee313d2SEric Christopher; Should not have a VP annotation on new indirect call (check before and after
36cee313d2SEric Christopher; branch_weights annotation).
37cee313d2SEric Christopher; ICALL-PROM-NOT: !"VP"
385c31b8b9SArthur Eubanks; ICALL-PROM: [[BRANCH_WEIGHT]] = !{!"branch_weights", i32 1, i32 0}
39cee313d2SEric Christopher; ICALL-PROM-NOT: !"VP"
40