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
This commit is contained in:
fschneider@chromium.org 2012-01-11 10:01:59 +00:00
parent c92a3949ea
commit befd149ef8
2 changed files with 20 additions and 0 deletions

View File

@ -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);
}

View File

@ -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,