diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/RemoveUnusedBrs.cpp | 16 | ||||
-rw-r--r-- | src/passes/pass.cpp | 3 |
2 files changed, 6 insertions, 13 deletions
diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 434b8a4bd..785b1c92e 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -122,6 +122,8 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { } else if (curr->is<Nop>()) { // ignore (could be result of a previous cycle) self->valueCanFlow = false; + } else if (curr->is<Loop>()) { + // do nothing - it's ok for values to flow out } else { // anything else stops the flow flows.clear(); @@ -323,10 +325,7 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { // map of all value-less breaks going to a block (and not a loop) std::map<Block*, std::vector<Break*>> breaksToBlock; - // number of definitions of each name - when a name is defined more than once, it is not trivially safe to do this - std::map<Name, Index> numDefs; - - // the names to update, when we can (just one def) + // the names to update std::map<Break*, Name> newNames; void visitBreak(Break* curr) { @@ -338,8 +337,6 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { } // TODO: Switch? void visitBlock(Block* curr) { - if (curr->name.is()) numDefs[curr->name]++; - auto& list = curr->list; if (list.size() == 1 && curr->name.is()) { // if this block has just one child, a sub-block, then jumps to the former are jumps to us, really @@ -372,17 +369,12 @@ struct RemoveUnusedBrs : public WalkerPass<PostWalker<RemoveUnusedBrs>> { } } } - void visitLoop(Loop* curr) { - if (curr->name.is()) numDefs[curr->name]++; - } void finish() { for (auto& iter : newNames) { auto* br = iter.first; auto name = iter.second; - if (numDefs[name] == 1) { - br->name = name; - } + br->name = name; } } }; diff --git a/src/passes/pass.cpp b/src/passes/pass.cpp index 50c8da46b..92ab694e0 100644 --- a/src/passes/pass.cpp +++ b/src/passes/pass.cpp @@ -135,8 +135,9 @@ void PassRunner::addDefaultFunctionOptimizationPasses() { add("simplify-locals"); add("vacuum"); // previous pass creates garbage add("reorder-locals"); + add("merge-blocks"); // makes remove-unused-brs more effective add("remove-unused-brs"); // coalesce-locals opens opportunities for optimizations - add("merge-blocks"); + add("merge-blocks"); // clean up remove-unused-brs new blocks add("optimize-instructions"); add("precompute"); if (options.shrinkLevel >= 2) { |