1; RUN: llc < %s -asm-verbose=false -relocation-model=pic -fast-isel -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+atomics,+sign-ext | FileCheck %s
2; RUN: llc < %s -asm-verbose=false -relocation-model=pic -fast-isel=false -wasm-disable-explicit-locals -wasm-keep-registers -mattr=+atomics,+sign-ext | FileCheck %s
3
4; Test that atomic operations in PIC mode.  Specifically we verify
5; that atomic operations on global address load addres via @GOT or
6; @MBREL relocations.
7
8target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
9target triple = "wasm32-unknown-emscripten"
10
11@external_global       = external        global i32
12@hidden_global         = external hidden global i32
13
14define i32 @rmw_add_external_global() {
15; CHECK-LABEL: rmw_add_external_global:
16; CHECK:         global.get $push[[L0:[0-9]+]]=, external_global@GOT{{$}}
17; CHECK-NEXT:    i32.const $push[[L1:[0-9]+]]=, 42{{$}}
18; CHECK-NEXT:    i32.atomic.rmw.add $push[[L2:[0-9]+]]=, 0($pop[[L0]]), $pop[[L1]]{{$}}
19; CHECK-NEXT:    end_function
20  %1 = atomicrmw add i32* @external_global, i32 42 seq_cst
21  ret i32 %1
22}
23
24define i32 @rmw_add_hidden_global() {
25; CHECK-LABEL: rmw_add_hidden_global:
26; CHECK:         global.get $push[[L0:[0-9]+]]=, __memory_base{{$}}
27; CHECK-NEXT:    i32.const $push[[L1:[0-9]+]]=, hidden_global@MBREL{{$}}
28; CHECK-NEXT:    i32.add $push[[L2:[0-9]+]]=, $pop[[L0]], $pop[[L1]]{{$}}
29; CHECK-NEXT:    i32.const $push[[L3:[0-9]+]]=, 42{{$}}
30; CHECK-NEXT:    i32.atomic.rmw.add $push[[L4:[0-9]+]]=, 0($pop[[L2]]), $pop[[L3]]{{$}}
31; CHECK-NEXT:    end_function
32  %1 = atomicrmw add i32* @hidden_global, i32 42 seq_cst
33  ret i32 %1
34}
35