1; RUN: llc < %s -asm-verbose=false -wasm-disable-explicit-locals -wasm-keep-registers | FileCheck %s -check-prefixes=NON-PIC,CHECK 2 3target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128" 4target triple = "wasm32-unknown-emscripten" 5 6@hidden_global = external hidden global i32 7@hidden_global_array = external hidden global [10 x i32] 8@external_global = external dso_local global i32 9@external_global_array = external dso_local global [10 x i32] 10 11declare i32 @foo(); 12 13; For hidden symbols PIC code needs to offset all loads and stores 14; by the value of the __memory_base global 15 16define i32 @load_hidden_global() { 17; CHECK-LABEL: load_hidden_global: 18; NON-PIC: i32.const $push0=, 0{{$}} 19; NON-PIC-NEXT: i32.load $push1=, hidden_global($pop0){{$}} 20; CHECK-NEXT: end_function 21 22 %1 = load i32, i32* @hidden_global 23 ret i32 %1 24} 25 26define i32 @load_hidden_global_offset() { 27; CHECK-LABEL: load_hidden_global_offset: 28; NON-PIC: i32.const $push0=, 0{{$}} 29; NON-PIC-NEXT:i32.load $push1=, hidden_global_array+20($pop0){{$}} 30; CHECK-NEXT: end_function 31 32 %1 = getelementptr [10 x i32], [10 x i32]* @hidden_global_array, i32 0, i32 5 33 %2 = load i32, i32* %1 34 ret i32 %2 35} 36 37; Store to a hidden global 38 39define void @store_hidden_global(i32 %n) { 40; CHECK-LABEL: store_hidden_global: 41; NON-PIC: i32.const $push0=, 0{{$}} 42; NON-PIC-NEXT: i32.store hidden_global($pop0), $0{{$}} 43; CHECK-NEXT: end_function 44 45 store i32 %n, i32* @hidden_global 46 ret void 47} 48 49define void @store_hidden_global_offset(i32 %n) { 50; CHECK-LABEL: store_hidden_global_offset: 51; NON-PIC: i32.const $push0=, 0{{$}} 52; NON-PIC-NEXT: i32.store hidden_global_array+20($pop0), $0{{$}} 53; CHECK-NEXT: end_function 54 55 %1 = getelementptr [10 x i32], [10 x i32]* @hidden_global_array, i32 0, i32 5 56 store i32 %n, i32* %1 57 ret void 58} 59 60; For non-hidden globals PIC code has to load the address from a wasm global 61; using the @GOT relocation type. 62 63 64define i32 @load_external_global() { 65; CHECK-LABEL: load_external_global: 66; NON-PIC: i32.const $push0=, 0{{$}} 67; NON-PIC-NEXT: i32.load $push1=, external_global($pop0){{$}} 68; CHECK-NEXT: end_function 69 70 %1 = load i32, i32* @external_global 71 ret i32 %1 72} 73 74define i32 @load_external_global_offset() { 75; CHECK-LABEL: load_external_global_offset: 76; NON-PIC: i32.const $push[[L0:[0-9]+]]=, 0{{$}} 77; NON-PIC-NEXT: i32.load $push{{[0-9]+}}=, external_global_array+20($pop[[L0]]){{$}} 78; CHECK-NEXT: end_function 79 80 %1 = getelementptr [10 x i32], [10 x i32]* @external_global_array, i32 0, i32 5 81 %2 = load i32, i32* %1 82 ret i32 %2 83} 84 85; Store to a non-hidden global via the wasm global. 86 87define void @store_external_global(i32 %n) { 88; CHECK-LABEL: store_external_global: 89; NON-PIC: i32.const $push0=, 0{{$}} 90; NON-PIC-NEXT: i32.store external_global($pop0), $0{{$}} 91; CHECK-NEXT: end_function 92 93 store i32 %n, i32* @external_global 94 ret void 95} 96 97define void @store_external_global_offset(i32 %n) { 98; CHECK-LABEL: store_external_global_offset: 99; NON-PIC: i32.const $push0=, 0{{$}} 100; NON-PIC-NEXT: i32.store external_global_array+20($pop0), $0{{$}} 101; CHECK-NEXT: end_function 102 103 %1 = getelementptr [10 x i32], [10 x i32]* @external_global_array, i32 0, i32 5 104 store i32 %n, i32* %1 105 ret void 106} 107