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: llvm-lto2 run %t1.bc %t2.bc -save-temps \
40 ; RUN: -r=%t2.bc,foo,pl \
41 ; RUN: -r=%t2.bc,bar,pl \
42 ; RUN: -r=%t2.bc,baz,pl \
43 ; RUN: -r=%t2.bc,rand, \
44 ; RUN: -r=%t2.bc,gBar,pl \
45 ; RUN: -r=%t1.bc,main,pl \
46 ; RUN: -r=%t1.bc,main2,plx \
47 ; RUN: -r=%t1.bc,foo, \
48 ; RUN: -r=%t1.bc,bar, \
49 ; RUN: -r=%t1.bc,baz, \
50 ; RUN: -r=%t1.bc,gBar, \
52 ; RUN: llvm-dis %t5.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT
53 ; RUN: llvm-dis %t5.1.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN2
54 ; Check that gFoo and gBar were eliminated from source module together
55 ; with corresponsing stores
56 ; RUN: llvm-dis %t5.2.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN2-SRC
58 ; IMPORT: @gFoo.llvm.0 = internal unnamed_addr global i32 1, align 4
59 ; IMPORT-NEXT: @gBar = internal local_unnamed_addr global i32 2, align 4
60 ; IMPORT: !DICompileUnit({{.*}})
62 ; CODEGEN: i32 @main()
63 ; CODEGEN-NEXT: ret i32 3
65 ; IMPORT2: @gBar = available_externally dso_local local_unnamed_addr global i32 2, align 4
67 ; CODEGEN2: i32 @main2
68 ; CODEGEN2-NEXT: %1 = tail call i32 @rand()
69 ; CODEGEN2-NEXT: %2 = tail call i32 @rand()
70 ; CODEGEN2-NEXT: ret i32 0
72 ; CODEGEN2-SRC: void @baz()
73 ; CODEGEN2-SRC-NEXT: %1 = tail call i32 @rand()
74 ; CODEGEN2-SRC-NEXT: %2 = tail call i32 @rand()
75 ; CODEGEN2-SRC-NEXT: ret void
77 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
78 target triple = "x86_64-pc-linux-gnu"
80 ; We should be able to link external definition of gBar to its declaration
81 @gBar = external global i32
83 define i32 @main() local_unnamed_addr {
84 %call = tail call i32 bitcast (i32 (...)* @foo to i32 ()*)()
85 %call1 = tail call i32 bitcast (i32 (...)* @bar to i32 ()*)()
86 %add = add nsw i32 %call1, %call
90 define i32 @main2() local_unnamed_addr {
95 declare i32 @foo(...) local_unnamed_addr
97 declare i32 @bar(...) local_unnamed_addr
99 declare void @baz() local_unnamed_addr