Reviewers: Jakob, Michael Starzinger,

Message:
Looks almost too easy. Is there a hidden problem with this approach?

Description:
Improve handling of unary plus.

Simple strategy: Transform unary plus into multiplication by one directly in the
parser and remove it from the Hydrogen graph later. This gives correct type
feedback without any special stub for it.

Please review this at https://codereview.chromium.org/13902013/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/hydrogen-instructions.h
  M src/hydrogen-instructions.cc
  M src/parser.cc


Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index 60a6912654fe50b3533a470a1df8a540d145b37d..6084dd787c337bfb9e487b3abb6cc7fdff3daff2 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -1436,6 +1436,22 @@ HValue* HSub::Canonicalize() {
 }


+HValue* HMul::Canonicalize() {
+  if (!representation().IsSpecialization()) return this;
+  if (left()->IsConstant() &&
+      HConstant::cast(left())->HasInteger32Value() &&
+      HConstant::cast(left())->Integer32Value() == 1) {
+    return right();
+  }
+  if (right()->IsConstant() &&
+      HConstant::cast(right())->HasInteger32Value() &&
+      HConstant::cast(right())->Integer32Value() == 1) {
+    return left();
+  }
+  return this;
+}
+
+
 HValue* HChange::Canonicalize() {
   return (from().Equals(to())) ? value() : this;
 }
Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index 6853dfe100e8cd5d35c9c6a60dc1032289fe2739..e74de4a1b1dc345398aff5b765de113fd865f78d 100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -4401,6 +4401,8 @@ class HMul: public HArithmeticBinaryOperation {

   virtual HValue* EnsureAndPropagateNotMinusZero(BitVector* visited);

+  virtual HValue* Canonicalize();
+
// Only commutative if it is certain that not two objects are multiplicated.
   virtual bool IsCommutative() const {
     return !representation().IsTagged();
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index b4ab623829b9657382ab58bcbe347ce4b31d3dff..8cbb748ba1a0b08a4f0d62edf7085c6ae6105952 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -3286,6 +3286,13 @@ Expression* Parser::ParseUnaryExpression(bool* ok) {
       }
     }

+    if (op == Token::ADD) {
+      return factory()->NewBinaryOperation(Token::MUL,
+                                           expression,
+                                           factory()->NewNumberLiteral(1),
+                                           position);
+    }
+
     return factory()->NewUnaryOperation(op, expression, position);

   } else if (Token::IsCountOp(op)) {


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to