diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index 1ff7f16fdf..d98fb3b7f0 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -788,6 +788,24 @@ HValue* HTypeof::Canonicalize() { } +HValue* HBitwise::Canonicalize() { + if (!representation().IsInteger32()) return this; + // If x is an int32, then x & -1 == x, x | 0 == x and x ^ 0 == x. + int32_t nop_constant = (op() == Token::BIT_AND) ? -1 : 0; + if (left()->IsConstant() && + HConstant::cast(left())->HasInteger32Value() && + HConstant::cast(left())->Integer32Value() == nop_constant) { + return right(); + } + if (right()->IsConstant() && + HConstant::cast(right())->HasInteger32Value() && + HConstant::cast(right())->Integer32Value() == nop_constant) { + return left(); + } + return this; +} + + void HTypeof::PrintDataTo(StringStream* stream) { value()->PrintNameTo(stream); } diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index 25f63ea7f5..f177c95fa6 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -3151,6 +3151,8 @@ class HBitwise: public HBitwiseBinaryOperation { virtual bool IsCommutative() const { return true; } + virtual HValue* Canonicalize(); + static HInstruction* NewHBitwise(Zone* zone, Token::Value op, HValue* context,