1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
2 ; RUN: opt -S -globalopt < %s | FileCheck %s
4 target datalayout = "p1:32:32"
6 @llvm.global_ctors = appending global [9 x { i32, ptr, ptr }] [
7 { i32, ptr, ptr } { i32 65535, ptr @ctor0, ptr null },
8 { i32, ptr, ptr } { i32 65535, ptr @ctor1, ptr null },
9 { i32, ptr, ptr } { i32 65535, ptr @ctor2, ptr null },
10 { i32, ptr, ptr } { i32 65535, ptr @ctor3, ptr null },
11 { i32, ptr, ptr } { i32 65535, ptr @ctor4, ptr null },
12 { i32, ptr, ptr } { i32 65535, ptr @ctor5, ptr null },
13 { i32, ptr, ptr } { i32 65535, ptr @ctor6, ptr null },
14 { i32, ptr, ptr } { i32 65535, ptr @ctor7, ptr null },
15 { i32, ptr, ptr } { i32 65535, ptr @ctor8, ptr null }
19 ; CHECK: @[[LLVM_GLOBAL_CTORS:[a-zA-Z0-9_$"\\.-]+]] = appending global [3 x { i32, ptr, ptr }] [{ i32, ptr, ptr } { i32 65535, ptr @ctor3, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @ctor4, ptr null }, { i32, ptr, ptr } { i32 65535, ptr @ctor7, ptr null }]
20 ; CHECK: @[[G0:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32 } zeroinitializer
21 ; CHECK: @[[G1:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32, i32 } { i32 0, i32 0, i32 1 }
22 ; CHECK: @[[G2:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32, i32 } { i32 1, i32 0, i32 0 }
23 ; CHECK: @[[G3:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32 } { i32 0, i32 1 }
24 ; CHECK: @[[G4:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32 } { i32 0, i32 undef }
25 ; CHECK: @[[G5:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i16, i32 } { i16 0, i32 1 }
26 ; CHECK: @[[G6:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32 } { i32 -1, i32 -1 }
27 ; CHECK: @[[G7:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr global { i32, i32 } { i32 -1, i32 1 }
28 ; CHECK: @[[G8:[a-zA-Z0-9_$"\\.-]+]] = local_unnamed_addr addrspace(1) global { i32, i32 } zeroinitializer
31 ; memset of all-zero global
32 @g0 = global { i32, i32 } zeroinitializer
33 define internal void @ctor0() {
34 call void @llvm.memset.p0.i64(ptr @g0, i8 0, i64 8, i1 false)
38 ; memset of zero prefix
39 @g1 = global { i32, i32, i32 } { i32 0, i32 0, i32 1 }
41 define internal void @ctor1() {
42 call void @llvm.memset.p0.i64(ptr @g1, i8 0, i64 8, i1 false)
46 ; memset of zero suffix
47 @g2 = global { i32, i32, i32 } { i32 1, i32 0, i32 0 }
49 define internal void @ctor2() {
50 call void @llvm.memset.p0.i64(ptr getelementptr (i32, ptr @g2, i64 1), i8 0, i64 8, i1 false)
54 ; memset of some non-zero bytes
55 @g3 = global { i32, i32 } { i32 0, i32 1 }
57 define internal void @ctor3() {
58 ; CHECK-LABEL: @ctor3(
59 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr @g3, i8 0, i64 8, i1 false)
60 ; CHECK-NEXT: ret void
62 call void @llvm.memset.p0.i64(ptr @g3, i8 0, i64 8, i1 false)
66 ; memset of some undef bytes
67 @g4 = global { i32, i32 } { i32 0, i32 undef }
69 define internal void @ctor4() {
70 ; CHECK-LABEL: @ctor4(
71 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr @g4, i8 0, i64 8, i1 false)
72 ; CHECK-NEXT: ret void
74 call void @llvm.memset.p0.i64(ptr @g4, i8 0, i64 8, i1 false)
78 ; memset including padding bytes
79 ; FIXME: We still incorrectly optimize the memset away here, even though code
80 ; might access the padding.
81 @g5 = global { i16, i32 } { i16 0, i32 1 }
83 define internal void @ctor5() {
84 call void @llvm.memset.p0.i64(ptr @g5, i8 0, i64 4, i1 false)
88 ; memset of non-zero value (matching initializer)
89 @g6 = global { i32, i32 } { i32 -1, i32 -1 }
91 define internal void @ctor6() {
92 call void @llvm.memset.p0.i64(ptr @g6, i8 -1, i64 8, i1 false)
96 ; memset of non-zero value (not matching initializer)
97 @g7 = global { i32, i32 } { i32 -1, i32 1 }
99 define internal void @ctor7() {
100 ; CHECK-LABEL: @ctor7(
101 ; CHECK-NEXT: call void @llvm.memset.p0.i64(ptr @g7, i8 -1, i64 8, i1 false)
102 ; CHECK-NEXT: ret void
104 call void @llvm.memset.p0.i64(ptr @g7, i8 -1, i64 8, i1 false)
108 ; memset of zero value in differently-sized address space
109 @g8 = addrspace(1) global { i32, i32 } zeroinitializer
111 define internal void @ctor8() {
112 call void @llvm.memset.p0.i64(ptr addrspacecast (ptr addrspace(1) @g8 to ptr), i8 0, i64 8, i1 false)
116 declare void @llvm.memset.p0.i64(ptr, i8, i64, i1)
118 ; CHECK: attributes #[[ATTR0:[0-9]+]] = { argmemonly nocallback nofree nounwind willreturn writeonly }