diff options
Diffstat (limited to 'llvm/test/ThinLTO')
23 files changed, 502 insertions, 7 deletions
diff --git a/llvm/test/ThinLTO/X86/Inputs/index-const-prop-alias.ll b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-alias.ll new file mode 100644 index 00000000000..d5aa6ee0b61 --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-alias.ll @@ -0,0 +1,5 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@g = global i32 42, align 4 +@g.alias = weak alias i32, i32* @g diff --git a/llvm/test/ThinLTO/X86/Inputs/index-const-prop-cache-foo.ll b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-cache-foo.ll new file mode 100644 index 00000000000..5f85f1e38c9 --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-cache-foo.ll @@ -0,0 +1,19 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@gFoo = internal unnamed_addr global i32 1, align 4 + +; Function Attrs: norecurse nounwind readonly ssp uwtable +define i32 @foo() local_unnamed_addr { + %1 = load i32, i32* @gFoo, align 4 + ret i32 %1 +} + +; Function Attrs: nounwind ssp uwtable +define void @bar() local_unnamed_addr { + %1 = tail call i32 @rand() + store i32 %1, i32* @gFoo, align 4 + ret void +} + +declare i32 @rand() local_unnamed_addr diff --git a/llvm/test/ThinLTO/X86/Inputs/index-const-prop-cache-test1.ll b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-cache-test1.ll new file mode 100644 index 00000000000..6bcf3b32d0d --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-cache-test1.ll @@ -0,0 +1,10 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: nounwind ssp uwtable +define i32 @test() local_unnamed_addr { + %1 = tail call i32 (...) @foo() + ret i32 %1 +} + +declare i32 @foo(...) local_unnamed_addr diff --git a/llvm/test/ThinLTO/X86/Inputs/index-const-prop-cache-test2.ll b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-cache-test2.ll new file mode 100644 index 00000000000..75a8f071f48 --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-cache-test2.ll @@ -0,0 +1,14 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: nounwind ssp uwtable +define i32 @test() local_unnamed_addr { + %1 = tail call i32 (...) @foo() + %2 = tail call i32 (...) @bar() + %3 = add nsw i32 %2, %1 + ret i32 %3 +} + +declare i32 @foo(...) local_unnamed_addr + +declare i32 @bar(...) local_unnamed_addr diff --git a/llvm/test/ThinLTO/X86/Inputs/index-const-prop-comdat.ll b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-comdat.ll new file mode 100644 index 00000000000..819ba8caa32 --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-comdat.ll @@ -0,0 +1,5 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +$comdat.any = comdat any +@g = global i32 42, comdat($comdat.any) diff --git a/llvm/test/ThinLTO/X86/Inputs/index-const-prop-define-g.ll b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-define-g.ll new file mode 100644 index 00000000000..555f76f5930 --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-define-g.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" + +@g = global i32 42, align 4 diff --git a/llvm/test/ThinLTO/X86/Inputs/index-const-prop-full-lto.ll b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-full-lto.ll new file mode 100644 index 00000000000..e22f9198951 --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-full-lto.ll @@ -0,0 +1,12 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@g = external global i32 + +define i32 @foo() { + %v = load i32, i32* @g + ret i32 %v +} + +!0 = !{i32 1, !"ThinLTO", i32 0} +!llvm.module.flags = !{ !0 } diff --git a/llvm/test/ThinLTO/X86/Inputs/index-const-prop-gvref.ll b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-gvref.ll new file mode 100644 index 00000000000..ec0de9c9141 --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-gvref.ll @@ -0,0 +1,5 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@b = global i32* @a, align 8 +@a = global i32 42, align 4 diff --git a/llvm/test/ThinLTO/X86/Inputs/index-const-prop-linkage.ll b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-linkage.ll new file mode 100644 index 00000000000..24c724743e0 --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/index-const-prop-linkage.ll @@ -0,0 +1,15 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@g1 = common global i32 0, align 4 +@g2 = global i32 42, align 4 +@g3 = available_externally global i32 42, align 4 + +define i32 @foo() { + %v1 = load i32, i32* @g1 + %v2 = load i32, i32* @g2 + %v3 = load i32, i32* @g3 + %s1 = add i32 %v1, %v2 + %s2 = add i32 %s1, %v3 + ret i32 %s2 +} diff --git a/llvm/test/ThinLTO/X86/Inputs/index-const-prop.ll b/llvm/test/ThinLTO/X86/Inputs/index-const-prop.ll new file mode 100644 index 00000000000..eda62fb4e5b --- /dev/null +++ b/llvm/test/ThinLTO/X86/Inputs/index-const-prop.ll @@ -0,0 +1,64 @@ +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-pc-linux-gnu" + +@gBar = local_unnamed_addr global i32 2, align 4, !dbg !0 +@gFoo = internal unnamed_addr global i32 1, align 4, !dbg !6 + +; Function Attrs: norecurse nounwind readonly +define i32 @foo() local_unnamed_addr #0 !dbg !14 { + %1 = load i32, i32* @gFoo, align 4, !dbg !17 + ret i32 %1, !dbg !18 +} + +; Function Attrs: norecurse nounwind readonly +define i32 @bar() local_unnamed_addr #0 !dbg !19 { + %1 = load i32, i32* @gBar, align 4, !dbg !20 + ret i32 %1, !dbg !21 +} + +define void @baz() local_unnamed_addr !dbg !22 { + %1 = tail call i32 @rand(), !dbg !25 + store i32 %1, i32* @gFoo, align 4, !dbg !26 + %2 = tail call i32 @rand(), !dbg !27 + store i32 %2, i32* @gBar, align 4, !dbg !28 + ret void, !dbg !29 +} + +declare i32 @rand() local_unnamed_addr + +attributes #0 = { norecurse nounwind readonly } + +!llvm.dbg.cu = !{!2} +!llvm.module.flags = !{!9, !10, !11, !12} +!llvm.ident = !{!13} + +!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) +!1 = distinct !DIGlobalVariable(name: "gBar", scope: !2, file: !3, line: 4, type: !8, isLocal: false, isDefinition: true) +!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang version 7.0.0 (trunk 332246)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5) +!3 = !DIFile(filename: "foo.c", directory: "/data/work/lto/roref/test") +!4 = !{} +!5 = !{!0, !6} +!6 = !DIGlobalVariableExpression(var: !7, expr: !DIExpression()) +!7 = distinct !DIGlobalVariable(name: "gFoo", scope: !2, file: !3, line: 3, type: !8, isLocal: true, isDefinition: true) +!8 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!9 = !{i32 2, !"Dwarf Version", i32 4} +!10 = !{i32 2, !"Debug Info Version", i32 3} +!11 = !{i32 1, !"wchar_size", i32 4} +!12 = !{i32 7, !"PIC Level", i32 2} +!13 = !{!"clang version 7.0.0 (trunk 332246)"} +!14 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 6, type: !15, isLocal: false, isDefinition: true, scopeLine: 6, isOptimized: true, unit: !2, retainedNodes: !4) +!15 = !DISubroutineType(types: !16) +!16 = !{!8} +!17 = !DILocation(line: 7, column: 10, scope: !14) +!18 = !DILocation(line: 7, column: 3, scope: !14) +!19 = distinct !DISubprogram(name: "bar", scope: !3, file: !3, line: 10, type: !15, isLocal: false, isDefinition: true, scopeLine: 10, isOptimized: true, unit: !2, retainedNodes: !4) +!20 = !DILocation(line: 11, column: 10, scope: !19) +!21 = !DILocation(line: 11, column: 3, scope: !19) +!22 = distinct !DISubprogram(name: "baz", scope: !3, file: !3, line: 14, type: !23, isLocal: false, isDefinition: true, scopeLine: 14, isOptimized: true, unit: !2, retainedNodes: !4) +!23 = !DISubroutineType(types: !24) +!24 = !{null} +!25 = !DILocation(line: 15, column: 10, scope: !22) +!26 = !DILocation(line: 15, column: 8, scope: !22) +!27 = !DILocation(line: 16, column: 10, scope: !22) +!28 = !DILocation(line: 16, column: 8, scope: !22) +!29 = !DILocation(line: 17, column: 1, scope: !22) diff --git a/llvm/test/ThinLTO/X86/dot-dumper.ll b/llvm/test/ThinLTO/X86/dot-dumper.ll index 72175a1ea4d..7578212ec44 100644 --- a/llvm/test/ThinLTO/X86/dot-dumper.ll +++ b/llvm/test/ThinLTO/X86/dot-dumper.ll @@ -20,7 +20,7 @@ ; STRUCTURE-DAG: subgraph cluster_1 ; STRUCTURE: // Cross-module edges: ; STRUCTURE-DAG: M0_{{[0-9]+}} -> M1_{{[0-9]+}} // call -; STRUCTURE-DAG: M0_{{[0-9]+}} -> M1_{{[0-9]+}} [{{.*}}]; // ref +; STRUCTURE-DAG: M0_{{[0-9]+}} -> M1_{{[0-9]+}} [{{.*}}]; // const-ref ; STRUCTURE-NEXT: } ; CLUSTER0: // Module: {{.*}}1.bc @@ -33,13 +33,13 @@ ; CLUSTER1: // Module: {{.*}}2.bc ; CLUSTER1-NEXT: subgraph cluster_1 { -; CLUSTER1-DAG: M1_[[A:[0-9]+]] [{{.*}}A|extern{{.*}}]; // variable +; CLUSTER1-DAG: M1_[[A:[0-9]+]] [{{.*}}A|extern{{.*}}]; // variable, immutable ; CLUSTER1-DAG: M1_[[FOO:[0-9]+]] [{{.*}}foo|extern{{.*}} ffl: 00001{{.*}}]; // function -; CLUSTER1-DAG: M1_[[B:[0-9]+]] [{{.*}}B|extern{{.*}}]; // variable +; CLUSTER1-DAG: M1_[[B:[0-9]+]] [{{.*}}B|extern{{.*}}]; // variable, immutable ; CLUSTER1-DAG: M1_[[BAR:[0-9]+]] [{{.*}}bar|extern{{.*}}]; // function, dead ; CLUSTER1-NEXT: // Edges: -; CLUSTER1-DAG: M1_[[FOO]] -> M1_[[B]] [{{.*}}]; // ref -; CLUSTER1-DAG: M1_[[FOO]] -> M1_[[A]] [{{.*}}]; // ref +; CLUSTER1-DAG: M1_[[FOO]] -> M1_[[B]] [{{.*}}]; // const-ref +; CLUSTER1-DAG: M1_[[FOO]] -> M1_[[A]] [{{.*}}]; // const-ref ; CLUSTER1-DAG: } target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" diff --git a/llvm/test/ThinLTO/X86/globals-import-const-fold.ll b/llvm/test/ThinLTO/X86/globals-import-const-fold.ll index 49e31b79a47..a250ed2e92b 100644 --- a/llvm/test/ThinLTO/X86/globals-import-const-fold.ll +++ b/llvm/test/ThinLTO/X86/globals-import-const-fold.ll @@ -2,12 +2,12 @@ ; RUN: opt -module-summary %p/Inputs/globals-import-cf-baz.ll -o %t2.bc ; RUN: llvm-lto -thinlto-action=thinlink %t1.bc %t2.bc -o %t3.index.bc -; RUN: llvm-lto -thinlto-action=import %t1.bc %t2.bc -thinlto-index=%t3.index.bc +; RUN: llvm-lto -thinlto-action=import -exported-symbol=main %t1.bc -thinlto-index=%t3.index.bc ; RUN: llvm-dis %t1.bc.thinlto.imported.bc -o - | FileCheck --check-prefix=IMPORT %s ; RUN: llvm-lto -thinlto-action=optimize %t1.bc.thinlto.imported.bc -o %t1.bc.thinlto.opt.bc ; RUN: llvm-dis %t1.bc.thinlto.opt.bc -o - | FileCheck --check-prefix=OPTIMIZE %s -; IMPORT: @baz = available_externally local_unnamed_addr constant i32 10 +; IMPORT: @baz = internal local_unnamed_addr constant i32 10 ; OPTIMIZE: define i32 @main() ; OPTIMIZE-NEXT: ret i32 10 diff --git a/llvm/test/ThinLTO/X86/index-const-prop-O0.ll b/llvm/test/ThinLTO/X86/index-const-prop-O0.ll new file mode 100644 index 00000000000..6426d726843 --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop-O0.ll @@ -0,0 +1,18 @@ +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop-define-g.ll -o %t2.bc +; RUN: llvm-lto2 run -O0 -save-temps %t2.bc -r=%t2.bc,g,pl %t1.bc -r=%t1.bc,main,plx -r=%t1.bc,g, -o %t3 +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s + +; With -O0 import is disabled so we must not internalize +; read-only globals +; CHECK: @g = dso_local global i32 42 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@g = external global i32 + +define i32 @main() { + %v = load i32, i32* @g + ret i32 %v +} diff --git a/llvm/test/ThinLTO/X86/index-const-prop-alias.ll b/llvm/test/ThinLTO/X86/index-const-prop-alias.ll new file mode 100644 index 00000000000..592fc9e081a --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop-alias.ll @@ -0,0 +1,42 @@ +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop-alias.ll -o %t2.bc +; RUN: llvm-lto2 run %t1.bc -r=%t1.bc,main,plx -r=%t1.bc,ret_ptr,pl -r=%t1.bc,g.alias,l -r=%t1.bc,g,l \ +; RUN: %t2.bc -r=%t2.bc,g,pl -r=%t2.bc,g.alias,pl -save-temps -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 + +; When ret_ptr is preserved we return pointer to alias, so we can't internalize aliasee +; RUN: llvm-lto2 run %t1.bc -r=%t1.bc,main,plx -r=%t1.bc,ret_ptr,plx -r=%t1.bc,g.alias,l -r=%t1.bc,g,l \ +; RUN: %t2.bc -r=%t2.bc,g,pl -r=%t2.bc,g.alias,pl -save-temps -o %t4 +; RUN: llvm-dis %t4.1.3.import.bc -o - | FileCheck %s --check-prefix=PRESERVED + +; When g.alias is preserved we can't internalize aliasee either +; RUN: llvm-lto2 run %t1.bc -r=%t1.bc,main,plx -r=%t1.bc,ret_ptr,pl -r=%t1.bc,g.alias,l -r=%t1.bc,g,l \ +; RUN: %t2.bc -r=%t2.bc,g,pl -r=%t2.bc,g.alias,plx -save-temps -o %t5 +; RUN: llvm-dis %t5.1.3.import.bc -o - | FileCheck %s --check-prefix=PRESERVED + +; We currently don't support importing aliases +; IMPORT: @g.alias = external dso_local global i32 +; IMPORT-NEXT: @g = internal global i32 42, align 4 #0 +; IMPORT: attributes #0 = { "thinlto-internalize" } + +; CODEGEN: define dso_local i32 @main +; CODEGEN-NEXT: ret i32 42 + +; PRESERVED: @g.alias = external dso_local global i32 +; PRESERVED-NEXT: @g = available_externally dso_local global i32 42, align 4 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@g.alias = external global i32 +@g = external global i32 + +define i32 @main() { + %v = load i32, i32* @g + ret i32 %v +} + +define i32* @ret_ptr() { + ret i32* @g.alias +} diff --git a/llvm/test/ThinLTO/X86/index-const-prop-cache.ll b/llvm/test/ThinLTO/X86/index-const-prop-cache.ll new file mode 100644 index 00000000000..62a22af0b1e --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop-cache.ll @@ -0,0 +1,41 @@ +; Check that we correctly handle 'ReadOnly' attribute when computing cache key +; RUN: opt -module-summary -module-hash %s -o %t1.bc +; RUN: opt -module-summary -module-hash %p/Inputs/index-const-prop-cache-foo.ll -o %t2.bc +; RUN: opt -module-summary -module-hash %p/Inputs/index-const-prop-cache-test1.ll -o %t3.bc +; RUN: opt -module-summary -module-hash %p/Inputs/index-const-prop-cache-test2.ll -o %t4.bc +; RUN: rm -Rf %t.cache && mkdir %t.cache + +; Here @gFoo variable is writeable +; RUN: llvm-lto -thinlto-action=run %t1.bc %t4.bc %t2.bc \ +; RUN: -exported-symbol=main -exported-symbol=test -thinlto-cache-dir=%t.cache +; RUN: ls %t.cache/llvmcache-* | count 3 + +; Now gFoo is read-only and all modules should get different cache keys. +; RUN: llvm-lto -thinlto-action=run %t1.bc %t3.bc %t2.bc \ +; RUN: -exported-symbol=main -exported-symbol=test -thinlto-cache-dir=%t.cache +; RUN: ls %t.cache/llvmcache-* | count 6 + +; Do the same but with llvm-lto2 +; RUN: rm -Rf %t.cache && mkdir %t.cache +; RUN: llvm-lto2 run %t1.bc %t4.bc %t2.bc -cache-dir=%t.cache -o %t5 \ +; RUN: -r=%t1.bc,main,plx -r=%t1.bc,foo,l \ +; RUN: -r=%t4.bc,test,plx -r=%t4.bc,foo,l -r=%t4.bc,bar,l \ +; RUN: -r=%t2.bc,foo,pl -r=%t2.bc,bar,pl -r=%t2.bc,rand, +; RUN: ls %t.cache/llvmcache-* | count 3 + +; RUN: llvm-lto2 run %t1.bc %t3.bc %t2.bc -cache-dir %t.cache -o %t6 \ +; RUN: -r=%t1.bc,main,plx -r=%t1.bc,foo,l \ +; RUN: -r=%t3.bc,test,plx -r=%t3.bc,foo,l \ +; RUN: -r=%t2.bc,foo,pl -r=%t2.bc,bar,pl -r=%t2.bc,rand, +; RUN: ls %t.cache/llvmcache-* | count 6 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +; Function Attrs: nounwind ssp uwtable +define i32 @main() local_unnamed_addr { + %1 = tail call i32 (...) @foo() + ret i32 %1 +} + +declare i32 @foo(...) local_unnamed_addr diff --git a/llvm/test/ThinLTO/X86/index-const-prop-comdat.ll b/llvm/test/ThinLTO/X86/index-const-prop-comdat.ll new file mode 100644 index 00000000000..e05aaf98d7f --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop-comdat.ll @@ -0,0 +1,17 @@ +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop-comdat.ll -o %t2.bc +; RUN: llvm-lto2 run -save-temps %t2.bc -r=%t2.bc,g,pl %t1.bc -r=%t1.bc,main,plx -r=%t1.bc,g, -o %t3 +; RUN: llvm-dis %t3.2.3.import.bc -o - | FileCheck %s + +; Comdats are not internalized even if they are read only. +; CHECK: @g = available_externally dso_local global i32 42 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@g = external global i32 + +define i32 @main() { + %v = load i32, i32* @g + ret i32 %v +} diff --git a/llvm/test/ThinLTO/X86/index-const-prop-dead.ll b/llvm/test/ThinLTO/X86/index-const-prop-dead.ll new file mode 100644 index 00000000000..f3ffca8cbdf --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop-dead.ll @@ -0,0 +1,26 @@ +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop-define-g.ll -o %t2.bc +; RUN: llvm-lto2 run -save-temps %t2.bc -r=%t2.bc,g,pl \ +; RUN: %t1.bc -r=%t1.bc,main,plx -r=%t1.bc,foo,pl -r=%t1.bc,g, -o %t3 +; RUN: llvm-dis %t3.2.3.import.bc -o - | FileCheck %s + +; Dead globals are converted to declarations by ThinLTO in dropDeadSymbols +; If we try to internalize such we'll get a broken module. +; CHECK: @g = external dso_local global i32 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@g = external global i32 + +; We need at least one live symbol to enable dead stripping +; Otherwise ModuleSummaryIndex::isGlobalValueLive will always +; return true. +define i32 @main() { + ret i32 42 +} + +define i32 @foo() { + %v = load i32, i32* @g + ret i32 %v +} diff --git a/llvm/test/ThinLTO/X86/index-const-prop-full-lto.ll b/llvm/test/ThinLTO/X86/index-const-prop-full-lto.ll new file mode 100644 index 00000000000..26fe4d644b7 --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop-full-lto.ll @@ -0,0 +1,24 @@ +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop-define-g.ll -o %t2.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop-full-lto.ll -o %t3.bc +; RUN: llvm-lto2 run -save-temps %t2.bc -r=%t2.bc,g,pl \ +; RUN: %t1.bc -r=%t1.bc,foo,l -r=%t1.bc,main,plx -r=%t1.bc,g, \ +; RUN: %t3.bc -r=%t3.bc,foo,pl -r=%t3.bc,g, -o %t4 +; RUN: llvm-dis %t4.2.3.import.bc -o - | FileCheck %s + +; All references from functions in full LTO module are not constant. +; We cannot internalize @g +; CHECK: @g = available_externally dso_local global i32 42 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare i32 @foo() +@g = external global i32 + +define i32 @main() { + %v = call i32 @foo() + %v2 = load i32, i32* @g + %v3 = add i32 %v, %v2 + ret i32 %v3 +} diff --git a/llvm/test/ThinLTO/X86/index-const-prop-gvref.ll b/llvm/test/ThinLTO/X86/index-const-prop-gvref.ll new file mode 100644 index 00000000000..87103fee141 --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop-gvref.ll @@ -0,0 +1,27 @@ +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop-gvref.ll -o %t2.bc +; RUN: llvm-lto2 run -save-temps %t2.bc -r=%t2.bc,b,pl -r=%t2.bc,a,pl \ +; RUN: %t1.bc -r=%t1.bc,main,plx -r=%t1.bc,a, -r=%t1.bc,b, -o %t3 +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=SRC +; RUN: llvm-dis %t3.2.3.import.bc -o - | FileCheck %s --check-prefix=DEST + +; No variable in the source module should have been internalized +; SRC: @b = dso_local global i32* @a +; SRC-NEXT: @a = dso_local global i32 42 + +; We can't internalize globals referenced by other live globals +; DEST: @b = external dso_local global i32* +; DEST-NEXT: @a = available_externally dso_local global i32 42, align 4 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@a = external global i32 +@b = external global i32* + +define i32 @main() { + %p = load i32*, i32** @b, align 8 + store i32 33, i32* %p, align 4 + %v = load i32, i32* @a, align 4 + ret i32 %v +} diff --git a/llvm/test/ThinLTO/X86/index-const-prop-ldst.ll b/llvm/test/ThinLTO/X86/index-const-prop-ldst.ll new file mode 100644 index 00000000000..4646557b6cf --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop-ldst.ll @@ -0,0 +1,21 @@ +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop-define-g.ll -o %t2.bc +; RUN: llvm-lto2 run -save-temps %t2.bc -r=%t2.bc,g,pl %t1.bc -r=%t1.bc,main,plx -r=%t1.bc,g, -o %t3 +; RUN: llvm-dis %t3.2.3.import.bc -o - | FileCheck %s + +; The 'store' instruction in @main should prevent internalization +; even when there is 'load' instruction before it. +; CHECK: @g = available_externally dso_local global i32 42 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +@g = external global i32 + +define i32 @main() { + %v = load i32, i32* @g + %q = add i32 %v, 1 + store i32 %q, i32* @g + + ret i32 %v +} diff --git a/llvm/test/ThinLTO/X86/index-const-prop-linkage.ll b/llvm/test/ThinLTO/X86/index-const-prop-linkage.ll new file mode 100644 index 00000000000..aac91772111 --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop-linkage.ll @@ -0,0 +1,27 @@ +; RUN: opt -module-summary %s -o %t1.bc +; RUN: opt -module-summary %p/Inputs/index-const-prop-linkage.ll -o %t2.bc +; RUN: llvm-lto2 run -save-temps %t2.bc -r=%t2.bc,foo,pl -r=%t2.bc,g1,pl -r=%t2.bc,g2,pl -r=%t2.bc,g3, \ +; RUN: %t1.bc -r=%t1.bc,foo, -r=%t1.bc,main,plx -r=%t1.bc,g2, -o %t3 +; RUN: llvm-dis %t3.2.3.import.bc -o - | FileCheck %s + +; Check that we never internalize anything with: +; - appending linkage +; - common linkage +; - available_externally linkage +; - reference from @llvm.used +; CHECK: @llvm.used = appending global [1 x i32*] [i32* @g2] +; CHECK-NEXT: @g1 = external dso_local global i32, align 4 +; CHECK-NEXT: @g2 = available_externally dso_local global i32 42, align 4 +; CHECK-NEXT: @g3 = available_externally global i32 42, align 4 + +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" +target triple = "x86_64-unknown-linux-gnu" + +declare i32 @foo() +@g2 = external global i32 +@llvm.used = appending global [1 x i32*] [i32* @g2] + +define i32 @main() { + %v = call i32 @foo() + ret i32 %v +} diff --git a/llvm/test/ThinLTO/X86/index-const-prop.ll b/llvm/test/ThinLTO/X86/index-const-prop.ll new file mode 100644 index 00000000000..df99d83fbb5 --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop.ll @@ -0,0 +1,40 @@ +; Check constant propagation in thinlto combined summary. This allows us to do 2 things: +; 1. Internalize global definition which is not used externally if all accesses to it are read-only +; 2. Make a local copy of internal definition if all accesses to it are readonly. This allows constant +; folding it during optimziation phase. + +; 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 +; RUN: llvm-lto -thinlto-action=import -exported-symbol=main %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported.bc +; 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 + +; Check that we don't internalize gBar when it is exported +; RUN: llvm-lto -thinlto-action=import -exported-symbol main -exported-symbol gBar %t1.bc -thinlto-index=%t3.index.bc -o %t1.imported2.bc +; RUN: llvm-dis %t1.imported2.bc -o - | FileCheck %s --check-prefix=IMPORT2 + +; 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({{.*}}, globals: !{{[0-9]+}}) + +; OPTIMIZE: define i32 @main +; OPTIMIZE-NEXT: ret i32 3 + +; IMPORT2: @gBar = available_externally local_unnamed_addr global i32 2, align 4, !dbg !5 + +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 + +define i32 @main() local_unnamed_addr { + %call = tail call i32 bitcast (i32 (...)* @foo to i32 ()*)() + %call1 = tail call i32 bitcast (i32 (...)* @bar to i32 ()*)() + %add = add nsw i32 %call1, %call + ret i32 %add +} + +declare i32 @foo(...) local_unnamed_addr + +declare i32 @bar(...) local_unnamed_addr diff --git a/llvm/test/ThinLTO/X86/index-const-prop2.ll b/llvm/test/ThinLTO/X86/index-const-prop2.ll new file mode 100644 index 00000000000..d6c8ec80661 --- /dev/null +++ b/llvm/test/ThinLTO/X86/index-const-prop2.ll @@ -0,0 +1,59 @@ +; Check constant propagation in thinlto combined summary. This allows us to do 2 things: +; 1. Internalize global definition which is not used externally if all accesses to it are read-only +; 2. Make a local copy of internal definition if all accesses to it are readonly. This allows constant +; folding it during optimziation phase. +; 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,foo, \ +; RUN: -r=%t1.bc,bar, \ +; 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 + +; Now check that we won't internalize global (gBar) if it's externally referenced +; 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,plx \ +; RUN: -r=%t1.bc,main,plx \ +; RUN: -r=%t1.bc,foo, \ +; RUN: -r=%t1.bc,bar, \ +; RUN: -r=%t1.bc,gBar, \ +; RUN: -o %t3 +; RUN: llvm-dis %t3.1.3.import.bc -o - | FileCheck %s --check-prefix=IMPORT2 + +; 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({{.*}}, globals: !{{[0-9]+}}) + +; CODEGEN: i32 @main() +; CODEGEN-NEXT: ret i32 3 + +; IMPORT2: @gBar = available_externally dso_local local_unnamed_addr global i32 2, align 4 + +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 { + %call = tail call i32 bitcast (i32 (...)* @foo to i32 ()*)() + %call1 = tail call i32 bitcast (i32 (...)* @bar to i32 ()*)() + %add = add nsw i32 %call1, %call + ret i32 %add +} + +declare i32 @foo(...) local_unnamed_addr + +declare i32 @bar(...) local_unnamed_addr |

