diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-08-23 15:55:11 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-09-07 09:55:07 -0700 |
commit | e073b8f59e7cddd3a86443444f00b0b1f48691f1 (patch) | |
tree | a78b1c0701b777e07bc13f39f79810a291a5b3a6 /src | |
parent | 323e32bc1ca73c92d81b7fe28fd54e62c2218801 (diff) | |
download | binaryen-e073b8f59e7cddd3a86443444f00b0b1f48691f1.tar.gz binaryen-e073b8f59e7cddd3a86443444f00b0b1f48691f1.tar.bz2 binaryen-e073b8f59e7cddd3a86443444f00b0b1f48691f1.zip |
sink a drop into a single if arm
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/Vacuum.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/passes/Vacuum.cpp b/src/passes/Vacuum.cpp index 89ef7359e..db42a994a 100644 --- a/src/passes/Vacuum.cpp +++ b/src/passes/Vacuum.cpp @@ -203,6 +203,25 @@ struct Vacuum : public WalkerPass<ExpressionStackWalker<Vacuum, Visitor<Vacuum>> // if the drop input has no side effects, it can be wiped out if (!EffectAnalyzer(curr->value).hasSideEffects()) { ExpressionManipulator::nop(curr); + return; + } + // sink a drop into an arm of an if-else if the other arm ends in an unreachable, as it if is a branch, this can make that branch optimizable and more vaccuming possible + auto* iff = curr->value->dynCast<If>(); + if (iff && iff->ifFalse && isConcreteWasmType(iff->type)) { + // reuse the drop in both cases + if (iff->ifTrue->type == unreachable) { + assert(isConcreteWasmType(iff->ifFalse->type)); + curr->value = iff->ifFalse; + iff->ifFalse = curr; + iff->type = none; + replaceCurrent(iff); + } else if (iff->ifFalse->type == unreachable) { + assert(isConcreteWasmType(iff->ifTrue->type)); + curr->value = iff->ifTrue; + iff->ifTrue = curr; + iff->type = none; + replaceCurrent(iff); + } } } |