xref: /llvm-project/llvm/test/Transforms/FunctionImport/funcimport_resolved.ll (revision 7f7dac712694ed661b2e774573b9ee1f99208882)
1cee313d2SEric Christopher; Test to ensure that we always select the same copy of a linkonce function
2cee313d2SEric Christopher; when it is encountered with different thresholds. When we encounter the
3cee313d2SEric Christopher; copy in funcimport_resolved1.ll with a higher threshold via the direct call
4cee313d2SEric Christopher; from main(), it will be selected for importing. When we encounter it with a
5cee313d2SEric Christopher; lower threshold by reaching it from the deeper call chain via foo(), it
6cee313d2SEric Christopher; won't be selected for importing. We don't want to select both the copy from
7cee313d2SEric Christopher; funcimport_resolved1.ll and the smaller one from funcimport_resolved2.ll,
8cee313d2SEric Christopher; leaving it up to the backend to figure out which one to actually import.
9cee313d2SEric Christopher; The linkonce_odr may have different instruction counts in practice due to
10cee313d2SEric Christopher; different inlines in the compile step.
11cee313d2SEric Christopher
12cee313d2SEric Christopher; Require asserts so we can use -debug-only
13cee313d2SEric Christopher; REQUIRES: asserts
14cee313d2SEric Christopher
15cee313d2SEric Christopher; REQUIRES: x86-registered-target
16cee313d2SEric Christopher
17cee313d2SEric Christopher; RUN: opt -module-summary %s -o %t.bc
18cee313d2SEric Christopher; RUN: opt -module-summary %p/Inputs/funcimport_resolved1.ll -o %t2.bc
19cee313d2SEric Christopher; RUN: opt -module-summary %p/Inputs/funcimport_resolved2.ll -o %t3.bc
20cee313d2SEric Christopher
21*7f7dac71SZarko Todorovski; First verify that all callees are imported with the default instruction limit
22cee313d2SEric Christopher; RUN: llvm-lto2 run %t.bc %t2.bc %t3.bc -o %t4 -r=%t.bc,_main,pl -r=%t.bc,_linkonceodrfunc,l -r=%t.bc,_foo,l -r=%t2.bc,_foo,pl -r=%t2.bc,_linkonceodrfunc,pl -r=%t2.bc,_linkonceodrfunc2,pl -r=%t3.bc,_linkonceodrfunc,l -thinlto-threads=1 -debug-only=function-import 2>&1 | FileCheck %s --check-prefix=INSTLIMDEFAULT
23cee313d2SEric Christopher; INSTLIMDEFAULT: Is importing function {{.*}} foo from {{.*}}funcimport_resolved1.ll
24cee313d2SEric Christopher; INSTLIMDEFAULT: Is importing function {{.*}} linkonceodrfunc from {{.*}}funcimport_resolved1.ll
25cee313d2SEric Christopher; INSTLIMDEFAULT: Is importing function {{.*}} linkonceodrfunc2 from {{.*}}funcimport_resolved1.ll
26cee313d2SEric Christopher; INSTLIMDEFAULT: Is importing function {{.*}} f from {{.*}}funcimport_resolved1.ll
27cee313d2SEric Christopher; INSTLIMDEFAULT-NOT: Is importing function {{.*}} linkonceodrfunc from {{.*}}funcimport_resolved2.ll
28cee313d2SEric Christopher
29cee313d2SEric Christopher; Now run with the lower threshold that will only allow linkonceodrfunc to be
30cee313d2SEric Christopher; imported from funcimport_resolved1.ll when encountered via the direct call
31cee313d2SEric Christopher; from main(). Ensure we don't also select the copy in funcimport_resolved2.ll
32cee313d2SEric Christopher; when it is encountered via the deeper call chain.
33cee313d2SEric Christopher; RUN: llvm-lto2 run %t.bc %t2.bc %t3.bc -o %t4 -r=%t.bc,_main,pl -r=%t.bc,_linkonceodrfunc,l -r=%t.bc,_foo,l -r=%t2.bc,_foo,pl -r=%t2.bc,_linkonceodrfunc,pl -r=%t2.bc,_linkonceodrfunc2,pl -r=%t3.bc,_linkonceodrfunc,l -thinlto-threads=1 -debug-only=function-import -import-instr-limit=8 2>&1 | FileCheck %s --check-prefix=INSTLIM8
34cee313d2SEric Christopher; INSTLIM8: Is importing function {{.*}} foo from {{.*}}funcimport_resolved1.ll
35cee313d2SEric Christopher; INSTLIM8: Is importing function {{.*}} linkonceodrfunc from {{.*}}funcimport_resolved1.ll
36cee313d2SEric Christopher; INSTLIM8: Not importing function {{.*}} linkonceodrfunc2 from {{.*}}funcimport_resolved1.ll
37cee313d2SEric Christopher; INSTLIM8: Is importing function {{.*}} f from {{.*}}funcimport_resolved1.ll
38cee313d2SEric Christopher; INSTLIM8-NOT: Is importing function {{.*}} linkonceodrfunc from {{.*}}funcimport_resolved2.ll
39cee313d2SEric Christopher
407b1d7937SAmy Huangtarget datalayout = "e-m:o-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
41cee313d2SEric Christophertarget triple = "x86_64-apple-macosx10.11.0"
42cee313d2SEric Christopher
43cee313d2SEric Christopherdefine i32 @main() #0 {
44cee313d2SEric Christopherentry:
45cee313d2SEric Christopher  call void (...) @foo()
46cee313d2SEric Christopher  call void (...) @linkonceodrfunc()
47cee313d2SEric Christopher  ret i32 0
48cee313d2SEric Christopher}
49cee313d2SEric Christopher
50cee313d2SEric Christopherdeclare void @foo(...) #1
51cee313d2SEric Christopherdeclare void @linkonceodrfunc(...) #1
52