From: svenpanne@chromium.org Date: Thu, 18 Apr 2013 09:24:29 +0000 (+0000) Subject: Unify canonicalization of HAdd/HSub/HMul a bit. X-Git-Tag: upstream/4.7.83~14536 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=55324693aa456bf9a5b61791e0acc0ef8eef32fa;p=platform%2Fupstream%2Fv8.git 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 --- diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc index 0aabfbc..71158ce 100644 --- a/src/hydrogen-instructions.cc +++ b/src/hydrogen-instructions.cc @@ -1422,21 +1422,14 @@ HValue* HBitNot::Canonicalize() { } -HValue* HAdd::Canonicalize() { - if (!representation().IsInteger32()) return this; - if (CheckUsesForFlag(kTruncatingToInt32)) ClearFlag(kCanOverflow); - return this; -} - - -HValue* HSub::Canonicalize() { - if (!representation().IsInteger32()) return this; - if (CheckUsesForFlag(kTruncatingToInt32)) ClearFlag(kCanOverflow); +HValue* HArithmeticBinaryOperation::Canonicalize() { + if (representation().IsInteger32() && CheckUsesForFlag(kTruncatingToInt32)) { + ClearFlag(kCanOverflow); + } return this; } -// TODO(svenpanne) Use this in other Canonicalize() functions. static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) { return arg1->representation().IsSpecialization() && arg2->IsInteger32Constant() && @@ -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() { if (IsIdentityOperation(left(), right(), 1)) return left(); if (IsIdentityOperation(right(), left(), 1)) return right(); - return this; + return HArithmeticBinaryOperation::Canonicalize(); } diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h index e74de4a..54f0672 100644 --- a/src/hydrogen-instructions.h +++ b/src/hydrogen-instructions.h @@ -3842,6 +3842,8 @@ class HArithmeticBinaryOperation: public HBinaryOperation { : representation(); } + virtual HValue* Canonicalize(); + private: virtual bool IsDeletable() const { return true; } };