From 13ce3488333f70607411eb504ea2046fe2dc7c6d Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 4 Nov 2016 17:24:01 -0700 Subject: optimize booleans through i32.or --- src/passes/OptimizeInstructions.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 6ba34990f..1970cf08f 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -363,8 +363,12 @@ private: } } } else if (auto* binary = boolean->dynCast()) { - // x != 0 is just x if it's used as a bool - if (binary->op == NeInt32) { + if (binary->op == OrInt32) { + // an or flowing into a boolean context can consider each input as boolean + binary->left = optimizeBoolean(binary->left); + binary->right = optimizeBoolean(binary->right); + } else if (binary->op == NeInt32) { + // x != 0 is just x if it's used as a bool if (auto* num = binary->right->dynCast()) { if (num->value.geti32() == 0) { return binary->left; -- cgit v1.2.3