summaryrefslogtreecommitdiff
path: root/src/passes/CoalesceLocals.cpp
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2016-09-07 10:55:02 -0700
committerGitHub <noreply@github.com>2016-09-07 10:55:02 -0700
commit135a20cd110d356d5d098a08a7b447205adaed7a (patch)
treef5200a6b35f19d1bf95dea1fa7e339f40391413b /src/passes/CoalesceLocals.cpp
parentfbe77b167002e8a49225b607ca8c37dc7e4b41fe (diff)
parentdd197d3212ac28e778d372df9d03e58b21386648 (diff)
downloadbinaryen-135a20cd110d356d5d098a08a7b447205adaed7a.tar.gz
binaryen-135a20cd110d356d5d098a08a7b447205adaed7a.tar.bz2
binaryen-135a20cd110d356d5d098a08a7b447205adaed7a.zip
Merge pull request #678 from WebAssembly/stack
Stack machine + 0xc update
Diffstat (limited to 'src/passes/CoalesceLocals.cpp')
-rw-r--r--src/passes/CoalesceLocals.cpp12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/passes/CoalesceLocals.cpp b/src/passes/CoalesceLocals.cpp
index 2c707b614..2063a20db 100644
--- a/src/passes/CoalesceLocals.cpp
+++ b/src/passes/CoalesceLocals.cpp
@@ -485,9 +485,19 @@ void CoalesceLocals::applyIndices(std::vector<Index>& indices, Expression* root)
// in addition, we can optimize out redundant copies and ineffective sets
GetLocal* get;
if ((get = set->value->dynCast<GetLocal>()) && get->index == set->index) {
- *action.origin = get; // further optimizations may get rid of the get, if this is in a place where the output does not matter
+ if (set->isTee()) {
+ *action.origin = get;
+ } else {
+ ExpressionManipulator::nop(set);
+ }
} else if (!action.effective) {
*action.origin = set->value; // value may have no side effects, further optimizations can eliminate it
+ if (!set->isTee()) {
+ // we need to drop it
+ Drop* drop = ExpressionManipulator::convert<SetLocal, Drop>(set);
+ drop->value = *action.origin;
+ *action.origin = drop;
+ }
}
}
}