Revision: 13704
Author:   [email protected]
Date:     Thu Feb 21 03:29:51 2013
Log:      Avoid creating unnecessary branches in Hydrogen

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

Modified:
 /branches/bleeding_edge/src/hydrogen-instructions.cc
 /branches/bleeding_edge/src/hydrogen.cc

=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Thu Feb 21 02:22:31 2013 +++ /branches/bleeding_edge/src/hydrogen-instructions.cc Thu Feb 21 03:29:51 2013
@@ -2784,11 +2784,9 @@


#define H_CONSTANT_INT32(val) \ -new(zone) HConstant(FACTORY->NewNumberFromInt(val, TENURED), \
-                    Representation::Integer32())
+new(zone) HConstant(val, Representation::Integer32())
#define H_CONSTANT_DOUBLE(val) \ -new(zone) HConstant(FACTORY->NewNumber(val, TENURED), \
-                    Representation::Double())
+new(zone) HConstant(val, Representation::Double())

#define DEFINE_NEW_H_SIMPLE_ARITHMETIC_INSTR(HInstr, op) \ HInstruction* HInstr::New##HInstr(Zone* zone, \
@@ -2933,7 +2931,8 @@
         return H_CONSTANT_DOUBLE(
             static_cast<double>(static_cast<uint32_t>(left_val)));
       }
- return H_CONSTANT_INT32(static_cast<uint32_t>(left_val) >> right_val);
+      return H_CONSTANT_INT32(static_cast<int32_t>(
+          static_cast<uint32_t>(left_val) >> right_val));
     }
   }
   return new(zone) HShr(context, left, right);
=======================================
--- /branches/bleeding_edge/src/hydrogen.cc     Thu Feb 21 01:09:01 2013
+++ /branches/bleeding_edge/src/hydrogen.cc     Thu Feb 21 03:29:51 2013
@@ -3620,6 +3620,16 @@
   if (value != NULL && value->CheckFlag(HValue::kIsArguments)) {
     builder->Bailout("arguments object value in a test context");
   }
+  if (value->IsConstant()) {
+    HConstant* constant_value = HConstant::cast(value);
+    if (constant_value->ToBoolean()) {
+      builder->current_block()->Goto(if_true(), builder->function_state());
+    } else {
+ builder->current_block()->Goto(if_false(), builder->function_state());
+    }
+    builder->set_current_block(NULL);
+    return;
+  }
   HBasicBlock* empty_true = builder->graph()->CreateBasicBlock();
   HBasicBlock* empty_false = builder->graph()->CreateBasicBlock();
   TypeFeedbackId test_id = condition()->test_id();
@@ -3627,8 +3637,8 @@
HBranch* test = new(zone()) HBranch(value, empty_true, empty_false, expected);
   builder->current_block()->Finish(test);

-  empty_true->Goto(if_true(), owner()->function_state());
-  empty_false->Goto(if_false(), owner()->function_state());
+  empty_true->Goto(if_true(), builder->function_state());
+  empty_false->Goto(if_false(), builder->function_state());
   builder->set_current_block(NULL);
 }

@@ -9037,6 +9047,17 @@
   } else if (ast_context()->IsValue()) {
     CHECK_ALIVE(VisitForValue(expr->left()));
     ASSERT(current_block() != NULL);
+    HValue* left_value = Top();
+
+    if (left_value->IsConstant()) {
+      HConstant* left_constant = HConstant::cast(left_value);
+      if ((is_logical_and && left_constant->ToBoolean()) ||
+          (!is_logical_and && !left_constant->ToBoolean())) {
+        Drop(1);  // left_value.
+        CHECK_BAILOUT(VisitForValue(expr->right()));
+      }
+      return ast_context()->ReturnValue(Pop());
+    }

     // We need an extra block to maintain edge-split form.
     HBasicBlock* empty_block = graph()->CreateBasicBlock();
@@ -9044,8 +9065,8 @@
     TypeFeedbackId test_id = expr->left()->test_id();
     ToBooleanStub::Types expected(oracle()->ToBooleanTypes(test_id));
     HBranch* test = is_logical_and
-      ? new(zone()) HBranch(Top(), eval_right, empty_block, expected)
-      : new(zone()) HBranch(Top(), empty_block, eval_right, expected);
+      ? new(zone()) HBranch(left_value, eval_right, empty_block, expected)
+      : new(zone()) HBranch(left_value, empty_block, eval_right, expected);
     current_block()->Finish(test);

     set_current_block(eval_right);

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