summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorHeejin Ahn <aheejin@gmail.com>2018-08-02 21:44:24 +0000
committerHeejin Ahn <aheejin@gmail.com>2018-08-02 21:44:24 +0000
commit4128cb0b6bbe921188247e8db1a0a9103f66e51f (patch)
tree1bb3f47161c5c9b1f0e14aff58801bcbca735263 /llvm/test
parent0faca0f09f43369ab7132f884d4f54873f54a168 (diff)
downloadbcm5719-llvm-4128cb0b6bbe921188247e8db1a0a9103f66e51f.tar.gz
bcm5719-llvm-4128cb0b6bbe921188247e8db1a0a9103f66e51f.zip
[WebAssembly] Support for atomic.wait / atomic.wake instructions
Summary: This adds support for atomic.wait / atomic.wake instructions in the wasm thread proposal. Reviewers: dschuff Subscribers: sbc100, jgravelle-google, sunfish, llvm-commits Differential Revision: https://reviews.llvm.org/D49395 llvm-svn: 338770
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/CodeGen/WebAssembly/offset-atomics.ll266
1 files changed, 266 insertions, 0 deletions
diff --git a/llvm/test/CodeGen/WebAssembly/offset-atomics.ll b/llvm/test/CodeGen/WebAssembly/offset-atomics.ll
index 92617c1f4b1..ed9aed01c9c 100644
--- a/llvm/test/CodeGen/WebAssembly/offset-atomics.ll
+++ b/llvm/test/CodeGen/WebAssembly/offset-atomics.ll
@@ -1525,3 +1525,269 @@ define i32 @cmpxchg_i8_i32_z_from_global_address(i32 %exp, i32 %new) {
%u = zext i8 %old to i32
ret i32 %u
}
+
+;===----------------------------------------------------------------------------
+; Waits: 32-bit
+;===----------------------------------------------------------------------------
+
+declare i32 @llvm.wasm.atomic.wait.i32(i32*, i32, i64)
+
+; Basic wait.
+
+; CHECK-LABEL: wait_i32_no_offset:
+; CHECK: i32.atomic.wait $push0=, 0($0), $1, $2{{$}}
+; CHECK-NEXT: return $pop0{{$}}
+define i32 @wait_i32_no_offset(i32* %p, i32 %exp, i64 %timeout) {
+ %v = call i32 @llvm.wasm.atomic.wait.i32(i32* %p, i32 %exp, i64 %timeout)
+ ret i32 %v
+}
+
+; With an nuw add, we can fold an offset.
+
+; CHECK-LABEL: wait_i32_with_folded_offset:
+; CHECK: i32.atomic.wait $push0=, 24($0), $1, $2{{$}}
+define i32 @wait_i32_with_folded_offset(i32* %p, i32 %exp, i64 %timeout) {
+ %q = ptrtoint i32* %p to i32
+ %r = add nuw i32 %q, 24
+ %s = inttoptr i32 %r to i32*
+ %t = call i32 @llvm.wasm.atomic.wait.i32(i32* %s, i32 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+; With an inbounds gep, we can fold an offset.
+
+; CHECK-LABEL: wait_i32_with_folded_gep_offset:
+; CHECK: i32.atomic.wait $push0=, 24($0), $1, $2{{$}}
+define i32 @wait_i32_with_folded_gep_offset(i32* %p, i32 %exp, i64 %timeout) {
+ %s = getelementptr inbounds i32, i32* %p, i32 6
+ %t = call i32 @llvm.wasm.atomic.wait.i32(i32* %s, i32 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+; We can't fold a negative offset though, even with an inbounds gep.
+
+; CHECK-LABEL: wait_i32_with_unfolded_gep_negative_offset:
+; CHECK: i32.const $push0=, -24{{$}}
+; CHECK: i32.add $push1=, $0, $pop0{{$}}
+; CHECK: i32.atomic.wait $push2=, 0($pop1), $1, $2{{$}}
+define i32 @wait_i32_with_unfolded_gep_negative_offset(i32* %p, i32 %exp, i64 %timeout) {
+ %s = getelementptr inbounds i32, i32* %p, i32 -6
+ %t = call i32 @llvm.wasm.atomic.wait.i32(i32* %s, i32 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+; Without nuw, and even with nsw, we can't fold an offset.
+
+; CHECK-LABEL: wait_i32_with_unfolded_offset:
+; CHECK: i32.const $push0=, 24{{$}}
+; CHECK: i32.add $push1=, $0, $pop0{{$}}
+; CHECK: i32.atomic.wait $push2=, 0($pop1), $1, $2{{$}}
+define i32 @wait_i32_with_unfolded_offset(i32* %p, i32 %exp, i64 %timeout) {
+ %q = ptrtoint i32* %p to i32
+ %r = add nsw i32 %q, 24
+ %s = inttoptr i32 %r to i32*
+ %t = call i32 @llvm.wasm.atomic.wait.i32(i32* %s, i32 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+; Without inbounds, we can't fold a gep offset.
+
+; CHECK-LABEL: wait_i32_with_unfolded_gep_offset:
+; CHECK: i32.const $push0=, 24{{$}}
+; CHECK: i32.add $push1=, $0, $pop0{{$}}
+; CHECK: i32.atomic.wait $push2=, 0($pop1), $1, $2{{$}}
+define i32 @wait_i32_with_unfolded_gep_offset(i32* %p, i32 %exp, i64 %timeout) {
+ %s = getelementptr i32, i32* %p, i32 6
+ %t = call i32 @llvm.wasm.atomic.wait.i32(i32* %s, i32 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+; When waiting from a fixed address, materialize a zero.
+
+; CHECK-LABEL: wait_i32_from_numeric_address
+; CHECK: i32.const $push0=, 0{{$}}
+; CHECK: i32.atomic.wait $push1=, 42($pop0), $0, $1{{$}}
+define i32 @wait_i32_from_numeric_address(i32 %exp, i64 %timeout) {
+ %s = inttoptr i32 42 to i32*
+ %t = call i32 @llvm.wasm.atomic.wait.i32(i32* %s, i32 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+; CHECK-LABEL: wait_i32_from_global_address
+; CHECK: i32.const $push0=, 0{{$}}
+; CHECK: i32.atomic.wait $push1=, gv($pop0), $0, $1{{$}}
+define i32 @wait_i32_from_global_address(i32 %exp, i64 %timeout) {
+ %t = call i32 @llvm.wasm.atomic.wait.i32(i32* @gv, i32 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+;===----------------------------------------------------------------------------
+; Waits: 64-bit
+;===----------------------------------------------------------------------------
+
+declare i32 @llvm.wasm.atomic.wait.i64(i64*, i64, i64)
+
+; Basic wait.
+
+; CHECK-LABEL: wait_i64_no_offset:
+; CHECK: i64.atomic.wait $push0=, 0($0), $1, $2{{$}}
+; CHECK-NEXT: return $pop0{{$}}
+define i32 @wait_i64_no_offset(i64* %p, i64 %exp, i64 %timeout) {
+ %v = call i32 @llvm.wasm.atomic.wait.i64(i64* %p, i64 %exp, i64 %timeout)
+ ret i32 %v
+}
+
+; With an nuw add, we can fold an offset.
+
+; CHECK-LABEL: wait_i64_with_folded_offset:
+; CHECK: i64.atomic.wait $push0=, 24($0), $1, $2{{$}}
+define i32 @wait_i64_with_folded_offset(i64* %p, i64 %exp, i64 %timeout) {
+ %q = ptrtoint i64* %p to i32
+ %r = add nuw i32 %q, 24
+ %s = inttoptr i32 %r to i64*
+ %t = call i32 @llvm.wasm.atomic.wait.i64(i64* %s, i64 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+; With an inbounds gep, we can fold an offset.
+
+; CHECK-LABEL: wait_i64_with_folded_gep_offset:
+; CHECK: i64.atomic.wait $push0=, 24($0), $1, $2{{$}}
+define i32 @wait_i64_with_folded_gep_offset(i64* %p, i64 %exp, i64 %timeout) {
+ %s = getelementptr inbounds i64, i64* %p, i32 3
+ %t = call i32 @llvm.wasm.atomic.wait.i64(i64* %s, i64 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+; We can't fold a negative offset though, even with an inbounds gep.
+
+; CHECK-LABEL: wait_i64_with_unfolded_gep_negative_offset:
+; CHECK: i32.const $push0=, -24{{$}}
+; CHECK: i32.add $push1=, $0, $pop0{{$}}
+; CHECK: i64.atomic.wait $push2=, 0($pop1), $1, $2{{$}}
+define i32 @wait_i64_with_unfolded_gep_negative_offset(i64* %p, i64 %exp, i64 %timeout) {
+ %s = getelementptr inbounds i64, i64* %p, i32 -3
+ %t = call i32 @llvm.wasm.atomic.wait.i64(i64* %s, i64 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+; Without nuw, and even with nsw, we can't fold an offset.
+
+; CHECK-LABEL: wait_i64_with_unfolded_offset:
+; CHECK: i32.const $push0=, 24{{$}}
+; CHECK: i32.add $push1=, $0, $pop0{{$}}
+; CHECK: i64.atomic.wait $push2=, 0($pop1), $1, $2{{$}}
+define i32 @wait_i64_with_unfolded_offset(i64* %p, i64 %exp, i64 %timeout) {
+ %q = ptrtoint i64* %p to i32
+ %r = add nsw i32 %q, 24
+ %s = inttoptr i32 %r to i64*
+ %t = call i32 @llvm.wasm.atomic.wait.i64(i64* %s, i64 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+; Without inbounds, we can't fold a gep offset.
+
+; CHECK-LABEL: wait_i64_with_unfolded_gep_offset:
+; CHECK: i32.const $push0=, 24{{$}}
+; CHECK: i32.add $push1=, $0, $pop0{{$}}
+; CHECK: i64.atomic.wait $push2=, 0($pop1), $1, $2{{$}}
+define i32 @wait_i64_with_unfolded_gep_offset(i64* %p, i64 %exp, i64 %timeout) {
+ %s = getelementptr i64, i64* %p, i32 3
+ %t = call i32 @llvm.wasm.atomic.wait.i64(i64* %s, i64 %exp, i64 %timeout)
+ ret i32 %t
+}
+
+;===----------------------------------------------------------------------------
+; Notifies
+;===----------------------------------------------------------------------------
+
+declare i64 @llvm.wasm.atomic.notify(i32*, i64)
+
+; Basic notify.
+
+; CHECK-LABEL: notify_no_offset:
+; CHECK: atomic.notify $push0=, 0($0), $1{{$}}
+; CHECK-NEXT: return $pop0{{$}}
+define i64 @notify_no_offset(i32* %p, i64 %notify_count) {
+ %v = call i64 @llvm.wasm.atomic.notify(i32* %p, i64 %notify_count)
+ ret i64 %v
+}
+
+; With an nuw add, we can fold an offset.
+
+; CHECK-LABEL: notify_with_folded_offset:
+; CHECK: atomic.notify $push0=, 24($0), $1{{$}}
+define i64 @notify_with_folded_offset(i32* %p, i64 %notify_count) {
+ %q = ptrtoint i32* %p to i32
+ %r = add nuw i32 %q, 24
+ %s = inttoptr i32 %r to i32*
+ %t = call i64 @llvm.wasm.atomic.notify(i32* %s, i64 %notify_count)
+ ret i64 %t
+}
+
+; With an inbounds gep, we can fold an offset.
+
+; CHECK-LABEL: notify_with_folded_gep_offset:
+; CHECK: atomic.notify $push0=, 24($0), $1{{$}}
+define i64 @notify_with_folded_gep_offset(i32* %p, i64 %notify_count) {
+ %s = getelementptr inbounds i32, i32* %p, i32 6
+ %t = call i64 @llvm.wasm.atomic.notify(i32* %s, i64 %notify_count)
+ ret i64 %t
+}
+
+; We can't fold a negative offset though, even with an inbounds gep.
+
+; CHECK-LABEL: notify_with_unfolded_gep_negative_offset:
+; CHECK: i32.const $push0=, -24{{$}}
+; CHECK: i32.add $push1=, $0, $pop0{{$}}
+; CHECK: atomic.notify $push2=, 0($pop1), $1{{$}}
+define i64 @notify_with_unfolded_gep_negative_offset(i32* %p, i64 %notify_count) {
+ %s = getelementptr inbounds i32, i32* %p, i32 -6
+ %t = call i64 @llvm.wasm.atomic.notify(i32* %s, i64 %notify_count)
+ ret i64 %t
+}
+
+; Without nuw, and even with nsw, we can't fold an offset.
+
+; CHECK-LABEL: notify_with_unfolded_offset:
+; CHECK: i32.const $push0=, 24{{$}}
+; CHECK: i32.add $push1=, $0, $pop0{{$}}
+; CHECK: atomic.notify $push2=, 0($pop1), $1{{$}}
+define i64 @notify_with_unfolded_offset(i32* %p, i64 %notify_count) {
+ %q = ptrtoint i32* %p to i32
+ %r = add nsw i32 %q, 24
+ %s = inttoptr i32 %r to i32*
+ %t = call i64 @llvm.wasm.atomic.notify(i32* %s, i64 %notify_count)
+ ret i64 %t
+}
+
+; Without inbounds, we can't fold a gep offset.
+
+; CHECK-LABEL: notify_with_unfolded_gep_offset:
+; CHECK: i32.const $push0=, 24{{$}}
+; CHECK: i32.add $push1=, $0, $pop0{{$}}
+; CHECK: atomic.notify $push2=, 0($pop1), $1{{$}}
+define i64 @notify_with_unfolded_gep_offset(i32* %p, i64 %notify_count) {
+ %s = getelementptr i32, i32* %p, i32 6
+ %t = call i64 @llvm.wasm.atomic.notify(i32* %s, i64 %notify_count)
+ ret i64 %t
+}
+
+; When notifying from a fixed address, materialize a zero.
+
+; CHECK-LABEL: notify_from_numeric_address
+; CHECK: i32.const $push0=, 0{{$}}
+; CHECK: atomic.notify $push1=, 42($pop0), $0{{$}}
+define i64 @notify_from_numeric_address(i64 %notify_count) {
+ %s = inttoptr i32 42 to i32*
+ %t = call i64 @llvm.wasm.atomic.notify(i32* %s, i64 %notify_count)
+ ret i64 %t
+}
+
+; CHECK-LABEL: notify_from_global_address
+; CHECK: i32.const $push0=, 0{{$}}
+; CHECK: atomic.notify $push1=, gv($pop0), $0{{$}}
+define i64 @notify_from_global_address(i64 %notify_count) {
+ %t = call i64 @llvm.wasm.atomic.notify(i32* @gv, i64 %notify_count)
+ ret i64 %t
+}
OpenPOWER on IntegriCloud