1 ; RUN: opt < %s -S -passes=globalopt | FileCheck %s
3 target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128"
5 @.str91250 = global [3 x i8] zeroinitializer
7 ; CHECK: @A = local_unnamed_addr global i64 4
8 @A = global i64 ptrtoint (ptr getelementptr (i32, ptr null, i64 1) to i64)
12 @xs = global [2 x i32] zeroinitializer, align 4
13 ; CHECK: @xs = local_unnamed_addr global [2 x i32] [i32 1, i32 1]
16 %PR12642.struct = type { i8 }
17 @PR12642.s = global <{}> zeroinitializer, align 1
18 @PR12642.p = constant ptr getelementptr (i8, ptr @PR12642.s, i64 1), align 8
20 define internal void @test1() {
23 %0 = load i32, ptr @xs, align 4
24 store i32 %0, ptr getelementptr inbounds ([2 x i32], ptr @xs, i64 0, i64 1)
30 %closure = type { i32 }
32 @f = internal global %closure zeroinitializer, align 4
33 @m = global i32 0, align 4
35 ; CHECK: @m = local_unnamed_addr global i32 13
37 define internal i32 @test2_helper(ptr %this, i32 %b) {
39 %0 = load i32, ptr %this, align 4
40 %add = add nsw i32 %0, %b
44 define internal void @test2() {
47 %call = call i32 @test2_helper(ptr @f, i32 9)
48 store i32 %call, ptr @m, align 4
54 @dllimportptr = global ptr null, align 4
55 ; CHECK: @dllimportptr = local_unnamed_addr global ptr null, align 4
56 @dllimportvar = external dllimport global i32
57 define internal void @test3() {
59 store ptr @dllimportvar, ptr @dllimportptr, align 4
63 @dllexportptr = global ptr null, align 4
64 ; CHECK: @dllexportptr = local_unnamed_addr global ptr @dllexportvar, align 4
65 @dllexportvar = dllexport global i32 0, align 4
66 ; CHECK: @dllexportvar = dllexport global i32 20, align 4
67 define internal void @test4() {
69 store i32 20, ptr @dllexportvar, align 4
70 store ptr @dllexportvar, ptr @dllexportptr, align 4
74 @threadlocalptr = global ptr null, align 4
75 ; CHECK: @threadlocalptr = local_unnamed_addr global ptr null, align 4
76 @threadlocalvar = external thread_local global i32
77 define internal void @test5() {
79 %p = call ptr @llvm.threadlocal.address(ptr @threadlocalvar)
80 store ptr %p, ptr @threadlocalptr, align 4
84 @test6_v1 = internal global { i32, i32 } { i32 42, i32 0 }, align 8
85 @test6_v2 = global i32 0, align 4
86 ; CHECK: @test6_v2 = local_unnamed_addr global i32 42, align 4
87 define internal void @test6() {
88 %load = load { i32, i32 }, ptr @test6_v1, align 8
89 %xv0 = extractvalue { i32, i32 } %load, 0
90 %iv = insertvalue { i32, i32 } %load, i32 %xv0, 1
91 %xv1 = extractvalue { i32, i32 } %iv, 1
92 store i32 %xv1, ptr @test6_v2, align 4
96 @llvm.global_ctors = appending constant
97 [6 x { i32, ptr, ptr }]
98 [{ i32, ptr, ptr } { i32 65535, ptr @test1, ptr null },
99 { i32, ptr, ptr } { i32 65535, ptr @test2, ptr null },
100 { i32, ptr, ptr } { i32 65535, ptr @test3, ptr null },
101 { i32, ptr, ptr } { i32 65535, ptr @test4, ptr null },
102 { i32, ptr, ptr } { i32 65535, ptr @test5, ptr null },
103 { i32, ptr, ptr } { i32 65535, ptr @test6, ptr null }]