Optimize simple constant cases for bitwise &, | and ^.

For integer bitwise operations we can replace
x & -1 with x,  x | 0 with x and x ^ 0 with x.
Review URL: http://codereview.chromium.org/9177001

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10382 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent c92a3949
...@@ -788,6 +788,24 @@ HValue* HTypeof::Canonicalize() { ...@@ -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) { void HTypeof::PrintDataTo(StringStream* stream) {
value()->PrintNameTo(stream); value()->PrintNameTo(stream);
} }
......
...@@ -3151,6 +3151,8 @@ class HBitwise: public HBitwiseBinaryOperation { ...@@ -3151,6 +3151,8 @@ class HBitwise: public HBitwiseBinaryOperation {
virtual bool IsCommutative() const { return true; } virtual bool IsCommutative() const { return true; }
virtual HValue* Canonicalize();
static HInstruction* NewHBitwise(Zone* zone, static HInstruction* NewHBitwise(Zone* zone,
Token::Value op, Token::Value op,
HValue* context, HValue* context,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment