diff options
-rw-r--r-- | src/ir/effects.h | 5 | ||||
-rw-r--r-- | test/lit/passes/simplify-locals-gc.wast | 35 |
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) + ) +) |