From 57d0a549d715a25b471c8913c3013fc407eceea6 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sat, 5 Nov 2016 19:29:26 -0700 Subject: 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 --- src/passes/SimplifyLocals.cpp | 15 +++++++++------ src/passes/pass.cpp | 3 ++- 2 files changed, 11 insertions(+), 7 deletions(-) (limited to 'src') 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 @@ -169,7 +169,9 @@ struct SimplifyLocals : public WalkerPasscast(); 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 WalkerPassname.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 WalkerPassisTee()) 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() || set->value->is())) 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 -- cgit v1.2.3