xref: /llvm-project/llvm/test/ThinLTO/X86/writeonly2.ll (revision cedfa38fc46d7531c44ea230b767d8286767f350)
13aef3528SEugene Leviant; Check that we optimize out writeonly variables and corresponding stores.
23aef3528SEugene Leviant; This test uses llvm-lto2
33aef3528SEugene Leviant
43aef3528SEugene Leviant; RUN: opt -module-summary %s -o %t1.bc
53aef3528SEugene Leviant; RUN: opt -module-summary %p/Inputs/index-const-prop.ll -o %t2.bc
63aef3528SEugene Leviant; RUN: llvm-lto2 run %t1.bc %t2.bc -save-temps \
73aef3528SEugene Leviant; RUN:  -r=%t2.bc,foo,pl \
83aef3528SEugene Leviant; RUN:  -r=%t2.bc,bar,pl \
93aef3528SEugene Leviant; RUN:  -r=%t2.bc,baz,pl \
103aef3528SEugene Leviant; RUN:  -r=%t2.bc,rand, \
113aef3528SEugene Leviant; RUN:  -r=%t2.bc,gBar,pl \
123aef3528SEugene Leviant; RUN:  -r=%t1.bc,main,plx \
133aef3528SEugene Leviant; RUN:  -r=%t1.bc,baz, \
143aef3528SEugene Leviant; RUN:  -r=%t1.bc,gBar, \
153aef3528SEugene Leviant; RUN:  -o %t3
163aef3528SEugene Leviant; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT
173aef3528SEugene Leviant; RUN: llvm-dis %t3.1.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN
183aef3528SEugene Leviant; Check that gFoo and gBar were eliminated from source module together
193aef3528SEugene Leviant; with corresponsing stores
203aef3528SEugene Leviant; RUN: llvm-dis %t3.2.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN-SRC
213aef3528SEugene Leviant
22*cedfa38fSJin Lin; IMPORT:       @gBar = internal local_unnamed_addr global i32 0, align 4
23*cedfa38fSJin Lin; IMPORT-NEXT:  @gFoo.llvm.0 = internal unnamed_addr global i32 0, align 4
243aef3528SEugene Leviant; IMPORT:       !DICompileUnit({{.*}})
253aef3528SEugene Leviant
263aef3528SEugene Leviant; CODEGEN-NOT:  gFoo
273aef3528SEugene Leviant; CODEGEN-NOT:  gBar
283aef3528SEugene Leviant; CODEGEN:      i32 @main
293aef3528SEugene Leviant; CODEGEN-NEXT:   %1 = tail call i32 @rand()
303aef3528SEugene Leviant; CODEGEN-NEXT:   %2 = tail call i32 @rand()
313aef3528SEugene Leviant; CODEGEN-NEXT:   ret i32 0
323aef3528SEugene Leviant
333aef3528SEugene Leviant; CODEGEN-SRC-NOT:   gFoo
343aef3528SEugene Leviant; CODEGEN-SRC-NOT:   gBar
353aef3528SEugene Leviant; CODEGEN-SRC:       void @baz()
363aef3528SEugene Leviant; CODEGEN-SRC-NEXT:    %1 = tail call i32 @rand()
373aef3528SEugene Leviant; CODEGEN-SRC-NEXT:    %2 = tail call i32 @rand()
383aef3528SEugene Leviant; CODEGEN-SRC-NEXT:    ret void
393aef3528SEugene Leviant
407b1d7937SAmy Huangtarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
413aef3528SEugene Levianttarget triple = "x86_64-pc-linux-gnu"
423aef3528SEugene Leviant
433aef3528SEugene Leviant; We should be able to link external definition of gBar to its declaration
443aef3528SEugene Leviant@gBar = external global i32
453aef3528SEugene Leviant
463aef3528SEugene Leviantdefine i32 @main() local_unnamed_addr {
473aef3528SEugene Leviant  tail call void @baz()
483aef3528SEugene Leviant  ret i32 0
493aef3528SEugene Leviant}
503aef3528SEugene Leviantdeclare void @baz() local_unnamed_addr
51