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,main2,pl \
15 ; RUN: -r=%t1.bc,foo, \
16 ; RUN: -r=%t1.bc,bar, \
17 ; RUN: -r=%t1.bc,baz, \
18 ; RUN: -r=%t1.bc,gBar, \
20 ; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT
21 ; RUN: llvm-dis %t3.1.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN
23 ; Now check that we won't internalize global (gBar) if it's externally referenced
24 ; RUN: llvm-lto2 run %t1.bc %t2.bc -save-temps \
25 ; RUN: -r=%t2.bc,foo,pl \
26 ; RUN: -r=%t2.bc,bar,pl \
27 ; RUN: -r=%t2.bc,baz,pl \
28 ; RUN: -r=%t2.bc,rand, \
29 ; RUN: -r=%t2.bc,gBar,plx \
30 ; RUN: -r=%t1.bc,main,plx \
31 ; RUN: -r=%t1.bc,main2,pl \
32 ; RUN: -r=%t1.bc,foo, \
33 ; RUN: -r=%t1.bc,bar, \
34 ; RUN: -r=%t1.bc,baz, \
35 ; RUN: -r=%t1.bc,gBar, \
37 ; RUN: llvm-dis %t4.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT2
39 ; Run again but with main2 exported instead of main to check that write only
40 ; variables are optimized out.
41 ; RUN: llvm-lto2 run %t1.bc %t2.bc -save-temps \
42 ; RUN: -r=%t2.bc,foo,pl \
43 ; RUN: -r=%t2.bc,bar,pl \
44 ; RUN: -r=%t2.bc,baz,pl \
45 ; RUN: -r=%t2.bc,rand, \
46 ; RUN: -r=%t2.bc,gBar,pl \
47 ; RUN: -r=%t1.bc,main,pl \
48 ; RUN: -r=%t1.bc,main2,plx \
49 ; RUN: -r=%t1.bc,foo, \
50 ; RUN: -r=%t1.bc,bar, \
51 ; RUN: -r=%t1.bc,baz, \
52 ; RUN: -r=%t1.bc,gBar, \
54 ; RUN: llvm-dis %t5.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT-WRITEONLY
55 ; RUN: llvm-dis %t5.1.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN2
56 ; Check that gFoo and gBar were eliminated from source module together
57 ; with corresponsing stores
58 ; RUN: llvm-dis %t5.2.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN2-SRC
60 ; IMPORT: @gBar = internal local_unnamed_addr global i32 2, align 4
61 ; IMPORT-NEXT: @gFoo.llvm.0 = internal unnamed_addr global i32 1, align 4
62 ; IMPORT: !DICompileUnit({{.*}})
64 ; Write only variables are imported with a zero initializer.
65 ; IMPORT-WRITEONLY: @gBar = internal local_unnamed_addr global i32 0
66 ; IMPORT-WRITEONLY: @gFoo.llvm.0 = internal unnamed_addr global i32 0
68 ; CODEGEN: i32 @main()
69 ; CODEGEN-NEXT: ret i32 3
71 ; IMPORT2: @gBar = available_externally local_unnamed_addr global i32 2, align 4
73 ; CODEGEN2: i32 @main2
74 ; CODEGEN2-NEXT: %1 = tail call i32 @rand()
75 ; CODEGEN2-NEXT: %2 = tail call i32 @rand()
76 ; CODEGEN2-NEXT: ret i32 0
78 ; CODEGEN2-SRC: void @baz()
79 ; CODEGEN2-SRC-NEXT: %1 = tail call i32 @rand()
80 ; CODEGEN2-SRC-NEXT: %2 = tail call i32 @rand()
81 ; CODEGEN2-SRC-NEXT: ret void
83 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
84 target triple = "x86_64-pc-linux-gnu"
86 ; We should be able to link external definition of gBar to its declaration
87 @gBar = external global i32
89 define i32 @main() local_unnamed_addr {
90 %call = tail call i32 @foo()
91 %call1 = tail call i32 @bar()
92 %add = add nsw i32 %call1, %call
96 define i32 @main2() local_unnamed_addr {
101 declare i32 @foo(...) local_unnamed_addr
103 declare i32 @bar(...) local_unnamed_addr
105 declare void @baz() local_unnamed_addr