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
6; -stats requires asserts
7; REQUIRES: asserts
8
9; RUN: opt -module-summary %s -o %t1.bc
10; RUN: opt -module-summary %p/Inputs/index-const-prop.ll -o %t2.bc
11; RUN: llvm-lto -thinlto-action=thinlink -o %t3.index.bc %t1.bc %t2.bc
12; RUN: llvm-lto -thinlto-action=import -exported-symbol=main  %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported.bc -stats 2>&1 | FileCheck %s --check-prefix=STATS
13; RUN: llvm-dis %t1.imported.bc -o - | FileCheck %s --check-prefix=IMPORT
14; RUN: llvm-lto -thinlto-action=optimize %t1.imported.bc -o - | llvm-dis - -o - | FileCheck %s --check-prefix=OPTIMIZE
15
16; STATS: 2 module-summary-index - Number of live global variables marked read only
17
18; Check that we don't internalize gBar when it is exported
19; RUN: llvm-lto -thinlto-action=import -exported-symbol main -exported-symbol gBar  %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported2.bc
20; RUN: llvm-dis %t1.imported2.bc -o - | FileCheck %s --check-prefix=IMPORT2
21
22; IMPORT: @gFoo.llvm.0 = internal unnamed_addr global i32 1, align 4, !dbg !0
23; IMPORT-NEXT: @gBar = internal local_unnamed_addr global i32 2, align 4, !dbg !5
24; IMPORT: !DICompileUnit({{.*}})
25
26; OPTIMIZE:        define i32 @main
27; OPTIMIZE-NEXT:     ret i32 3
28
29; IMPORT2: @gBar = available_externally local_unnamed_addr global i32 2, align 4, !dbg !5
30
31target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
32target triple = "x86_64-pc-linux-gnu"
33
34@gBar = external global i32
35
36; Should not be counted in the stats of live read only variables since it is
37; dead and will be dropped anyway.
38@gDead = internal unnamed_addr global i32 1, align 4
39
40define i32 @main() local_unnamed_addr {
41  %call = tail call i32 bitcast (i32 (...)* @foo to i32 ()*)()
42  %call1 = tail call i32 bitcast (i32 (...)* @bar to i32 ()*)()
43  %add = add nsw i32 %call1, %call
44  ret i32 %add
45}
46
47declare i32 @foo(...) local_unnamed_addr
48
49declare i32 @bar(...) local_unnamed_addr
50