1 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mcpu=mvp -mattr=-atomics | FileCheck %s
2 ; RUN: llc < %s -asm-verbose=false -disable-wasm-fallthrough-return-opt -wasm-disable-explicit-locals -wasm-keep-registers -mcpu=mvp -mattr=+atomics | FileCheck %s
4 ; Test that globals assemble as expected.
6 target triple = "wasm32-unknown-unknown"
9 ; CHECK-NOT: llvm.metadata
10 @llvm.used = appending global [1 x i32*] [i32* @g], section "llvm.metadata"
13 ; CHECK: i32.const $push0=, 0{{$}}
14 ; CHECK-NEXT: i32.load $push1=, answer($pop0){{$}}
15 ; CHECK-NEXT: return $pop1{{$}}
17 %a = load i32, i32* @answer
21 ; CHECK-LABEL: call_memcpy:
22 ; CHECK-NEXT: .functype call_memcpy (i32, i32, i32) -> (i32){{$}}
23 ; CHECK-NEXT: call $push0=, memcpy, $0, $1, $2{{$}}
24 ; CHECK-NEXT: return $pop0{{$}}
25 declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture readonly, i32, i1)
26 define i8* @call_memcpy(i8* %p, i8* nocapture readonly %q, i32 %n) {
27 tail call void @llvm.memcpy.p0i8.p0i8.i32(i8* %p, i8* %q, i32 %n, i1 false)
31 ; CHECK: .type .Lg,@object
32 ; CHECK: .p2align 2, 0x0{{$}}
34 ; CHECK-NEXT: .int32 1337{{$}}
35 ; CHECK-NEXT: .size .Lg, 4{{$}}
36 @g = private global i32 1337
39 ; CHECK-NEXT: .skip 4{{$}}
40 ; CHECK-NEXT: .size ud, 4{{$}}
41 @ud = internal global i32 undef
43 ; CHECK: .type nil,@object
44 ; CHECK: .p2align 2, 0x0
48 @nil = internal global i32 zeroinitializer
50 ; CHECK: .type z,@object
51 ; CHECK: .p2align 2, 0x0
55 @z = internal global i32 0
57 ; CHECK: .type one,@object
58 ; CHECK: .p2align 2, 0x0{{$}}
60 ; CHECK-NEXT: .int32 1{{$}}
61 ; CHECK-NEXT: .size one, 4{{$}}
62 @one = internal global i32 1
64 ; CHECK: .type answer,@object
65 ; CHECK: .p2align 2, 0x0{{$}}
67 ; CHECK-NEXT: .int32 42{{$}}
68 ; CHECK-NEXT: .size answer, 4{{$}}
69 @answer = internal global i32 42
71 ; CHECK: .type u32max,@object
72 ; CHECK: .p2align 2, 0x0{{$}}
74 ; CHECK-NEXT: .int32 4294967295{{$}}
75 ; CHECK-NEXT: .size u32max, 4{{$}}
76 @u32max = internal global i32 -1
78 ; CHECK: .type ud64,@object
79 ; CHECK: .p2align 3, 0x0{{$}}
81 ; CHECK-NEXT: .skip 8{{$}}
82 ; CHECK-NEXT: .size ud64, 8{{$}}
83 @ud64 = internal global i64 undef
85 ; CHECK: .type nil64,@object
86 ; CHECK: .p2align 3, 0x0{{$}}
88 ; CHECK-NEXT: .int64 0{{$}}
89 ; CHECK-NEXT: .size nil64, 8{{$}}
90 @nil64 = internal global i64 zeroinitializer
92 ; CHECK: .type z64,@object
93 ; CHECK: .p2align 3, 0x0{{$}}
95 ; CHECK-NEXT: .int64 0{{$}}
96 ; CHECK-NEXT: .size z64, 8{{$}}
97 @z64 = internal global i64 0
99 ; CHECK: .type twoP32,@object
100 ; CHECK: .p2align 3, 0x0{{$}}
101 ; CHECK-NEXT: twoP32:
102 ; CHECK-NEXT: .int64 4294967296{{$}}
103 ; CHECK-NEXT: .size twoP32, 8{{$}}
104 @twoP32 = internal global i64 4294967296
106 ; CHECK: .type u64max,@object
107 ; CHECK: .p2align 3, 0x0{{$}}
108 ; CHECK-NEXT: u64max:
109 ; CHECK-NEXT: .int64 -1{{$}}
110 ; CHECK-NEXT: .size u64max, 8{{$}}
111 @u64max = internal global i64 -1
113 ; CHECK: .type f32ud,@object
114 ; CHECK: .p2align 2, 0x0{{$}}
116 ; CHECK-NEXT: .skip 4{{$}}
117 ; CHECK-NEXT: .size f32ud, 4{{$}}
118 @f32ud = internal global float undef
120 ; CHECK: .type f32nil,@object
121 ; CHECK: .p2align 2, 0x0{{$}}
122 ; CHECK-NEXT: f32nil:
123 ; CHECK-NEXT: .int32 0x00000000{{$}}
124 ; CHECK-NEXT: .size f32nil, 4{{$}}
125 @f32nil = internal global float zeroinitializer
127 ; CHECK: .type f32z,@object
128 ; CHECK: .p2align 2, 0x0{{$}}
130 ; CHECK-NEXT: .int32 0x00000000{{$}}
131 ; CHECK-NEXT: .size f32z, 4{{$}}
132 @f32z = internal global float 0.0
134 ; CHECK: .type f32nz,@object
135 ; CHECK: .p2align 2, 0x0{{$}}
137 ; CHECK: .int32 0x80000000{{$}}
138 ; CHECK: .size f32nz, 4{{$}}
139 @f32nz = internal global float -0.0
141 ; CHECK: .type f32two,@object
142 ; CHECK: .p2align 2, 0x0{{$}}
143 ; CHECK-NEXT: f32two:
144 ; CHECK-NEXT: .int32 0x40000000{{$}}
145 ; CHECK-NEXT: .size f32two, 4{{$}}
146 @f32two = internal global float 2.0
148 ; CHECK: .type f64ud,@object
149 ; CHECK: .p2align 3, 0x0{{$}}
151 ; CHECK-NEXT: .skip 8{{$}}
152 ; CHECK-NEXT: .size f64ud, 8{{$}}
153 @f64ud = internal global double undef
155 ; CHECK: .type f64nil,@object
156 ; CHECK: .p2align 3, 0x0{{$}}
157 ; CHECK-NEXT: f64nil:
158 ; CHECK-NEXT: .int64 0x0000000000000000{{$}}
159 ; CHECK-NEXT: .size f64nil, 8{{$}}
160 @f64nil = internal global double zeroinitializer
162 ; CHECK: .type f64z,@object
163 ; CHECK: .p2align 3, 0x0{{$}}
165 ; CHECK-NEXT: .int64 0x0000000000000000{{$}}
166 ; CHECK-NEXT: .size f64z, 8{{$}}
167 @f64z = internal global double 0.0
169 ; CHECK: .type f64nz,@object
170 ; CHECK: .p2align 3, 0x0{{$}}
172 ; CHECK-NEXT: .int64 0x8000000000000000{{$}}
173 ; CHECK-NEXT: .size f64nz, 8{{$}}
174 @f64nz = internal global double -0.0
176 ; CHECK: .type f64two,@object
177 ; CHECK: .p2align 3, 0x0{{$}}
178 ; CHECK-NEXT: f64two:
179 ; CHECK-NEXT: .int64 0x4000000000000000{{$}}
180 ; CHECK-NEXT: .size f64two, 8{{$}}
181 @f64two = internal global double 2.0
183 ; Indexing into a global array produces a relocation.
184 ; CHECK: .type arr,@object
185 ; CHECK: .type ptr,@object
187 ; CHECK-NEXT: .int32 arr+80
188 ; CHECK-NEXT: .size ptr, 4
189 @arr = global [128 x i32] zeroinitializer, align 16
190 @ptr = global i32* getelementptr inbounds ([128 x i32], [128 x i32]* @arr, i32 0, i32 20), align 4
193 ; CHECK: .type rom,@object{{$}}
194 ; CHECK: .section .rodata.rom,""
195 ; CHECK: .globl rom{{$}}
196 ; CHECK: .p2align 4, 0x0{{$}}
198 ; CHECK: .skip 512{{$}}
199 ; CHECK: .size rom, 512{{$}}
200 @rom = constant [128 x i32] zeroinitializer, align 16
202 ; CHECK: .type array,@object
204 ; CHECK-NEXT: .skip 8
205 ; CHECK-NEXT: .size array, 8
206 ; CHECK: .type pointer_to_array,@object
207 ; CHECK-NEXT: .section .rodata.pointer_to_array,""
208 ; CHECK-NEXT: .globl pointer_to_array
209 ; CHECK-NEXT: .p2align 2, 0x0
210 ; CHECK-NEXT: pointer_to_array:
211 ; CHECK-NEXT: .int32 array+4
212 ; CHECK-NEXT: .size pointer_to_array, 4
213 @array = internal constant [8 x i8] zeroinitializer, align 1
214 @pointer_to_array = constant i8* getelementptr inbounds ([8 x i8], [8 x i8]* @array, i32 0, i32 4), align 4
216 ; Handle external objects with opaque type.
217 %struct.ASTRUCT = type opaque
218 @g_struct = external global %struct.ASTRUCT, align 1
219 define i32 @address_of_opaque() {
220 ret i32 ptrtoint (%struct.ASTRUCT* @g_struct to i32)