From 7077f78538be1364df24477fc713dfe480e63558 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Thu, 13 Oct 2016 12:22:50 -0700 Subject: when simplify-locals give br_if a value, the br_if also returns it, so it must be dropped --- src/passes/SimplifyLocals.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/passes/SimplifyLocals.cpp') diff --git a/src/passes/SimplifyLocals.cpp b/src/passes/SimplifyLocals.cpp index acc6860be..17206af89 100644 --- a/src/passes/SimplifyLocals.cpp +++ b/src/passes/SimplifyLocals.cpp @@ -93,7 +93,7 @@ struct SimplifyLocals : public WalkerPassunoptimizableBlocks.insert(br->name); } else { - self->blockBreaks[br->name].push_back({ br, std::move(self->sinkables) }); + self->blockBreaks[br->name].push_back({ currp, std::move(self->sinkables) }); } } else if (curr->is()) { return; // handled in visitBlock @@ -290,7 +290,7 @@ struct SimplifyLocals : public WalkerPassname]); blockBreaks.erase(block->name); if (breaks.size() == 0) return; // block has no branches TODO we might optimize trivial stuff here too - assert(!breaks[0].br->value); // block does not already have a return value (if one break has one, they all do) + assert(!(*breaks[0].brp)->cast()->value); // block does not already have a return value (if one break has one, they all do) // look for a set_local that is present in them all bool found = false; Index sharedIndex = -1; @@ -328,7 +328,8 @@ struct SimplifyLocals : public WalkerPasscast(); assert(!br->value); // if the break is conditional, then we must set the value here - if the break is not taken, we must still have the new value in the local auto* set = (*breakSetLocalPointer)->cast(); @@ -336,6 +337,9 @@ struct SimplifyLocals : public WalkerPassvalue = set; set->setTee(true); *breakSetLocalPointer = getModule()->allocator.alloc(); + // in addition, as this is a conditional br that now has a value, it now returns a value, so it must be dropped + br->finalize(); + *brp = Builder(*getModule()).makeDrop(br); } else { br->value = set->value; ExpressionManipulator::nop(set); -- cgit v1.2.3