From 323e0b489a2b26d144da440d8043189ebbf49db2 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Sun, 6 Aug 2017 11:19:03 -0700 Subject: handle merging blocks with items after an unreachable, that if merged would be invalid. stop on the unreachable, it is easier and better --- src/passes/MergeBlocks.cpp | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/passes/MergeBlocks.cpp b/src/passes/MergeBlocks.cpp index 3627a5b0e..1ef34117e 100644 --- a/src/passes/MergeBlocks.cpp +++ b/src/passes/MergeBlocks.cpp @@ -214,21 +214,18 @@ static void optimizeBlock(Block* curr, Module* module, PassOptions& passOptions) } if (!child) continue; if (child->name.is()) continue; // named blocks can have breaks to them (and certainly do, if we ran RemoveUnusedNames and RemoveUnusedBrs) - if (child->type == unreachable) { - // an unreachable block can have a concrete final element (which is never reached) - if (!child->list.empty()) { - if (isConcreteWasmType(child->list.back()->type)) { - // just remove it - child->list.pop_back(); - } - } - } ExpressionList merged(module->allocator); for (size_t j = 0; j < i; j++) { merged.push_back(curr->list[j]); } for (auto item : child->list) { merged.push_back(item); + if (item->type == unreachable) { + // we don't need anything else from the child, + // and it is always valid to end on an unreachable, + // so stop there (otherwise, we need to be careful) + break; + } } for (size_t j = i + 1; j < curr->list.size(); j++) { merged.push_back(curr->list[j]); -- cgit v1.2.3