1 ; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s -check-prefixes=NON-PIC,CHECK
3 target triple = "wasm32-unknown-emscripten"
5 @hidden_global = external hidden global i32
6 @hidden_global_array = external hidden global [10 x i32]
7 @external_global = external dso_local global i32
8 @external_global_array = external dso_local global [10 x i32]
12 ; For hidden symbols PIC code needs to offset all loads and stores
13 ; by the value of the __memory_base global
15 define i32 @load_hidden_global() {
16 ; CHECK-LABEL: load_hidden_global:
17 ; NON-PIC: i32.const $push0=, 0{{$}}
18 ; NON-PIC-NEXT: i32.load $push1=, hidden_global($pop0){{$}}
19 ; CHECK-NEXT: end_function
21 %1 = load i32, i32* @hidden_global
25 define i32 @load_hidden_global_offset() {
26 ; CHECK-LABEL: load_hidden_global_offset:
27 ; NON-PIC: i32.const $push0=, 0{{$}}
28 ; NON-PIC-NEXT:i32.load $push1=, hidden_global_array+20($pop0){{$}}
29 ; CHECK-NEXT: end_function
31 %1 = getelementptr [10 x i32], [10 x i32]* @hidden_global_array, i32 0, i32 5
32 %2 = load i32, i32* %1
36 ; Store to a hidden global
38 define void @store_hidden_global(i32 %n) {
39 ; CHECK-LABEL: store_hidden_global:
40 ; NON-PIC: i32.const $push0=, 0{{$}}
41 ; NON-PIC-NEXT: i32.store hidden_global($pop0), $0{{$}}
42 ; CHECK-NEXT: end_function
44 store i32 %n, i32* @hidden_global
48 define void @store_hidden_global_offset(i32 %n) {
49 ; CHECK-LABEL: store_hidden_global_offset:
50 ; NON-PIC: i32.const $push0=, 0{{$}}
51 ; NON-PIC-NEXT: i32.store hidden_global_array+20($pop0), $0{{$}}
52 ; CHECK-NEXT: end_function
54 %1 = getelementptr [10 x i32], [10 x i32]* @hidden_global_array, i32 0, i32 5
59 ; For non-hidden globals PIC code has to load the address from a wasm global
60 ; using the @GOT relocation type.
63 define i32 @load_external_global() {
64 ; CHECK-LABEL: load_external_global:
65 ; NON-PIC: i32.const $push0=, 0{{$}}
66 ; NON-PIC-NEXT: i32.load $push1=, external_global($pop0){{$}}
67 ; CHECK-NEXT: end_function
69 %1 = load i32, i32* @external_global
73 define i32 @load_external_global_offset() {
74 ; CHECK-LABEL: load_external_global_offset:
75 ; NON-PIC: i32.const $push[[L0:[0-9]+]]=, 0{{$}}
76 ; NON-PIC-NEXT: i32.load $push{{[0-9]+}}=, external_global_array+20($pop[[L0]]){{$}}
77 ; CHECK-NEXT: end_function
79 %1 = getelementptr [10 x i32], [10 x i32]* @external_global_array, i32 0, i32 5
80 %2 = load i32, i32* %1
84 ; Store to a non-hidden global via the wasm global.
86 define void @store_external_global(i32 %n) {
87 ; CHECK-LABEL: store_external_global:
88 ; NON-PIC: i32.const $push0=, 0{{$}}
89 ; NON-PIC-NEXT: i32.store external_global($pop0), $0{{$}}
90 ; CHECK-NEXT: end_function
92 store i32 %n, i32* @external_global
96 define void @store_external_global_offset(i32 %n) {
97 ; CHECK-LABEL: store_external_global_offset:
98 ; NON-PIC: i32.const $push0=, 0{{$}}
99 ; NON-PIC-NEXT: i32.store external_global_array+20($pop0), $0{{$}}
100 ; CHECK-NEXT: end_function
102 %1 = getelementptr [10 x i32], [10 x i32]* @external_global_array, i32 0, i32 5
103 store i32 %n, i32* %1