1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=-atomics | FileCheck %s
2 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+atomics | FileCheck %s
4 ; Test that globals assemble as expected.
6 target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
7 target triple = "wasm32-unknown-unknown"
10 ; CHECK-NOT: llvm.metadata
11 @llvm.used = appending global [1 x i32*] [i32* @g], section "llvm.metadata"
14 ; CHECK: i32.const $push0=, 0{{$}}
15 ; CHECK-NEXT: i32.load $push1=, answer($pop0){{$}}
16 ; CHECK-NEXT: return $pop1{{$}}
18 %a = load i32, i32* @answer
22 ; CHECK-LABEL: call_memcpy:
23 ; CHECK-NEXT: .functype call_memcpy (i32, i32, i32) -> (i32){{$}}
24 ; CHECK-NEXT: i32.call $push0=, memcpy, $0, $1, $2{{$}}
25 ; CHECK-NEXT: return $pop0{{$}}
26 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i1)
27 define i8* @call_memcpy(i8* %p, i8* nocapture readonly %q, i32 %n) {
28 tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %p, i8* %q, i32 %n, i1 false)
32 ; CHECK: .type .Lg,@object
33 ; CHECK: .p2align 2{{$}}
35 ; CHECK-NEXT: .int32 1337{{$}}
36 ; CHECK-NEXT: .size .Lg, 4{{$}}
37 @g = private global i32 1337
40 ; CHECK-NEXT: .skip 4{{$}}
41 ; CHECK-NEXT: .size ud, 4{{$}}
42 @ud = internal global i32 undef
44 ; CHECK: .type nil,@object
49 @nil = internal global i32 zeroinitializer
51 ; CHECK: .type z,@object
56 @z = internal global i32 0
58 ; CHECK: .type one,@object
59 ; CHECK: .p2align 2{{$}}
61 ; CHECK-NEXT: .int32 1{{$}}
62 ; CHECK-NEXT: .size one, 4{{$}}
63 @one = internal global i32 1
65 ; CHECK: .type answer,@object
66 ; CHECK: .p2align 2{{$}}
68 ; CHECK-NEXT: .int32 42{{$}}
69 ; CHECK-NEXT: .size answer, 4{{$}}
70 @answer = internal global i32 42
72 ; CHECK: .type u32max,@object
73 ; CHECK: .p2align 2{{$}}
75 ; CHECK-NEXT: .int32 4294967295{{$}}
76 ; CHECK-NEXT: .size u32max, 4{{$}}
77 @u32max = internal global i32 -1
79 ; CHECK: .type ud64,@object
80 ; CHECK: .p2align 3{{$}}
82 ; CHECK-NEXT: .skip 8{{$}}
83 ; CHECK-NEXT: .size ud64, 8{{$}}
84 @ud64 = internal global i64 undef
86 ; CHECK: .type nil64,@object
87 ; CHECK: .p2align 3{{$}}
89 ; CHECK-NEXT: .int64 0{{$}}
90 ; CHECK-NEXT: .size nil64, 8{{$}}
91 @nil64 = internal global i64 zeroinitializer
93 ; CHECK: .type z64,@object
94 ; CHECK: .p2align 3{{$}}
96 ; CHECK-NEXT: .int64 0{{$}}
97 ; CHECK-NEXT: .size z64, 8{{$}}
98 @z64 = internal global i64 0
100 ; CHECK: .type twoP32,@object
101 ; CHECK: .p2align 3{{$}}
102 ; CHECK-NEXT: twoP32:
103 ; CHECK-NEXT: .int64 4294967296{{$}}
104 ; CHECK-NEXT: .size twoP32, 8{{$}}
105 @twoP32 = internal global i64 4294967296
107 ; CHECK: .type u64max,@object
108 ; CHECK: .p2align 3{{$}}
109 ; CHECK-NEXT: u64max:
110 ; CHECK-NEXT: .int64 -1{{$}}
111 ; CHECK-NEXT: .size u64max, 8{{$}}
112 @u64max = internal global i64 -1
114 ; CHECK: .type f32ud,@object
115 ; CHECK: .p2align 2{{$}}
117 ; CHECK-NEXT: .skip 4{{$}}
118 ; CHECK-NEXT: .size f32ud, 4{{$}}
119 @f32ud = internal global float undef
121 ; CHECK: .type f32nil,@object
122 ; CHECK: .p2align 2{{$}}
123 ; CHECK-NEXT: f32nil:
124 ; CHECK-NEXT: .int32 0{{$}}
125 ; CHECK-NEXT: .size f32nil, 4{{$}}
126 @f32nil = internal global float zeroinitializer
128 ; CHECK: .type f32z,@object
129 ; CHECK: .p2align 2{{$}}
131 ; CHECK-NEXT: .int32 0{{$}}
132 ; CHECK-NEXT: .size f32z, 4{{$}}
133 @f32z = internal global float 0.0
135 ; CHECK: .type f32nz,@object
136 ; CHECK: .p2align 2{{$}}
138 ; CHECK: .int32 2147483648{{$}}
139 ; CHECK: .size f32nz, 4{{$}}
140 @f32nz = internal global float -0.0
142 ; CHECK: .type f32two,@object
143 ; CHECK: .p2align 2{{$}}
144 ; CHECK-NEXT: f32two:
145 ; CHECK-NEXT: .int32 1073741824{{$}}
146 ; CHECK-NEXT: .size f32two, 4{{$}}
147 @f32two = internal global float 2.0
149 ; CHECK: .type f64ud,@object
150 ; CHECK: .p2align 3{{$}}
152 ; CHECK-NEXT: .skip 8{{$}}
153 ; CHECK-NEXT: .size f64ud, 8{{$}}
154 @f64ud = internal global double undef
156 ; CHECK: .type f64nil,@object
157 ; CHECK: .p2align 3{{$}}
158 ; CHECK-NEXT: f64nil:
159 ; CHECK-NEXT: .int64 0{{$}}
160 ; CHECK-NEXT: .size f64nil, 8{{$}}
161 @f64nil = internal global double zeroinitializer
163 ; CHECK: .type f64z,@object
164 ; CHECK: .p2align 3{{$}}
166 ; CHECK-NEXT: .int64 0{{$}}
167 ; CHECK-NEXT: .size f64z, 8{{$}}
168 @f64z = internal global double 0.0
170 ; CHECK: .type f64nz,@object
171 ; CHECK: .p2align 3{{$}}
173 ; CHECK-NEXT: .int64 -9223372036854775808{{$}}
174 ; CHECK-NEXT: .size f64nz, 8{{$}}
175 @f64nz = internal global double -0.0
177 ; CHECK: .type f64two,@object
178 ; CHECK: .p2align 3{{$}}
179 ; CHECK-NEXT: f64two:
180 ; CHECK-NEXT: .int64 4611686018427387904{{$}}
181 ; CHECK-NEXT: .size f64two, 8{{$}}
182 @f64two = internal global double 2.0
184 ; Indexing into a global array produces a relocation.
185 ; CHECK: .type arr,@object
186 ; CHECK: .type ptr,@object
188 ; CHECK-NEXT: .int32 arr+80
189 ; CHECK-NEXT: .size ptr, 4
190 @arr = global [128 x i32] zeroinitializer, align 16
191 @ptr = global i32* getelementptr inbounds ([128 x i32], [128 x i32]* @arr, i32 0, i32 20), align 4
194 ; CHECK: .type rom,@object{{$}}
195 ; CHECK: .section .rodata.rom,""
196 ; CHECK: .globl rom{{$}}
197 ; CHECK: .p2align 4{{$}}
199 ; CHECK: .skip 512{{$}}
200 ; CHECK: .size rom, 512{{$}}
201 @rom = constant [128 x i32] zeroinitializer, align 16
203 ; CHECK: .type array,@object
205 ; CHECK-NEXT: .skip 8
206 ; CHECK-NEXT: .size array, 8
207 ; CHECK: .type pointer_to_array,@object
208 ; CHECK-NEXT: .section .rodata.pointer_to_array,""
209 ; CHECK-NEXT: .globl pointer_to_array
210 ; CHECK-NEXT: .p2align 2
211 ; CHECK-NEXT: pointer_to_array:
212 ; CHECK-NEXT: .int32 array+4
213 ; CHECK-NEXT: .size pointer_to_array, 4
214 @array = internal constant [8 x i8] zeroinitializer, align 1
215 @pointer_to_array = constant i8* getelementptr inbounds ([8 x i8], [8 x i8]* @array, i32 0, i32 4), align 4
217 ; Handle external objects with opaque type.
218 %struct.ASTRUCT = type opaque
219 @g_struct = external global %struct.ASTRUCT, align 1
220 define i32 @address_of_opaque() {
221 ret i32 ptrtoint (%struct.ASTRUCT* @g_struct to i32)