diff options
author | Alon Zakai <alonzakai@gmail.com> | 2016-11-05 19:29:26 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2016-11-06 10:13:12 -0800 |
commit | 57d0a549d715a25b471c8913c3013fc407eceea6 (patch) | |
tree | 4984374220181ca61044bd7d8849aaec2084c1ec /src | |
parent | 5447c53b612c8d0f0d0902efe5053f2f81bd1595 (diff) | |
download | binaryen-57d0a549d715a25b471c8913c3013fc407eceea6.tar.gz binaryen-57d0a549d715a25b471c8913c3013fc407eceea6.tar.bz2 binaryen-57d0a549d715a25b471c8913c3013fc407eceea6.zip |
improve local simplication: simplify without if/block structure values before coalesce, so that coalesce can remove all copies, then do another pass of full simplification after it
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/SimplifyLocals.cpp | 15 | ||||
-rw-r--r-- | src/passes/pass.cpp | 3 |
2 files changed, 11 insertions, 7 deletions
diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp index 852fbc0cd..6509c9da5 100644 --- a/src/passes/SimplifyLocals.cpp +++ b/src/passes/SimplifyLocals.cpp @@ -36,9 +36,9 @@ // // * Tee: allow teeing, i.e., sinking a local with more than one use, // and so after sinking we have a tee for the first use. -// * Structure: allow sinking of locals whose value is a control flow -// structure, an if or a block (and the value is thus the -// return value of the if/block). +// * Structure: create block and if return values, by merging the +// internal set_locals into one on the outside, +// that can itself then be sunk further. // #include <wasm.h> @@ -169,7 +169,9 @@ struct SimplifyLocals : public WalkerPass<LinearExecutionWalker<SimplifyLocals, // mere with the ifTrue side and optimize a return value, if possible auto* iff = (*currp)->cast<If>(); assert(iff->ifFalse); - self->optimizeIfReturn(iff, currp, self->ifStack.back()); + if (self->allowStructure) { + self->optimizeIfReturn(iff, currp, self->ifStack.back()); + } self->ifStack.pop_back(); self->sinkables.clear(); } @@ -177,7 +179,9 @@ struct SimplifyLocals : public WalkerPass<LinearExecutionWalker<SimplifyLocals, void visitBlock(Block* curr) { bool hasBreaks = curr->name.is() && blockBreaks[curr->name].size() > 0; - optimizeBlockReturn(curr); // can modify blockBreaks + if (allowStructure) { + optimizeBlockReturn(curr); // can modify blockBreaks + } // post-block cleanups if (curr->name.is()) { @@ -289,7 +293,6 @@ struct SimplifyLocals : public WalkerPass<LinearExecutionWalker<SimplifyLocals, if (set->isTee()) return false; // if in the first cycle, or not allowing tees, then we cannot sink if >1 use as that would make a tee if ((firstCycle || !allowTee) && getCounter.num[set->index] > 1) return false; - if (!allowStructure && (set->value->is<If>() || set->value->is<Block>())) return false; return true; } diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 4dc21ace0..20e002f4b 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -116,11 +116,12 @@ void PassRunner::addDefaultFunctionOptimizationPasses() { if (options.optimizeLevel >= 2 || options.shrinkLevel >= 2) { add("code-pushing"); } - add("simplify-locals"); + add("simplify-locals-nostructure"); // don't create if/block return values yet, as coalesce can remove copies that that could inhibit add("vacuum"); // previous pass creates garbage add("reorder-locals"); add("remove-unused-brs"); // simplify-locals opens opportunities for optimizations add("coalesce-locals"); + add("simplify-locals"); add("vacuum"); // previous pass creates garbage add("reorder-locals"); add("remove-unused-brs"); // coalesce-locals opens opportunities for optimizations |