diff options
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 2 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.txt | 11 | ||||
-rw-r--r-- | test/passes/remove-unused-brs.wast | 10 |
3 files changed, 23 insertions, 0 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 8994c7fe2..f0db1eee6 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -31,6 +31,8 @@ namespace wasm { // condition and possible value, and the possible value must // not have side effects (as they would run unconditionally) static bool canTurnIfIntoBrIf(Expression* ifCondition, Expression* brValue, PassOptions& options) { + // if the if isn't even taken, this is all dead code anyhow + if (ifCondition->type == unreachable) return false; if (!brValue) return true; EffectAnalyzer value(options, brValue); if (value.hasSideEffects()) return false; diff --git a/test/passes/remove-unused-brs.txt b/test/passes/remove-unused-brs.txt index fe0c59fca..5cc900abd 100644 --- a/test/passes/remove-unused-brs.txt +++ b/test/passes/remove-unused-brs.txt @@ -6,6 +6,7 @@ (type $4 (func (param i32 i32))) (type $5 (func (param f32 i32 f32 i32 i32 f64 f32) (result i32))) (type $6 (func (param i32) (result i64))) + (type $7 (func (result i64))) (memory $0 256 256) (func $b0-yes (type $0) (param $i1 i32) (block $topmost @@ -1059,4 +1060,14 @@ ) ) ) + (func $unreachable-if-that-could-be-a-br_if (type $7) (result i64) + (loop $label$3 + (if + (unreachable) + (f64.const 1) + (br $label$3) + ) + (i64.const 1) + ) + ) ) diff --git a/test/passes/remove-unused-brs.wast b/test/passes/remove-unused-brs.wast index 996b05264..ecf70b758 100644 --- a/test/passes/remove-unused-brs.wast +++ b/test/passes/remove-unused-brs.wast @@ -943,5 +943,15 @@ ) ) ) + (func $unreachable-if-that-could-be-a-br_if (result i64) + (loop $label$3 + (if + (unreachable) + (f64.const 1) + (br $label$3) + ) + (i64.const 1) + ) + ) ) |