xref: /llvm-project/llvm/test/ThinLTO/X86/writeonly.ll (revision cedfa38fc46d7531c44ea230b767d8286767f350)
13aef3528SEugene Leviant; Checks that we optimize writeonly variables and corresponding stores using llvm-lto
23aef3528SEugene Leviant; -stats requires asserts
33aef3528SEugene Leviant; REQUIRES: asserts
43aef3528SEugene Leviant
53aef3528SEugene Leviant; RUN: opt -module-summary %s -o %t1.bc
63aef3528SEugene Leviant; RUN: opt -module-summary %p/Inputs/index-const-prop.ll -o %t2.bc
73aef3528SEugene Leviant; RUN: llvm-lto -thinlto-action=thinlink -o %t3.index.bc %t1.bc %t2.bc
83aef3528SEugene Leviant
93aef3528SEugene Leviant; Check that we optimize write-only variables
103aef3528SEugene Leviant; RUN: llvm-lto -thinlto-action=import -exported-symbol=main  %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported.bc -stats 2>&1 | FileCheck %s --check-prefix=STATS
113aef3528SEugene Leviant; RUN: llvm-dis %t1.imported.bc -o - | FileCheck %s --check-prefix=IMPORT
123aef3528SEugene Leviant; RUN: llvm-lto -thinlto-action=optimize %t1.imported.bc -o - | llvm-dis - -o - | FileCheck %s --check-prefix=OPTIMIZE
133aef3528SEugene Leviant
14*cedfa38fSJin Lin; IMPORT:      @gBar = internal local_unnamed_addr global i32 0, align 4, !dbg !0
15*cedfa38fSJin Lin; IMPORT-NEXT: @gFoo.llvm.0 = internal unnamed_addr global i32 0, align 4, !dbg !5
163aef3528SEugene Leviant; IMPORT: !DICompileUnit({{.*}})
173aef3528SEugene Leviant
183aef3528SEugene Leviant; STATS:  2 module-summary-index - Number of live global variables marked write only
193aef3528SEugene Leviant
203aef3528SEugene Leviant; Check that we've optimized out variables and corresponding stores
213aef3528SEugene Leviant; OPTIMIZE-NOT:  gFoo
223aef3528SEugene Leviant; OPTIMIZE-NOT:  gBar
233aef3528SEugene Leviant; OPTIMIZE:      i32 @main
243aef3528SEugene Leviant; OPTIMIZE-NEXT:   %1 = tail call i32 @rand()
253aef3528SEugene Leviant; OPTIMIZE-NEXT:   %2 = tail call i32 @rand()
263aef3528SEugene Leviant; OPTIMIZE-NEXT:   ret i32 0
273aef3528SEugene Leviant
2854a3c2a8STeresa Johnson; Confirm that with -propagate-attrs=false we no longer do write-only importing
2954a3c2a8STeresa Johnson; RUN: llvm-lto -propagate-attrs=false -thinlto-action=import -exported-symbol=main  %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported.bc -stats 2>&1 | FileCheck %s --check-prefix=STATS-NOPROP
3054a3c2a8STeresa Johnson; RUN: llvm-dis %t1.imported.bc -o - | FileCheck %s --check-prefix=IMPORT-NOPROP
3154a3c2a8STeresa Johnson; STATS-NOPROP-NOT: Number of live global variables marked write only
32*cedfa38fSJin Lin; IMPORT-NOPROP:      @gBar = available_externally
33*cedfa38fSJin Lin; IMPORT-NOPROP-NEXT: @gFoo.llvm.0 = available_externally
3454a3c2a8STeresa Johnson
357b1d7937SAmy Huangtarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
363aef3528SEugene Levianttarget triple = "x86_64-pc-linux-gnu"
373aef3528SEugene Leviant
383aef3528SEugene Leviant@gBar = external global i32
393aef3528SEugene Leviant
403aef3528SEugene Leviant; Should not be counted in the stats of live write only variables since it is
413aef3528SEugene Leviant; dead and will be dropped anyway.
423aef3528SEugene Leviant@gDead = internal unnamed_addr global i32 1, align 4
433aef3528SEugene Leviant
443aef3528SEugene Leviantdefine i32 @main() local_unnamed_addr {
453aef3528SEugene Leviant  tail call void @baz()
463aef3528SEugene Leviant  ret i32 0
473aef3528SEugene Leviant}
483aef3528SEugene Leviantdeclare void @baz() local_unnamed_addr
49