summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-10-13 12:14:49 -0700
committerGitHub <noreply@github.com>2021-10-13 19:14:49 +0000
commit7126a43e9e1cea50d3534b50d4554f4a18cd6e14 (patch)
tree8267b7f52cc914463bafc892b7c3f97554f10fc8 /test
parent31af332f2a1627ae2bd9232baf5837366a481cfe (diff)
downloadbinaryen-7126a43e9e1cea50d3534b50d4554f4a18cd6e14.tar.gz
binaryen-7126a43e9e1cea50d3534b50d4554f4a18cd6e14.tar.bz2
binaryen-7126a43e9e1cea50d3534b50d4554f4a18cd6e14.zip
[Wasm GC] Take advantage of immutable struct fields in effects.h (#4240)
This is the easy part of using immutability more: Just note immutable fields as such when we read from them, and then a write to a struct does not interfere with such reads. That is, only a read from a mutable field can notice the effect of a write.
Diffstat (limited to 'test')
-rw-r--r--test/example/cpp-unit.cpp3
-rw-r--r--test/lit/passes/simplify-locals-gc.wast61
2 files changed, 63 insertions, 1 deletions
diff --git a/test/example/cpp-unit.cpp b/test/example/cpp-unit.cpp
index 961013bc3..7c32478c6 100644
--- a/test/example/cpp-unit.cpp
+++ b/test/example/cpp-unit.cpp
@@ -611,7 +611,8 @@ void test_effects() {
assert_equal(effects.trap, true);
assert_equal(effects.readsArray, true);
assert_equal(effects.writesArray, true);
- assert_equal(effects.readsStruct, false);
+ assert_equal(effects.readsMutableStruct, false);
+ assert_equal(effects.readsImmutableStruct, false);
assert_equal(effects.writesStruct, false);
}
}
diff --git a/test/lit/passes/simplify-locals-gc.wast b/test/lit/passes/simplify-locals-gc.wast
index 912c3a688..97891aca4 100644
--- a/test/lit/passes/simplify-locals-gc.wast
+++ b/test/lit/passes/simplify-locals-gc.wast
@@ -8,6 +8,9 @@
;; CHECK: (type $struct (struct (field (mut i32))))
(type $struct (struct (field (mut i32))))
+ ;; CHECK: (type $struct-immutable (struct (field i32)))
+ (type $struct-immutable (struct (field i32)))
+
;; Writes to heap objects cannot be reordered with reads.
;; CHECK: (func $no-reorder-past-write (param $x (ref $struct)) (result i32)
;; CHECK-NEXT: (local $temp i32)
@@ -36,6 +39,64 @@
(local.get $temp)
)
+ ;; CHECK: (func $reorder-past-write-if-immutable (param $x (ref $struct)) (param $y (ref $struct-immutable)) (result i32)
+ ;; CHECK-NEXT: (local $temp i32)
+ ;; CHECK-NEXT: (nop)
+ ;; CHECK-NEXT: (struct.set $struct 0
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: (i32.const 42)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (struct.get $struct-immutable 0
+ ;; CHECK-NEXT: (local.get $y)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ (func $reorder-past-write-if-immutable (param $x (ref $struct)) (param $y (ref $struct-immutable)) (result i32)
+ (local $temp i32)
+ (local.set $temp
+ (struct.get $struct-immutable 0
+ (local.get $y)
+ )
+ )
+ (struct.set $struct 0
+ (local.get $x)
+ (i32.const 42)
+ )
+ (local.get $temp)
+ )
+
+ ;; CHECK: (func $unreachable-struct.get (param $x (ref $struct)) (param $y (ref $struct-immutable)) (result i32)
+ ;; CHECK-NEXT: (local $temp i32)
+ ;; CHECK-NEXT: (local.tee $temp
+ ;; CHECK-NEXT: (block ;; (replaces something unreachable we can't emit)
+ ;; CHECK-NEXT: (drop
+ ;; CHECK-NEXT: (unreachable)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (struct.set $struct 0
+ ;; CHECK-NEXT: (local.get $x)
+ ;; CHECK-NEXT: (i32.const 42)
+ ;; CHECK-NEXT: )
+ ;; CHECK-NEXT: (local.get $temp)
+ ;; CHECK-NEXT: )
+ (func $unreachable-struct.get (param $x (ref $struct)) (param $y (ref $struct-immutable)) (result i32)
+ (local $temp i32)
+ ;; As above, but the get's ref is unreachable. This tests we do not hit an
+ ;; assertion on the get's type not having a heap type (as we depend on
+ ;; finding the heap type there in the reachable case).
+ ;; We simply do not handle this case, leaving it for DCE.
+ (local.set $temp
+ (struct.get $struct-immutable 0
+ (unreachable)
+ )
+ )
+ (struct.set $struct 0
+ (local.get $x)
+ (i32.const 42)
+ )
+ (local.get $temp)
+ )
+
;; CHECK: (func $no-block-values-if-br_on
;; CHECK-NEXT: (local $temp anyref)
;; CHECK-NEXT: (block $block