Unify canonicalization of HAdd/HSub/HMul a bit.
authorsvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 18 Apr 2013 09:24:29 +0000 (09:24 +0000)
committersvenpanne@chromium.org <svenpanne@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 18 Apr 2013 09:24:29 +0000 (09:24 +0000)
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

src/hydrogen-instructions.cc
src/hydrogen-instructions.h

index 0aabfbc..71158ce 100644 (file)
@@ -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();
 }
 
 
index e74de4a..54f0672 100644 (file)
@@ -3842,6 +3842,8 @@ class HArithmeticBinaryOperation: public HBinaryOperation {
         : representation();
   }
 
+  virtual HValue* Canonicalize();
+
  private:
   virtual bool IsDeletable() const { return true; }
 };