| @@ -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 | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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 | |||
| @@ -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) | |||
| @@ -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 | |||
| @@ -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 } | |||
| @@ -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 | |||
| @@ -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 | |||
| } | |||
| @@ -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) | |||
| @@ -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 | |||
| } | |||
| @@ -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 | |||
| } | |||
| @@ -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 | |||
| @@ -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 | |||
| } | |||
| @@ -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 | |||
| } | |||
| @@ -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 | |||
| } | |||
| @@ -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 | |||
| } | |||
| @@ -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 | |||
| } | |||
| @@ -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 | |||
| } | |||
| @@ -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 | |||
| @@ -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 | |||