From ded69c16a2b3f27dd9b12b184d7045596d2a21d0 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Tue, 25 Oct 2016 17:03:10 -0700 Subject: Optimize out bool & 1 (#804) * asm.js corrections to unit.asm.js test * optimize out bool&1 --- src/passes/OptimizeInstructions.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/passes/OptimizeInstructions.cpp') diff --git a/src/passes/OptimizeInstructions.cpp b/src/passes/OptimizeInstructions.cpp index 7f1483371..a5c665458 100644 --- a/src/passes/OptimizeInstructions.cpp +++ b/src/passes/OptimizeInstructions.cpp @@ -25,6 +25,7 @@ #include #include #include +#include namespace wasm { @@ -197,6 +198,12 @@ struct OptimizeInstructions : public WalkerPassdynCast()) { + if (Properties::isSymmetric(binary)) { + // canonicalize a const to the second position + if (binary->left->is() && !binary->right->is()) { + std::swap(binary->left, binary->right); + } + } // pattern match a load of 8 bits and a sign extend using a shl of 24 then shr_s of 24 as well, etc. if (binary->op == BinaryOp::ShrSInt32 && binary->right->is()) { auto shifts = binary->right->cast()->value.geti32(); @@ -238,6 +245,9 @@ struct OptimizeInstructions : public WalkerPasssigned_ = false; return load; } + } else if (mask == 1 && Properties::emitsBoolean(binary->left)) { + // (bool) & 1 does not need the outer mask + return binary->left; } } } -- cgit v1.2.3