50 lines · plain
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-only3; 2. Make a local copy of internal definition if all accesses to it are readonly. This allows constant4; folding it during optimziation phase.5 6; -stats requires asserts7; REQUIRES: asserts8 9; RUN: opt -module-summary %s -o %t1.bc10; RUN: opt -module-summary %p/Inputs/index-const-prop.ll -o %t2.bc11; RUN: llvm-lto -thinlto-action=thinlink -o %t3.index.bc %t1.bc %t2.bc12; 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=STATS13; RUN: llvm-dis %t1.imported.bc -o - | FileCheck %s --check-prefix=IMPORT14; RUN: llvm-lto -thinlto-action=optimize %t1.imported.bc -o - | llvm-dis - -o - | FileCheck %s --check-prefix=OPTIMIZE15 16; STATS: 2 module-summary-index - Number of live global variables marked read only17 18; Check that we don't internalize gBar when it is exported19; RUN: llvm-lto -thinlto-action=import -exported-symbol main -exported-symbol gBar %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported2.bc20; RUN: llvm-dis %t1.imported2.bc -o - | FileCheck %s --check-prefix=IMPORT221 22; IMPORT: @gBar = internal local_unnamed_addr global i32 2, align 4, !dbg !023; IMPORT-NEXT: @gFoo.llvm.0 = internal unnamed_addr global i32 1, align 4, !dbg !524; IMPORT: !DICompileUnit({{.*}})25 26; OPTIMIZE: define noundef i32 @main27; OPTIMIZE-NEXT: ret i32 328 29; IMPORT2: @gBar = available_externally local_unnamed_addr global i32 2, align 4, !dbg !030 31target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"32target triple = "x86_64-pc-linux-gnu"33 34@gBar = external global i3235 36; Should not be counted in the stats of live read only variables since it is37; dead and will be dropped anyway.38@gDead = internal unnamed_addr global i32 1, align 439 40define i32 @main() local_unnamed_addr {41 %call = tail call i32 @foo()42 %call1 = tail call i32 @bar()43 %add = add nsw i32 %call1, %call44 ret i32 %add45}46 47declare i32 @foo(...) local_unnamed_addr48 49declare i32 @bar(...) local_unnamed_addr50