Reviewers: Sven Panne,

Message:
Here's the full-codegen based version I talked about.

Description:
Type feedback for Unary Plus

BUG=v8:2527


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

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

Affected files:
  M src/hydrogen-instructions.h
  M src/hydrogen-instructions.cc
  M src/hydrogen.cc
  M src/ia32/full-codegen-ia32.cc
  M src/type-info.h
  M src/type-info.cc


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


+HValue* HMul::Canonicalize() {
+  if (left()->IsInteger32Constant() &&
+      HConstant::cast(left())->Integer32Value() == 1 &&
+      right()->representation().IsSpecialization()) {
+    return right();
+  }
+  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/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 127d7a9aa1ed13943d558e7096ec35ca15ae3818..894a1cc26cd3f5c1021affd8e32ea12c659a423c 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -9222,12 +9222,18 @@ void HOptimizedGraphBuilder::VisitAdd(UnaryOperation* expr) {
   CHECK_ALIVE(VisitForValue(expr->expression()));
   HValue* value = Pop();
   HValue* context = environment()->LookupContext();
+  TypeInfo left_info, right_info, result_info;
+  oracle()->BinaryType(
+ expr->UnaryOperationFeedbackId(), &left_info, &right_info, &result_info);
+  // Left is constant 1.
+  ASSERT(left_info.IsSmi());
+  Representation left_rep = ToRepresentation(left_info);
+  Representation right_rep = ToRepresentation(right_info);
   HInstruction* instr =
-      HMul::New(zone(), context, value, graph()->GetConstant1());
+      HMul::New(zone(), context, graph()->GetConstant1(), value);
   if (instr->IsBinaryOperation()) {
-    // Since we don't have type feedback, we must be cautious/pessimistic.
     HBinaryOperation::cast(instr)->set_observed_input_representation(
-        Representation::Tagged(), Representation::Tagged());
+        left_rep, right_rep);
   }
   return ast_context()->ReturnInstruction(instr, expr->id());
 }
@@ -9618,8 +9624,9 @@ HInstruction* HOptimizedGraphBuilder::BuildBinaryOperation(
     HValue* left,
     HValue* right) {
   HValue* context = environment()->LookupContext();
-  TypeInfo left_info, right_info, result_info, combined_info;
-  oracle()->BinaryType(expr, &left_info, &right_info, &result_info);
+  TypeInfo left_info, right_info, result_info;
+  oracle()->BinaryType(
+ expr->BinaryOperationFeedbackId(), &left_info, &right_info, &result_info);
   Representation left_rep = ToRepresentation(left_info);
   Representation right_rep = ToRepresentation(right_info);
   Representation result_rep = ToRepresentation(result_info);
Index: src/ia32/full-codegen-ia32.cc
diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc
index 19989b1c626dd3ea85f6cb9c3c44d7bfab8dffa9..82b107f07fcb9bead38f739da75fc8f53d854885 100644
--- a/src/ia32/full-codegen-ia32.cc
+++ b/src/ia32/full-codegen-ia32.cc
@@ -3972,8 +3972,14 @@ void FullCodeGenerator::VisitUnaryOperation(UnaryOperation* expr) {
       VisitForAccumulatorValue(expr->expression());
       Label no_conversion;
       __ JumpIfSmi(result_register(), &no_conversion);
-      ToNumberStub convert_stub;
-      __ CallStub(&convert_stub);
+      __ mov(edx, Immediate(Smi::FromInt(1)));
+      OverwriteMode mode = expr->expression()->ResultOverwriteAllowed()
+          ? OVERWRITE_RIGHT : NO_OVERWRITE;
+      BinaryOpStub stub(Token::MUL, mode);
+ JumpPatchSite patch_site(masm_); // unbound, signals no inlined smi code.
+      CallIC(stub.GetCode(isolate()), RelocInfo::CODE_TARGET,
+             expr->UnaryOperationFeedbackId());
+      patch_site.EmitPatchInfo();
       __ bind(&no_conversion);
       context()->Plug(result_register());
       break;
Index: src/type-info.cc
diff --git a/src/type-info.cc b/src/type-info.cc
index 39a01f59e8d826c41f027133af064d8289a4ca55..2bdbd38d0922e4be10ed3b5a9c4e884e4fdf496e 100644
--- a/src/type-info.cc
+++ b/src/type-info.cc
@@ -458,11 +458,11 @@ static TypeInfo TypeFromBinaryOpType(BinaryOpIC::TypeInfo binary_type) {
 }


-void TypeFeedbackOracle::BinaryType(BinaryOperation* expr,
+void TypeFeedbackOracle::BinaryType(TypeFeedbackId type_feedback_id,
                                     TypeInfo* left,
                                     TypeInfo* right,
                                     TypeInfo* result) {
-  Handle<Object> object = GetInfo(expr->BinaryOperationFeedbackId());
+  Handle<Object> object = GetInfo(type_feedback_id);
   TypeInfo unknown = TypeInfo::Unknown();
   if (!object->IsCode()) {
     *left = *right = *result = unknown;
Index: src/type-info.h
diff --git a/src/type-info.h b/src/type-info.h
index 583c3fc52059badd4bbcae7f3bc7e57703053465..a0c945a7dfb067e44ded043e891b86329292b993 100644
--- a/src/type-info.h
+++ b/src/type-info.h
@@ -295,7 +295,7 @@ class TypeFeedbackOracle: public ZoneObject {

   // Get type information for arithmetic operations and compares.
   TypeInfo UnaryType(UnaryOperation* expr);
-  void BinaryType(BinaryOperation* expr,
+  void BinaryType(TypeFeedbackId type_feedback_id,
                   TypeInfo* left,
                   TypeInfo* right,
                   TypeInfo* result);


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