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