[Crankshaft] Don't add an instruction twice for %_StringGetLength.
authorsvenpanne <svenpanne@chromium.org>
Mon, 30 Mar 2015 12:41:54 +0000 (05:41 -0700)
committerCommit bot <commit-bot@chromium.org>
Mon, 30 Mar 2015 12:42:10 +0000 (12:42 +0000)
Review URL: https://codereview.chromium.org/1042843002

Cr-Commit-Position: refs/heads/master@{#27521}

src/hydrogen.cc
src/hydrogen.h

index 121ea8e..35761f7 100644 (file)
@@ -6832,13 +6832,18 @@ HInstruction* HGraphBuilder::AddLoadStringInstanceType(HValue* string) {
 
 
 HInstruction* HGraphBuilder::AddLoadStringLength(HValue* string) {
+  return AddInstruction(BuildLoadStringLength(string));
+}
+
+
+HInstruction* HGraphBuilder::BuildLoadStringLength(HValue* string) {
   if (string->IsConstant()) {
     HConstant* c_string = HConstant::cast(string);
     if (c_string->HasStringValue()) {
-      return Add<HConstant>(c_string->StringValue()->length());
+      return New<HConstant>(c_string->StringValue()->length());
     }
   }
-  return Add<HLoadNamedField>(string, nullptr,
+  return New<HLoadNamedField>(string, nullptr,
                               HObjectAccess::ForStringLength());
 }
 
@@ -11871,7 +11876,7 @@ void HOptimizedGraphBuilder::GenerateStringGetLength(CallRuntime* call) {
   DCHECK(call->arguments()->length() == 1);
   CHECK_ALIVE(VisitForValue(call->arguments()->at(0)));
   HValue* string = Pop();
-  HInstruction* result = AddLoadStringLength(string);
+  HInstruction* result = BuildLoadStringLength(string);
   return ast_context()->ReturnInstruction(result, call->id());
 }
 
index 268976a..d4b33ac 100644 (file)
@@ -1418,6 +1418,7 @@ class HGraphBuilder {
 
   HInstruction* AddLoadStringInstanceType(HValue* string);
   HInstruction* AddLoadStringLength(HValue* string);
+  HInstruction* BuildLoadStringLength(HValue* string);
   HStoreNamedField* AddStoreMapConstant(HValue* object, Handle<Map> map) {
     return Add<HStoreNamedField>(object, HObjectAccess::ForMap(),
                                  Add<HConstant>(map));