From caf624d0b1b81cf93cfb66dfdb50f49c5cc51578 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 9 Oct 2020 19:51:22 -0700 Subject: RemoveUnusedBrs fuzz fix for switches with a single target and with a value (#3220) We turn a br_table with a single target into a br, but we reverse the order of the condition and the value when doing so, which we forgot to take into account. --- src/passes/RemoveUnusedBrs.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/passes/RemoveUnusedBrs.cpp b/src/passes/RemoveUnusedBrs.cpp index 2238e9e95..0a3374c4d 100644 --- a/src/passes/RemoveUnusedBrs.cpp +++ b/src/passes/RemoveUnusedBrs.cpp @@ -828,11 +828,18 @@ struct RemoveUnusedBrs : public WalkerPass> { void visitSwitch(Switch* curr) { if (BranchUtils::getUniqueTargets(curr).size() == 1) { - // This switch has just one target no matter what; replace with a br. - Builder builder(*getModule()); - replaceCurrent(builder.makeSequence( - builder.makeDrop(curr->condition), // might have side effects - builder.makeBreak(curr->default_, curr->value))); + // This switch has just one target no matter what; replace with a br + // if we can (to do so, we must put the condition before a possible + // value). + if (!curr->value || EffectAnalyzer::canReorder(passOptions, + getModule()->features, + curr->condition, + curr->value)) { + Builder builder(*getModule()); + replaceCurrent(builder.makeSequence( + builder.makeDrop(curr->condition), // might have side effects + builder.makeBreak(curr->default_, curr->value))); + } } } -- cgit v1.2.3