1; Check constant propagation in thinlto combined summary. This allows us to do 2 things:
2;  1. Internalize global definition which is not used externally if all accesses to it are read-only
3;  2. Make a local copy of internal definition if all accesses to it are readonly. This allows constant
4;     folding it during optimziation phase.
5; RUN: opt -module-summary %s -o %t1.bc
6; RUN: opt -module-summary %p/Inputs/index-const-prop.ll -o %t2.bc
7; RUN: llvm-lto2 run %t1.bc %t2.bc -save-temps \
8; RUN:  -r=%t2.bc,foo,pl \
9; RUN:  -r=%t2.bc,bar,pl \
10; RUN:  -r=%t2.bc,baz,pl \
11; RUN:  -r=%t2.bc,rand, \
12; RUN:  -r=%t2.bc,gBar,pl \
13; RUN:  -r=%t1.bc,main,plx \
14; RUN:  -r=%t1.bc,foo, \
15; RUN:  -r=%t1.bc,bar, \
16; RUN:  -r=%t1.bc,gBar, \
17; RUN:  -o %t3
18; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT
19; RUN: llvm-dis %t3.1.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN
20
21; Now check that we won't internalize global (gBar) if it's externally referenced
22; RUN: llvm-lto2 run %t1.bc %t2.bc -save-temps \
23; RUN:  -r=%t2.bc,foo,pl \
24; RUN:  -r=%t2.bc,bar,pl \
25; RUN:  -r=%t2.bc,baz,pl \
26; RUN:  -r=%t2.bc,rand, \
27; RUN:  -r=%t2.bc,gBar,plx \
28; RUN:  -r=%t1.bc,main,plx \
29; RUN:  -r=%t1.bc,foo, \
30; RUN:  -r=%t1.bc,bar, \
31; RUN:  -r=%t1.bc,gBar, \
32; RUN:  -o %t3
33; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT2
34
35; IMPORT:       @gFoo.llvm.0 = internal unnamed_addr global i32 1, align 4
36; IMPORT-NEXT:  @gBar = internal local_unnamed_addr global i32 2, align 4
37; IMPORT:       !DICompileUnit({{.*}})
38
39; CODEGEN:        i32 @main()
40; CODEGEN-NEXT:     ret i32 3
41
42; IMPORT2: @gBar = available_externally dso_local local_unnamed_addr global i32 2, align 4
43
44target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
45target triple = "x86_64-pc-linux-gnu"
46
47; We should be able to link external definition of gBar to its declaration
48@gBar = external global i32
49
50define i32 @main() local_unnamed_addr {
51  %call = tail call i32 bitcast (i32 (...)* @foo to i32 ()*)()
52  %call1 = tail call i32 bitcast (i32 (...)* @bar to i32 ()*)()
53  %add = add nsw i32 %call1, %call
54  ret i32 %add
55}
56
57declare i32 @foo(...) local_unnamed_addr
58
59declare i32 @bar(...) local_unnamed_addr
60