1; Check that we optimize out writeonly variables and corresponding stores.
2; This test uses llvm-lto2
3
4; RUN: opt -module-summary %s -o %t1.bc
5; RUN: opt -module-summary %p/Inputs/index-const-prop.ll -o %t2.bc
6; RUN: llvm-lto2 run %t1.bc %t2.bc -save-temps \
7; RUN:  -r=%t2.bc,foo,pl \
8; RUN:  -r=%t2.bc,bar,pl \
9; RUN:  -r=%t2.bc,baz,pl \
10; RUN:  -r=%t2.bc,rand, \
11; RUN:  -r=%t2.bc,gBar,pl \
12; RUN:  -r=%t1.bc,main,plx \
13; RUN:  -r=%t1.bc,baz, \
14; RUN:  -r=%t1.bc,gBar, \
15; RUN:  -o %t3
16; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT
17; RUN: llvm-dis %t3.1.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN
18; Check that gFoo and gBar were eliminated from source module together
19; with corresponsing stores
20; RUN: llvm-dis %t3.2.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN-SRC
21
22; IMPORT:       @gFoo.llvm.0 = internal unnamed_addr global i32 0, align 4
23; IMPORT-NEXT:  @gBar = internal local_unnamed_addr global i32 0, align 4
24; IMPORT:       !DICompileUnit({{.*}})
25
26; CODEGEN-NOT:  gFoo
27; CODEGEN-NOT:  gBar
28; CODEGEN:      i32 @main
29; CODEGEN-NEXT:   %1 = tail call i32 @rand()
30; CODEGEN-NEXT:   %2 = tail call i32 @rand()
31; CODEGEN-NEXT:   ret i32 0
32
33; CODEGEN-SRC-NOT:   gFoo
34; CODEGEN-SRC-NOT:   gBar
35; CODEGEN-SRC:       void @baz()
36; CODEGEN-SRC-NEXT:    %1 = tail call i32 @rand()
37; CODEGEN-SRC-NEXT:    %2 = tail call i32 @rand()
38; CODEGEN-SRC-NEXT:    ret void
39
40target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
41target triple = "x86_64-pc-linux-gnu"
42
43; We should be able to link external definition of gBar to its declaration
44@gBar = external global i32
45
46define i32 @main() local_unnamed_addr {
47  tail call void @baz()
48  ret i32 0
49}
50declare void @baz() local_unnamed_addr
51