When adding constant string with something unknown, assume it's a string.
authorishell <ishell@chromium.org>
Tue, 5 May 2015 12:47:04 +0000 (05:47 -0700)
committerCommit bot <commit-bot@chromium.org>
Tue, 5 May 2015 12:47:08 +0000 (12:47 +0000)
Review URL: https://codereview.chromium.org/1122823002

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

src/hydrogen.cc

index 15c83c6..6a6ac6c 100644 (file)
@@ -10664,15 +10664,30 @@ HValue* HGraphBuilder::BuildBinaryOperation(
     Maybe<int> fixed_right_arg,
     HAllocationMode allocation_mode,
     LanguageMode language_mode) {
+  bool maybe_string_add = false;
+  if (op == Token::ADD) {
+    // If we are adding constant string with something for which we don't have
+    // a feedback yet, assume that it's also going to be a string and don't
+    // generate deopt instructions.
+    if (!left_type->IsInhabited() && right->IsConstant() &&
+        HConstant::cast(right)->HasStringValue()) {
+      left_type = Type::String();
+    }
+
+    if (!right_type->IsInhabited() && left->IsConstant() &&
+        HConstant::cast(left)->HasStringValue()) {
+      right_type = Type::String();
+    }
+
+    maybe_string_add = (left_type->Maybe(Type::String()) ||
+                        left_type->Maybe(Type::Receiver()) ||
+                        right_type->Maybe(Type::String()) ||
+                        right_type->Maybe(Type::Receiver()));
+  }
+
   Representation left_rep = RepresentationFor(left_type);
   Representation right_rep = RepresentationFor(right_type);
 
-  bool maybe_string_add = op == Token::ADD &&
-                          (left_type->Maybe(Type::String()) ||
-                           left_type->Maybe(Type::Receiver()) ||
-                           right_type->Maybe(Type::String()) ||
-                           right_type->Maybe(Type::Receiver()));
-
   if (!left_type->IsInhabited()) {
     Add<HDeoptimize>(
         Deoptimizer::kInsufficientTypeFeedbackForLHSOfBinaryOperation,