diff options
Diffstat (limited to 'llvm/test/ThinLTO/X86')
-rw-r--r-- | llvm/test/ThinLTO/X86/Inputs/dot-dumper2.ll | 4 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/dot-dumper2.ll | 43 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/index-const-prop2.ll | 44 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/writeonly.ll | 41 | ||||
-rw-r--r-- | llvm/test/ThinLTO/X86/writeonly2.ll | 50 |
5 files changed, 180 insertions, 2 deletions
diff --git a/llvm/test/ThinLTO/X86/Inputs/dot-dumper2.ll b/llvm/test/ThinLTO/X86/Inputs/dot-dumper2.ll new file mode 100644 index 00000000000..6d9783e92d0 --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/dot-dumper2.ll @@ -0,0 +1,4 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@A = local_unnamed_addr global i32 10, align 4 diff --git a/llvm/test/ThinLTO/X86/dot-dumper2.ll b/llvm/test/ThinLTO/X86/dot-dumper2.ll new file mode 100644 index 00000000000..8cc9822aed4 --- /dev/null +++ b/llvm/test/ThinLTO/X86/dot-dumper2.ll @@ -0,0 +1,43 @@ +; Test writeOnly attribute +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/dot-dumper2.ll -o %t2.bc +; RUN: llvm-lto2 run -save-temps %t1.bc %t2.bc -o %t3 \ +; RUN: -r=%t1.bc,main,px \ +; RUN: -r=%t1.bc,A, \ +; RUN: -r=%t2.bc,A,p + +; RUN: cat %t3.index.dot | FileCheck --check-prefix=COMBINED %s + +; COMBINED: digraph Summary { +; COMBINED-NEXT: // Module: +; COMBINED-NEXT: subgraph cluster_0 { +; COMBINED-NEXT: style = filled; +; COMBINED-NEXT: color = lightgrey; +; COMBINED-NEXT: label = +; COMBINED-NEXT: node [style=filled,fillcolor=lightblue]; +; COMBINED-NEXT: M0_[[MAIN:[0-9]+]] [shape="record",label="main|extern (inst: 2, ffl: 00000)}"]; // function +; COMBINED-NEXT: // Edges: +; COMBINED-NEXT: } +; COMBINED-NEXT: // Module: +; COMBINED-NEXT: subgraph cluster_1 { +; COMBINED-NEXT: style = filled; +; COMBINED-NEXT: color = lightgrey; +; COMBINED-NEXT: label = +; COMBINED-NEXT: node [style=filled,fillcolor=lightblue]; +; COMBINED-NEXT: M1_[[A:[0-9]+]] [shape="Mrecord",label="A|extern}"]; // variable, writeOnly +; COMBINED-NEXT: // Edges: +; COMBINED-NEXT: } +; COMBINED-NEXT: // Cross-module edges: +; COMBINED-NEXT: M0_[[MAIN]] -> M1_[[A]] [style=dashed,color=violetred]; // writeOnly-ref +; COMBINED-NEXT: } + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@A = external local_unnamed_addr global i32, align 4 + +; Function Attrs: nounwind uwtable +define i32 @main() local_unnamed_addr { + store i32 42, i32* @A, align 4 + ret i32 0 +} diff --git a/llvm/test/ThinLTO/X86/index-const-prop2.ll b/llvm/test/ThinLTO/X86/index-const-prop2.ll index 96b7593dd4f..a5fbbdf1e92 100644 --- a/llvm/test/ThinLTO/X86/index-const-prop2.ll +++ b/llvm/test/ThinLTO/X86/index-const-prop2.ll @@ -11,8 +11,10 @@ ; RUN: -r=%t2.bc,rand, \ ; RUN: -r=%t2.bc,gBar,pl \ ; RUN: -r=%t1.bc,main,plx \ +; RUN: -r=%t1.bc,main2,pl \ ; RUN: -r=%t1.bc,foo, \ ; RUN: -r=%t1.bc,bar, \ +; RUN: -r=%t1.bc,baz, \ ; RUN: -r=%t1.bc,gBar, \ ; RUN: -o %t3 ; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT @@ -26,11 +28,32 @@ ; RUN: -r=%t2.bc,rand, \ ; RUN: -r=%t2.bc,gBar,plx \ ; RUN: -r=%t1.bc,main,plx \ +; RUN: -r=%t1.bc,main2,pl \ ; RUN: -r=%t1.bc,foo, \ ; RUN: -r=%t1.bc,bar, \ +; RUN: -r=%t1.bc,baz, \ ; RUN: -r=%t1.bc,gBar, \ -; RUN: -o %t3 -; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT2 +; RUN: -o %t4 +; RUN: llvm-dis %t4.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT2 + +; RUN: llvm-lto2 run %t1.bc %t2.bc -save-temps \ +; RUN: -r=%t2.bc,foo,pl \ +; RUN: -r=%t2.bc,bar,pl \ +; RUN: -r=%t2.bc,baz,pl \ +; RUN: -r=%t2.bc,rand, \ +; RUN: -r=%t2.bc,gBar,pl \ +; RUN: -r=%t1.bc,main,pl \ +; RUN: -r=%t1.bc,main2,plx \ +; RUN: -r=%t1.bc,foo, \ +; RUN: -r=%t1.bc,bar, \ +; RUN: -r=%t1.bc,baz, \ +; RUN: -r=%t1.bc,gBar, \ +; RUN: -o %t5 +; RUN: llvm-dis %t5.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT +; RUN: llvm-dis %t5.1.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN2 +; Check that gFoo and gBar were eliminated from source module together +; with corresponsing stores +; RUN: llvm-dis %t5.2.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN2-SRC ; IMPORT: @gFoo.llvm.0 = internal unnamed_addr global i32 1, align 4 ; IMPORT-NEXT: @gBar = internal local_unnamed_addr global i32 2, align 4 @@ -41,6 +64,16 @@ ; IMPORT2: @gBar = available_externally dso_local local_unnamed_addr global i32 2, align 4 +; CODEGEN2: i32 @main2 +; CODEGEN2-NEXT: %1 = tail call i32 @rand() +; CODEGEN2-NEXT: %2 = tail call i32 @rand() +; CODEGEN2-NEXT: ret i32 0 + +; CODEGEN2-SRC: void @baz() +; CODEGEN2-SRC-NEXT: %1 = tail call i32 @rand() +; CODEGEN2-SRC-NEXT: %2 = tail call i32 @rand() +; CODEGEN2-SRC-NEXT: ret void + target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" target triple = "x86_64-pc-linux-gnu" @@ -54,6 +87,13 @@ define i32 @main() local_unnamed_addr { ret i32 %add } +define i32 @main2() local_unnamed_addr { + tail call void @baz() + ret i32 0 +} + declare i32 @foo(...) local_unnamed_addr declare i32 @bar(...) local_unnamed_addr + +declare void @baz() local_unnamed_addr diff --git a/llvm/test/ThinLTO/X86/writeonly.ll b/llvm/test/ThinLTO/X86/writeonly.ll new file mode 100644 index 00000000000..7c2af6d9cce --- /dev/null +++ b/llvm/test/ThinLTO/X86/writeonly.ll @@ -0,0 +1,41 @@ +; Checks that we optimize writeonly variables and corresponding stores using llvm-lto +; -stats requires asserts +; REQUIRES: asserts + +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop.ll -o %t2.bc +; RUN: llvm-lto -thinlto-action=thinlink -o %t3.index.bc %t1.bc %t2.bc + +; Check that we optimize write-only variables +; 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 +; RUN: llvm-dis %t1.imported.bc -o - | FileCheck %s --check-prefix=IMPORT +; RUN: llvm-lto -thinlto-action=optimize %t1.imported.bc -o - | llvm-dis - -o - | FileCheck %s --check-prefix=OPTIMIZE + +; IMPORT: @gFoo.llvm.0 = internal unnamed_addr global i32 1, align 4, !dbg !0 +; IMPORT-NEXT: @gBar = internal local_unnamed_addr global i32 2, align 4, !dbg !5 +; IMPORT: !DICompileUnit({{.*}}) + +; STATS: 2 module-summary-index - Number of live global variables marked write only + +; Check that we've optimized out variables and corresponding stores +; OPTIMIZE-NOT: gFoo +; OPTIMIZE-NOT: gBar +; OPTIMIZE: i32 @main +; OPTIMIZE-NEXT: %1 = tail call i32 @rand() +; OPTIMIZE-NEXT: %2 = tail call i32 @rand() +; OPTIMIZE-NEXT: ret i32 0 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-linux-gnu" + +@gBar = external global i32 + +; Should not be counted in the stats of live write only variables since it is +; dead and will be dropped anyway. +@gDead = internal unnamed_addr global i32 1, align 4 + +define i32 @main() local_unnamed_addr { + tail call void @baz() + ret i32 0 +} +declare void @baz() local_unnamed_addr diff --git a/llvm/test/ThinLTO/X86/writeonly2.ll b/llvm/test/ThinLTO/X86/writeonly2.ll new file mode 100644 index 00000000000..b1e53ba47b5 --- /dev/null +++ b/llvm/test/ThinLTO/X86/writeonly2.ll @@ -0,0 +1,50 @@ +; Check that we optimize out writeonly variables and corresponding stores. +; This test uses llvm-lto2 + +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop.ll -o %t2.bc +; RUN: llvm-lto2 run %t1.bc %t2.bc -save-temps \ +; RUN: -r=%t2.bc,foo,pl \ +; RUN: -r=%t2.bc,bar,pl \ +; RUN: -r=%t2.bc,baz,pl \ +; RUN: -r=%t2.bc,rand, \ +; RUN: -r=%t2.bc,gBar,pl \ +; RUN: -r=%t1.bc,main,plx \ +; RUN: -r=%t1.bc,baz, \ +; RUN: -r=%t1.bc,gBar, \ +; RUN: -o %t3 +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT +; RUN: llvm-dis %t3.1.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN +; Check that gFoo and gBar were eliminated from source module together +; with corresponsing stores +; RUN: llvm-dis %t3.2.5.precodegen.bc -o - | FileCheck %s --check-prefix=CODEGEN-SRC + +; IMPORT: @gFoo.llvm.0 = internal unnamed_addr global i32 1, align 4 +; IMPORT-NEXT: @gBar = internal local_unnamed_addr global i32 2, align 4 +; IMPORT: !DICompileUnit({{.*}}) + +; CODEGEN-NOT: gFoo +; CODEGEN-NOT: gBar +; CODEGEN: i32 @main +; CODEGEN-NEXT: %1 = tail call i32 @rand() +; CODEGEN-NEXT: %2 = tail call i32 @rand() +; CODEGEN-NEXT: ret i32 0 + +; CODEGEN-SRC-NOT: gFoo +; CODEGEN-SRC-NOT: gBar +; CODEGEN-SRC: void @baz() +; CODEGEN-SRC-NEXT: %1 = tail call i32 @rand() +; CODEGEN-SRC-NEXT: %2 = tail call i32 @rand() +; CODEGEN-SRC-NEXT: ret void + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-linux-gnu" + +; We should be able to link external definition of gBar to its declaration +@gBar = external global i32 + +define i32 @main() local_unnamed_addr { + tail call void @baz() + ret i32 0 +} +declare void @baz() local_unnamed_addr |