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.
6 ; -stats requires asserts
9 ; RUN: opt -module-summary %s -o %t1.bc
10 ; RUN: opt -module-summary %p/Inputs/index-const-prop.ll -o %t2.bc
11 ; RUN: llvm-lto -thinlto-action=thinlink -o %t3.index.bc %t1.bc %t2.bc
12 ; 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
13 ; RUN: llvm-dis %t1.imported.bc -o - | FileCheck %s --check-prefix=IMPORT
14 ; RUN: llvm-lto -thinlto-action=optimize %t1.imported.bc -o - | llvm-dis - -o - | FileCheck %s --check-prefix=OPTIMIZE
16 ; STATS: 2 module-summary-index - Number of live global variables marked read only
18 ; Check that we don't internalize gBar when it is exported
19 ; RUN: llvm-lto -thinlto-action=import -exported-symbol main -exported-symbol gBar %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported2.bc
20 ; RUN: llvm-dis %t1.imported2.bc -o - | FileCheck %s --check-prefix=IMPORT2
22 ; IMPORT: @gBar = internal local_unnamed_addr global i32 2, align 4, !dbg !0
23 ; IMPORT-NEXT: @gFoo.llvm.0 = internal unnamed_addr global i32 1, align 4, !dbg !5
24 ; IMPORT: !DICompileUnit({{.*}})
26 ; OPTIMIZE: define noundef i32 @main
27 ; OPTIMIZE-NEXT: ret i32 3
29 ; IMPORT2: @gBar = available_externally local_unnamed_addr global i32 2, align 4, !dbg !0
31 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
32 target triple = "x86_64-pc-linux-gnu"
34 @gBar = external global i32
36 ; Should not be counted in the stats of live read only variables since it is
37 ; dead and will be dropped anyway.
38 @gDead = internal unnamed_addr global i32 1, align 4
40 define i32 @main() local_unnamed_addr {
41 %call = tail call i32 @foo()
42 %call1 = tail call i32 @bar()
43 %add = add nsw i32 %call1, %call
47 declare i32 @foo(...) local_unnamed_addr
49 declare i32 @bar(...) local_unnamed_addr