Reviewers: Jakob,

Description:
Comparison in effect context lazy deopt fix.

[email protected]
BUG=

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

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

Affected files (+44, -32 lines):
  M src/hydrogen.h
  M src/hydrogen.cc
  A + test/mjsunit/regress/comparison-in-effect-context-deopt.js


Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index d3d7b5837a0c5e3d9a09ba4a58ce9486773818e8..0af75ce4ae60199623b75b5bcbbe441b4ea9b8d8 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -4375,7 +4375,7 @@ void HOptimizedGraphBuilder::VisitSwitchStatement(SwitchStatement* stmt) {
     HControlInstruction* compare = BuildCompareInstruction(
         Token::EQ_STRICT, tag_value, label_value, tag_type, label_type,
combined_type, stmt->tag()->position(), clause->label()->position(),
-        clause->id());
+        PUSH_BEFORE_SIMULATE, clause->id());

     HBasicBlock* next_test_block = graph()->CreateBasicBlock();
     HBasicBlock* body_block = graph()->CreateBasicBlock();
@@ -9527,9 +9527,13 @@ void HOptimizedGraphBuilder::VisitCompareOperation(CompareOperation* expr) {
     return ast_context()->ReturnInstruction(result, expr->id());
   }

+  PushBeforeSimulateBehavior push_behavior =
+    ast_context()->IsEffect() ? NO_PUSH_BEFORE_SIMULATE
+                              : PUSH_BEFORE_SIMULATE;
   HControlInstruction* compare = BuildCompareInstruction(
       op, left, right, left_type, right_type, combined_type,
-      expr->left()->position(), expr->right()->position(), expr->id());
+      expr->left()->position(), expr->right()->position(),
+      push_behavior, expr->id());
   if (compare == NULL) return;  // Bailed out.
   return ast_context()->ReturnControl(compare, expr->id());
 }
@@ -9544,6 +9548,7 @@ HControlInstruction* HOptimizedGraphBuilder::BuildCompareInstruction(
     Type* combined_type,
     int left_position,
     int right_position,
+    PushBeforeSimulateBehavior push_sim_result,
     BailoutId bailout_id) {
   // Cases handled below depend on collected type feedback. They should
   // soft deoptimize when there is no type feedback.
@@ -9608,9 +9613,14 @@ HControlInstruction* HOptimizedGraphBuilder::BuildCompareInstruction(
       result->set_observed_input_representation(1, left_rep);
       result->set_observed_input_representation(2, right_rep);
       if (result->HasObservableSideEffects()) {
-        Push(result);
-        AddSimulate(bailout_id, REMOVABLE_SIMULATE);
-        Drop(1);
+        if (push_sim_result == NO_PUSH_BEFORE_SIMULATE) {
+          AddSimulate(bailout_id, REMOVABLE_SIMULATE);
+        } else {
+          ASSERT(push_sim_result == PUSH_BEFORE_SIMULATE);
+          Push(result);
+          AddSimulate(bailout_id, REMOVABLE_SIMULATE);
+          Drop(1);
+        }
       }
       // TODO(jkummerow): Can we make this more efficient?
       HBranch* branch = New<HBranch>(result);
Index: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index 6a4320f2b1d459245ded72e59cc27ce9ab1322ae..d854c12a04d934423e732bfcefece4b93050e64a 100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -2417,23 +2417,27 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
   void HandleLiteralCompareNil(CompareOperation* expr,
                                Expression* sub_expr,
                                NilValue nil);
-  HControlInstruction* BuildCompareInstruction(Token::Value op,
-                                               HValue* left,
-                                               HValue* right,
-                                               Type* left_type,
-                                               Type* right_type,
-                                               Type* combined_type,
-                                               int left_position,
-                                               int right_position,
-                                               BailoutId bailout_id);
-
-  HInstruction* BuildStringCharCodeAt(HValue* string,
-                                      HValue* index);

   enum PushBeforeSimulateBehavior {
     PUSH_BEFORE_SIMULATE,
     NO_PUSH_BEFORE_SIMULATE
   };
+
+  HControlInstruction* BuildCompareInstruction(
+      Token::Value op,
+      HValue* left,
+      HValue* right,
+      Type* left_type,
+      Type* right_type,
+      Type* combined_type,
+      int left_position,
+      int right_position,
+      PushBeforeSimulateBehavior push_sim_result,
+      BailoutId bailout_id);
+
+  HInstruction* BuildStringCharCodeAt(HValue* string,
+                                      HValue* index);
+
   HValue* BuildBinaryOperation(
       BinaryOperation* expr,
       HValue* left,
Index: test/mjsunit/regress/comparison-in-effect-context-deopt.js
diff --git a/test/mjsunit/compiler/smi-stores-opt.js b/test/mjsunit/regress/comparison-in-effect-context-deopt.js
similarity index 86%
copy from test/mjsunit/compiler/smi-stores-opt.js
copy to test/mjsunit/regress/comparison-in-effect-context-deopt.js
index ca0923abc99501096d182bcdcd05f6f4020de9c9..b28dff73a745dfc7445a6c093380c56f51b3fb76 100644
--- a/test/mjsunit/compiler/smi-stores-opt.js
+++ b/test/mjsunit/regress/comparison-in-effect-context-deopt.js
@@ -27,23 +27,21 @@

 // Flags: --allow-natives-syntax

-var o = {a:1.5};
-o.a = 0;
-var a = o.a;
-
-function g() {
-  return 1;
+function lazyDeopt() {
+  %DeoptimizeFunction(test);
+  return "deopt";
 }

-var o2 = {a:{}};
+var x = { toString : lazyDeopt };
+
+function g(x) {
+  return "result";
+}

-function f() {
-  var result = {a: a};
-  var literal = {x:g()};
-  return [result, literal];
+function test(x) {
+  return g(void(x == ""));
 }

-f();
-f();
-%OptimizeFunctionOnNextCall(f);
-assertEquals(1, f()[1].x);
+test(x);
+%OptimizeFunctionOnNextCall(test);
+assertEquals("result", test(x));


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