diff options
author | Thomas Lively <tlively123@gmail.com> | 2024-11-26 17:12:15 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-27 01:12:15 +0000 |
commit | 6f0f2e00521843118b63f41732dc2eb86d39fa09 (patch) | |
tree | 260d2be13758e3768955ee1f2c684102b6fea39a /test/wasm2js | |
parent | cd3805e31e8f2544d5e32aa505fc5e3abcf93df2 (diff) | |
download | binaryen-6f0f2e00521843118b63f41732dc2eb86d39fa09.tar.gz binaryen-6f0f2e00521843118b63f41732dc2eb86d39fa09.tar.bz2 binaryen-6f0f2e00521843118b63f41732dc2eb86d39fa09.zip |
Make more Ifs unreachable (#7094)
Previously the only Ifs that were typed unreachable were those in which
both arms were unreachable and those in which the condition was
unreachable that would have otherwise been typed none. This caused
problems in IRBuilder because Ifs with unreachable conditions and
value-returning arms would have concrete types, effectively hiding the
unreachable condition from the logic for dropping concretely typed
expressions preceding an unreachable expression when finishing a scope.
Relax the conditions under which an If can be typed unreachable so that
all Ifs with unreachable conditions or two unreachable arms are typed
unreachable. Propagating unreachability more eagerly this way makes
various optimizations of Ifs more powerful. It also requires new
handling for unreachable Ifs with concretely typed arms in the Printer
to ensure that printed wat remains valid.
Also update Unsubtyping, Flatten, and CodeFolding to account for the
newly unreachable Ifs.
Diffstat (limited to 'test/wasm2js')
-rw-r--r-- | test/wasm2js/br_table_temp.2asm.js | 2 | ||||
-rw-r--r-- | test/wasm2js/unreachable-if.2asm.js | 19 | ||||
-rw-r--r-- | test/wasm2js/unreachable-if.2asm.js.opt | 19 | ||||
-rw-r--r-- | test/wasm2js/unreachable-if.wast | 22 |
4 files changed, 61 insertions, 1 deletions
diff --git a/test/wasm2js/br_table_temp.2asm.js b/test/wasm2js/br_table_temp.2asm.js index 245792eaf..704ec0687 100644 --- a/test/wasm2js/br_table_temp.2asm.js +++ b/test/wasm2js/br_table_temp.2asm.js @@ -12671,7 +12671,7 @@ function asmFunc(imports) { } function $30() { - var $1_1 = 0, $2_1 = 0; + var $1_1 = 0; block : { $1_1 = 2; switch (0 | 0) { diff --git a/test/wasm2js/unreachable-if.2asm.js b/test/wasm2js/unreachable-if.2asm.js new file mode 100644 index 000000000..f5656223c --- /dev/null +++ b/test/wasm2js/unreachable-if.2asm.js @@ -0,0 +1,19 @@ + +function asmFunc(imports) { + var Math_imul = Math.imul; + var Math_fround = Math.fround; + var Math_abs = Math.abs; + var Math_clz32 = Math.clz32; + var Math_min = Math.min; + var Math_max = Math.max; + var Math_floor = Math.floor; + var Math_ceil = Math.ceil; + var Math_trunc = Math.trunc; + var Math_sqrt = Math.sqrt; + return { + + }; +} + +var retasmFunc = asmFunc({ +}); diff --git a/test/wasm2js/unreachable-if.2asm.js.opt b/test/wasm2js/unreachable-if.2asm.js.opt new file mode 100644 index 000000000..f5656223c --- /dev/null +++ b/test/wasm2js/unreachable-if.2asm.js.opt @@ -0,0 +1,19 @@ + +function asmFunc(imports) { + var Math_imul = Math.imul; + var Math_fround = Math.fround; + var Math_abs = Math.abs; + var Math_clz32 = Math.clz32; + var Math_min = Math.min; + var Math_max = Math.max; + var Math_floor = Math.floor; + var Math_ceil = Math.ceil; + var Math_trunc = Math.trunc; + var Math_sqrt = Math.sqrt; + return { + + }; +} + +var retasmFunc = asmFunc({ +}); diff --git a/test/wasm2js/unreachable-if.wast b/test/wasm2js/unreachable-if.wast new file mode 100644 index 000000000..5bc0257c0 --- /dev/null +++ b/test/wasm2js/unreachable-if.wast @@ -0,0 +1,22 @@ +;; Regression test for bad assertion in autodrop that did not expect the if to +;; be finalized to unreachable. +(module + (func $test (result i32) + (block $l (result i32) + (drop + (br_if $l + (if (result i32) + (unreachable) + (then + (i32.const 0) + ) + (else + (i32.const 0) + ) + ) + ) + (i32.const 0) + ) + ) + ) +) |