Unify canonicalization of HAdd/HSub/HMul a bit.

HDiv/HMul are a slightly different story and will be handled in a separate CL.

Review URL: https://codereview.chromium.org/14296013

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@14322 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5a215129
...@@ -1422,21 +1422,14 @@ HValue* HBitNot::Canonicalize() { ...@@ -1422,21 +1422,14 @@ HValue* HBitNot::Canonicalize() {
} }
HValue* HAdd::Canonicalize() { HValue* HArithmeticBinaryOperation::Canonicalize() {
if (!representation().IsInteger32()) return this; if (representation().IsInteger32() && CheckUsesForFlag(kTruncatingToInt32)) {
if (CheckUsesForFlag(kTruncatingToInt32)) ClearFlag(kCanOverflow); ClearFlag(kCanOverflow);
return this; }
}
HValue* HSub::Canonicalize() {
if (!representation().IsInteger32()) return this;
if (CheckUsesForFlag(kTruncatingToInt32)) ClearFlag(kCanOverflow);
return this; return this;
} }
// TODO(svenpanne) Use this in other Canonicalize() functions.
static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) { static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) {
return arg1->representation().IsSpecialization() && return arg1->representation().IsSpecialization() &&
arg2->IsInteger32Constant() && arg2->IsInteger32Constant() &&
...@@ -1444,10 +1437,23 @@ static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) { ...@@ -1444,10 +1437,23 @@ static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) {
} }
HValue* HAdd::Canonicalize() {
if (IsIdentityOperation(left(), right(), 0)) return left();
if (IsIdentityOperation(right(), left(), 0)) return right();
return HArithmeticBinaryOperation::Canonicalize();
}
HValue* HSub::Canonicalize() {
if (IsIdentityOperation(left(), right(), 0)) return left();
return HArithmeticBinaryOperation::Canonicalize();
}
HValue* HMul::Canonicalize() { HValue* HMul::Canonicalize() {
if (IsIdentityOperation(left(), right(), 1)) return left(); if (IsIdentityOperation(left(), right(), 1)) return left();
if (IsIdentityOperation(right(), left(), 1)) return right(); if (IsIdentityOperation(right(), left(), 1)) return right();
return this; return HArithmeticBinaryOperation::Canonicalize();
} }
......
...@@ -3842,6 +3842,8 @@ class HArithmeticBinaryOperation: public HBinaryOperation { ...@@ -3842,6 +3842,8 @@ class HArithmeticBinaryOperation: public HBinaryOperation {
: representation(); : representation();
} }
virtual HValue* Canonicalize();
private: private:
virtual bool IsDeletable() const { return true; } virtual bool IsDeletable() const { return true; }
}; };
......
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