summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <azakai@google.com>2021-03-30 12:31:03 -0700
committerGitHub <noreply@github.com>2021-03-30 12:31:03 -0700
commit2b62a65d7dcf91e1971048012a842f83e54761af (patch)
treee4ac1b000f7d681e0e5e062206791a4c0fc2ed61
parentcdac6b123b1231859dc0dfbcb88dfabe005855e3 (diff)
downloadbinaryen-2b62a65d7dcf91e1971048012a842f83e54761af.tar.gz
binaryen-2b62a65d7dcf91e1971048012a842f83e54761af.tar.bz2
binaryen-2b62a65d7dcf91e1971048012a842f83e54761af.zip
[Wasm GC] Heap reads/writes are reads/writes of global state (#3755)
We missed that in effects.h, with the result that sets could look like they had no side effects. Fixes #3754
-rw-r--r--src/ir/effects.h5
-rw-r--r--test/lit/passes/simplify-locals-gc.wast35
2 files changed, 38 insertions, 2 deletions
diff --git a/src/ir/effects.h b/src/ir/effects.h
index 268a7b4e0..444099fe9 100644
--- a/src/ir/effects.h
+++ b/src/ir/effects.h
@@ -123,10 +123,11 @@ public:
// Changes something in globally-stored state.
bool writesGlobalState() const {
- return globalsWritten.size() || writesMemory || isAtomic || calls;
+ return globalsWritten.size() || writesMemory || writesHeap || isAtomic ||
+ calls;
}
bool readsGlobalState() const {
- return globalsRead.size() || readsMemory || isAtomic || calls;
+ return globalsRead.size() || readsMemory || readsHeap || isAtomic || calls;
}
bool hasSideEffects() const {
diff --git a/test/lit/passes/simplify-locals-gc.wast b/test/lit/passes/simplify-locals-gc.wast
new file mode 100644
index 000000000..4308a25a1
--- /dev/null
+++ b/test/lit/passes/simplify-locals-gc.wast
@@ -0,0 +1,35 @@
+;; NOTE: Assertions have been generated by update_lit_checks.py and should not be edited.
+;; RUN: wasm-opt %s --simplify-locals -all -S -o - \
+;; RUN: | filecheck %s
+
+(module
+ (type $struct (struct (field (mut 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)
+ ;; CHECK-NEXT: (local.set $temp
+ ;; CHECK-NEXT: (struct.get $struct 0
+ ;; CHECK-NEXT: (local.get $x)
+ ;; 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 $no-reorder-past-write (param $x (ref $struct)) (result i32)
+ (local $temp i32)
+ (local.set $temp
+ (struct.get $struct 0
+ (local.get $x)
+ )
+ )
+ (struct.set $struct 0
+ (local.get $x)
+ (i32.const 42)
+ )
+ (local.get $temp)
+ )
+)