diff options
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 2 | ||||
-rw-r--r-- | src/wasm-validator.h | 4 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.txt | 32 |
3 files changed, 21 insertions, 17 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 263cea655..59d3af6fc 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -189,7 +189,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs, Visitor<R // finally, we may have simplified ifs enough to turn them into selects struct Selectifier : public WalkerPass<PostWalker<Selectifier, Visitor<Selectifier>>> { void visitIf(If* curr) { - if (curr->ifFalse) { + if (curr->ifFalse && isConcreteWasmType(curr->ifTrue->type) && isConcreteWasmType(curr->ifFalse->type)) { // if with else, consider turning it into a select if there is no control flow // TODO: estimate cost EffectAnalyzer condition(curr->condition); diff --git a/src/wasm-validator.h b/src/wasm-validator.h index 5844dafcd..8e989c94d 100644 --- a/src/wasm-validator.h +++ b/src/wasm-validator.h @@ -280,6 +280,10 @@ public: default: abort(); } } + void visitSelect(Select* curr) { + shouldBeUnequal(curr->ifTrue->type, none, curr, "select left must be valid"); + shouldBeUnequal(curr->ifFalse->type, none, curr, "select right must be valid"); + } void visitReturn(Return* curr) { if (curr->value) { diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index de6dc4779..1c5c8e713 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -117,7 +117,8 @@ ) (func $b12-yes (type $1) (block $topmost - (select + (if + (i32.const 1) (block $block1 (drop (i32.const 12) @@ -138,7 +139,6 @@ ) ) ) - (i32.const 1) ) ) ) @@ -221,42 +221,42 @@ ) (func $b17 (type $1) (block $a - (select + (if + (i32.const 0) (block $block1 ) (block $block3 ) - (i32.const 0) ) ) (block $a - (select + (if + (i32.const 0) (drop (i32.const 1) ) (block $block6 ) - (i32.const 0) ) ) (block $a - (select + (if + (i32.const 0) (block $block8 ) (drop (i32.const 1) ) - (i32.const 0) ) ) (block $c (block $b - (select + (if + (i32.const 0) (block $block11 ) (block $block13 ) - (i32.const 0) ) ) ) @@ -272,11 +272,11 @@ ) (func $ret-3 (type $1) (block $block0 - (select + (if + (i32.const 0) (nop) (block $block3 ) - (i32.const 0) ) ) ) @@ -340,7 +340,10 @@ (i32.const 1) ) ) - (select + (if + (block $a + (i32.const 0) + ) (block $a (block $block11 (drop @@ -355,9 +358,6 @@ ) ) ) - (block $a - (i32.const 0) - ) ) ) ) |