Revision: 17912
Author:   [email protected]
Date:     Wed Nov 20 11:53:09 2013 UTC
Log:      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
[email protected]

Review URL: https://codereview.chromium.org/78063002
http://code.google.com/p/v8/source/detail?r=17912

Modified:
 /branches/bleeding_edge/src/hydrogen.cc
 /branches/bleeding_edge/src/hydrogen.h

=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Tue Nov 19 16:41:07 2013 UTC
+++ /branches/bleeding_edge/src/hydrogen.cc     Wed Nov 20 11:53:09 2013 UTC
@@ -1271,6 +1271,20 @@
 HValue* HGraphBuilder::BuildCheckMap(HValue* obj, Handle<Map> map) {
   return Add<HCheckMaps>(obj, map, top_info());
 }
+
+
+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) {
@@ -8631,18 +8645,14 @@
       (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.
=======================================
--- /branches/bleeding_edge/src/hydrogen.h      Mon Nov 18 13:57:49 2013 UTC
+++ /branches/bleeding_edge/src/hydrogen.h      Wed Nov 20 11:53:09 2013 UTC
@@ -1256,6 +1256,7 @@

   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