diff options
author | Alon Zakai <azakai@google.com> | 2023-02-02 13:13:49 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-02-02 21:13:49 +0000 |
commit | d3f2df39c9e55ec25e4a2ac59804d6137679272d (patch) | |
tree | 5c993e649d691a634076ca5ae465d7cd9b7a5965 /test | |
parent | 91f54df07766a5884203aa1fcfd6b0d61a3eb142 (diff) | |
download | binaryen-d3f2df39c9e55ec25e4a2ac59804d6137679272d.tar.gz binaryen-d3f2df39c9e55ec25e4a2ac59804d6137679272d.tar.bz2 binaryen-d3f2df39c9e55ec25e4a2ac59804d6137679272d.zip |
[Wasm GC] Fix struct.set / ref.as_non_null ordering issue (#5474)
If traps can happen, then we can't always remove a trap on null
on the ref input to struct.set, since it has two children,
(struct.set
(ref.as_non_null X)
(call $foo))
Removing the ref.as would not prevent a trap, as the struct.set
will trap, but it does move the trap to after the call which is bad.
Diffstat (limited to 'test')
-rw-r--r-- | test/lit/passes/optimize-instructions-gc-tnh.wast | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/test/lit/passes/optimize-instructions-gc-tnh.wast b/test/lit/passes/optimize-instructions-gc-tnh.wast index 2307362ff..87795f31d 100644 --- a/test/lit/passes/optimize-instructions-gc-tnh.wast +++ b/test/lit/passes/optimize-instructions-gc-tnh.wast @@ -11,6 +11,10 @@ ;; NO_TNH: (type $void (func)) (type $void (func)) + ;; TNH: (import "a" "b" (func $import (result i32))) + ;; NO_TNH: (import "a" "b" (func $import (result i32))) + (import "a" "b" (func $import (result i32))) + ;; TNH: (func $ref.eq (type $eqref_eqref_=>_i32) (param $a eqref) (param $b eqref) (result i32) ;; TNH-NEXT: (ref.eq ;; TNH-NEXT: (local.get $a) @@ -603,6 +607,49 @@ ) ) + ;; TNH: (func $null.cast-other.effects (type $ref?|$struct|_=>_none) (param $x (ref null $struct)) + ;; TNH-NEXT: (struct.set $struct 0 + ;; TNH-NEXT: (local.get $x) + ;; TNH-NEXT: (call $import) + ;; TNH-NEXT: ) + ;; TNH-NEXT: (struct.set $struct 0 + ;; TNH-NEXT: (local.get $x) + ;; TNH-NEXT: (i32.const 10) + ;; TNH-NEXT: ) + ;; TNH-NEXT: ) + ;; NO_TNH: (func $null.cast-other.effects (type $ref?|$struct|_=>_none) (param $x (ref null $struct)) + ;; NO_TNH-NEXT: (struct.set $struct 0 + ;; NO_TNH-NEXT: (ref.as_non_null + ;; NO_TNH-NEXT: (local.get $x) + ;; NO_TNH-NEXT: ) + ;; NO_TNH-NEXT: (call $import) + ;; NO_TNH-NEXT: ) + ;; NO_TNH-NEXT: (struct.set $struct 0 + ;; NO_TNH-NEXT: (local.get $x) + ;; NO_TNH-NEXT: (i32.const 10) + ;; NO_TNH-NEXT: ) + ;; NO_TNH-NEXT: ) + (func $null.cast-other.effects (param $x (ref null $struct)) + (struct.set $struct 0 + ;; We cannot remove this ref.as_non_null, even though the struct.set will + ;; trap if the ref is null, because that would move the trap from before + ;; the call to the import to be after it. But in TNH we can assume it does + ;; not trap, and remove it. + (ref.as_non_null + (local.get $x) + ) + (call $import) + ) + (struct.set $struct 0 + ;; This one can be removed even without TNH, as there are no effects after + ;; it. + (ref.as_non_null + (local.get $x) + ) + (i32.const 10) + ) + ) + ;; Helper functions. ;; TNH: (func $get-i32 (type $none_=>_i32) (result i32) |