diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-09-13 17:50:17 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-13 17:50:17 -0700 |
commit | da407c06333857f153f9fd1dba780dfbc64677bc (patch) | |
tree | 81de6f348b5f21831a608732bcb304618b9a188d /src | |
parent | 6cb6d65dd0c19dc5cba43d9367bcbdf691f80df3 (diff) | |
download | binaryen-da407c06333857f153f9fd1dba780dfbc64677bc.tar.gz binaryen-da407c06333857f153f9fd1dba780dfbc64677bc.tar.bz2 binaryen-da407c06333857f153f9fd1dba780dfbc64677bc.zip |
drop if-else arms as necessary
Diffstat (limited to 'src')
-rw-r--r-- | src/ast_utils.h | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/ast_utils.h b/src/ast_utils.h index f883d5f66..4664f22ae 100644 --- a/src/ast_utils.h +++ b/src/ast_utils.h @@ -881,9 +881,21 @@ struct AutoDrop : public WalkerPass<ExpressionStackWalker<AutoDrop, Visitor<Auto } void visitIf(If* curr) { - // if without else does not return a value, so the body must be dropped if it is concrete - if (!curr->ifFalse && isConcreteWasmType(curr->ifTrue->type)) { - curr->ifTrue = Builder(*getModule()).makeDrop(curr->ifTrue); + if (curr->ifFalse) { + if (!isConcreteWasmType(curr->type)) { + // if either side of an if-else not returning a value is concrete, drop it + if (isConcreteWasmType(curr->ifTrue->type)) { + curr->ifTrue = Builder(*getModule()).makeDrop(curr->ifTrue); + } + if (isConcreteWasmType(curr->ifFalse->type)) { + curr->ifFalse = Builder(*getModule()).makeDrop(curr->ifFalse); + } + } + } else { + // if without else does not return a value, so the body must be dropped if it is concrete + if (isConcreteWasmType(curr->ifTrue->type)) { + curr->ifTrue = Builder(*getModule()).makeDrop(curr->ifTrue); + } } } |