diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-13 10:41:14 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-13 10:50:48 -0700 |
commit | 39ed7c6477f24b06e7ec33d03a86d932aa9a6a5f (patch) | |
tree | 9ca557be1384415a732d3130b0e3fd6546af3437 | |
parent | b4a77cf9b0780248c1a62c4409899ee1e23573ef (diff) | |
download | binaryen-39ed7c6477f24b06e7ec33d03a86d932aa9a6a5f.tar.gz binaryen-39ed7c6477f24b06e7ec33d03a86d932aa9a6a5f.tar.bz2 binaryen-39ed7c6477f24b06e7ec33d03a86d932aa9a6a5f.zip |
update br type when turning it into a br_if in remove-unused-brs
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 3 | ||||
-rw-r--r-- | src/wasm.h | 2 | ||||
-rw-r--r-- | test/unit.asm.js | 17 | ||||
-rw-r--r-- | test/unit.fromasm | 17 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise | 17 | ||||
-rw-r--r-- | test/unit.fromasm.imprecise.no-opts | 28 | ||||
-rw-r--r-- | test/unit.fromasm.no-opts | 28 |
7 files changed, 112 insertions, 0 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 8b7611ec9..86a46374f 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -149,6 +149,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs, Visitor<R // if the br has a value, then if => br_if means we always execute the value, and also the order is value,condition vs condition,value if (canTurnIfIntoBrIf(curr->condition, br->value)) { br->condition = curr->condition; + br->finalize(); replaceCurrent(br); anotherCycle = true; } @@ -408,6 +409,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs, Visitor<R // we are an if-else where the ifTrue is a break without a condition, so we can do this list[i] = ifTrueBreak; ifTrueBreak->condition = iff->condition; + ifTrueBreak->finalize(); ExpressionManipulator::spliceIntoBlock(curr, i + 1, iff->ifFalse); continue; } @@ -416,6 +418,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs, Visitor<R if (ifFalseBreak && !ifFalseBreak->condition && canTurnIfIntoBrIf(iff->condition, ifFalseBreak->value)) { list[i] = ifFalseBreak; ifFalseBreak->condition = Builder(*getModule()).makeUnary(EqZInt32, iff->condition); + ifFalseBreak->finalize(); ExpressionManipulator::spliceIntoBlock(curr, i + 1, iff->ifTrue); continue; } diff --git a/src/wasm.h b/src/wasm.h index d6bdfe91f..ca3c8e5f5 100644 --- a/src/wasm.h +++ b/src/wasm.h @@ -1027,6 +1027,8 @@ public: void finalize() { if (condition) { type = none; + } else { + type = unreachable; } } }; diff --git a/test/unit.asm.js b/test/unit.asm.js index 5833d2fd8..0decc886c 100644 --- a/test/unit.asm.js +++ b/test/unit.asm.js @@ -540,6 +540,23 @@ function asm(global, env, buffer) { } } + function __Z12multi_varargiz($0) { + $0 = $0|0; + var $2 = 0, $$06$i4 = 0, $exitcond$i6 = 0, $12 = 0, $20 = 0; + if ($2) { + while(1) { + $12 = $$06$i4; + if ($exitcond$i6) { + break; + } else { + $$06$i4 = $20; + } + } + } else { + lb(1) | 0; // returns a value, and the while is unreachable + } + } + var FUNCTION_TABLE_a = [ z, big_negative, z, z ]; var FUNCTION_TABLE_b = [ w, w, importedDoubles, w ]; var FUNCTION_TABLE_c = [ z, cneg ]; diff --git a/test/unit.fromasm b/test/unit.fromasm index 77e5a9eb1..773cbbd9d 100644 --- a/test/unit.fromasm +++ b/test/unit.fromasm @@ -990,4 +990,21 @@ (br $while-in$1) ) ) + (func $__Z12multi_varargiz (param $0 i32) + (local $1 i32) + (local $2 i32) + (if + (get_local $1) + (loop $while-in$1 + (br_if $while-in$1 + (i32.eqz + (get_local $2) + ) + ) + ) + (call $lb + (i32.const 1) + ) + ) + ) ) diff --git a/test/unit.fromasm.imprecise b/test/unit.fromasm.imprecise index 35aa3e4f3..80e34dfb9 100644 --- a/test/unit.fromasm.imprecise +++ b/test/unit.fromasm.imprecise @@ -971,4 +971,21 @@ (br $while-in$1) ) ) + (func $__Z12multi_varargiz (param $0 i32) + (local $1 i32) + (local $2 i32) + (if + (get_local $1) + (loop $while-in$1 + (br_if $while-in$1 + (i32.eqz + (get_local $2) + ) + ) + ) + (call $lb + (i32.const 1) + ) + ) + ) ) diff --git a/test/unit.fromasm.imprecise.no-opts b/test/unit.fromasm.imprecise.no-opts index 7808b6cf2..3e532ef2a 100644 --- a/test/unit.fromasm.imprecise.no-opts +++ b/test/unit.fromasm.imprecise.no-opts @@ -1549,4 +1549,32 @@ ) ) ) + (func $__Z12multi_varargiz (param $$0 i32) + (local $$2 i32) + (local $$$06$i4 i32) + (local $$exitcond$i6 i32) + (local $$12 i32) + (local $$20 i32) + (if + (get_local $$2) + (loop $while-in$1 + (block $while-out$0 + (set_local $$12 + (get_local $$$06$i4) + ) + (if + (get_local $$exitcond$i6) + (br $while-out$0) + (set_local $$$06$i4 + (get_local $$20) + ) + ) + (br $while-in$1) + ) + ) + (call $lb + (i32.const 1) + ) + ) + ) ) diff --git a/test/unit.fromasm.no-opts b/test/unit.fromasm.no-opts index 22528323a..d2c1beec7 100644 --- a/test/unit.fromasm.no-opts +++ b/test/unit.fromasm.no-opts @@ -1555,4 +1555,32 @@ ) ) ) + (func $__Z12multi_varargiz (param $$0 i32) + (local $$2 i32) + (local $$$06$i4 i32) + (local $$exitcond$i6 i32) + (local $$12 i32) + (local $$20 i32) + (if + (get_local $$2) + (loop $while-in$1 + (block $while-out$0 + (set_local $$12 + (get_local $$$06$i4) + ) + (if + (get_local $$exitcond$i6) + (br $while-out$0) + (set_local $$$06$i4 + (get_local $$20) + ) + ) + (br $while-in$1) + ) + ) + (call $lb + (i32.const 1) + ) + ) + ) ) |