Reviewers: mvstanton,

Message:
Hey Michael,
This is an obvious optimization for inline binary operations in crankshaft. PTAL
-- Benedikt

Description:
Don't generate useless string checks for string adds.

If we know that one side of a string add is definitely a string
(i.e. if it's a string constant), then we don't need to emit a
string check for the argument.

This adds a new BuildCheckString() method to the graph builder,
which does "the right thing".

TEST=mjsunit/string-add

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

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

Affected files (+19, -8 lines):
  M src/hydrogen.h
  M src/hydrogen.cc


Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 22da9477e53608ce1b4df08357bfce25960e2e53..b47bb956630b35dfdb9457c9c80934440e9d21f4 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -1273,6 +1273,20 @@ HValue* HGraphBuilder::BuildCheckMap(HValue* obj, Handle<Map> map) {
 }


+HValue* HGraphBuilder::BuildCheckString(
+    HValue* object, const char* failure_reason) {
+  if (!object->type().IsString()) {
+    ASSERT(!object->IsConstant() ||
+           !HConstant::cast(object)->HasStringValue());
+    IfBuilder if_isstring(this);
+    if_isstring.If<HIsStringAndBranch>(object);
+    if_isstring.Then();
+    if_isstring.ElseDeopt(failure_reason);
+  }
+  return object;
+}
+
+
HValue* HGraphBuilder::BuildWrapReceiver(HValue* object, HValue* function) {
   if (object->type().IsJSObject()) return object;
   return Add<HWrapReceiver>(object, function);
@@ -8631,18 +8645,14 @@ HInstruction* HGraphBuilder::BuildBinaryOperation(
       (left_type->Is(Type::String()) || right_type->Is(Type::String()))) {
     // Validate type feedback for left argument.
     if (left_type->Is(Type::String())) {
-      IfBuilder if_isstring(this);
-      if_isstring.If<HIsStringAndBranch>(left);
-      if_isstring.Then();
-      if_isstring.ElseDeopt("Expected string for LHS of binary operation");
+      left = BuildCheckString(
+          left, "Expected string for LHS of binary operation");
     }

     // Validate type feedback for right argument.
     if (right_type->Is(Type::String())) {
-      IfBuilder if_isstring(this);
-      if_isstring.If<HIsStringAndBranch>(right);
-      if_isstring.Then();
-      if_isstring.ElseDeopt("Expected string for RHS of binary operation");
+      right = BuildCheckString(
+          right, "Expected string for RHS of binary operation");
     }

     // Convert left argument as necessary.
Index: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index 9aa9489aa3f376701f73aa5dc775714ae7d405f1..723bb440537f7ac1f1612057c70212b9c1a2b5ed 100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -1256,6 +1256,7 @@ class HGraphBuilder {

   HValue* BuildCheckHeapObject(HValue* object);
   HValue* BuildCheckMap(HValue* obj, Handle<Map> map);
+  HValue* BuildCheckString(HValue* object, const char* failure_reason);
   HValue* BuildWrapReceiver(HValue* object, HValue* function);

   // Building common constructs


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