Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / test / ThinLTO / X86 / index-const-prop2.ll
blob96b7593dd4fe88b9d015bccd549d1bbc992664a5
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
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
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({{.*}})
39 ; CODEGEN:        i32 @main()
40 ; CODEGEN-NEXT:     ret i32 3
42 ; IMPORT2: @gBar = available_externally dso_local local_unnamed_addr global i32 2, align 4
44 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
45 target triple = "x86_64-pc-linux-gnu"
47 ; We should be able to link external definition of gBar to its declaration
48 @gBar = external global i32
50 define 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
57 declare i32 @foo(...) local_unnamed_addr
59 declare i32 @bar(...) local_unnamed_addr