Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Unified Diff: src/hydrogen.cc

Issue 12281019: Avoid creating unnecessary branches in Hydrogen (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed Yang's comment Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/hydrogen-instructions.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 62fa571bbcdcd2e29e687b5d2ffc4604979cbab8..5bda97d2187c4b78ef098eb8d40f7d72c725c45a 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -3615,6 +3615,16 @@ void TestContext::BuildBranch(HValue* value) {
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();
@@ -3622,8 +3632,8 @@ void TestContext::BuildBranch(HValue* value) {
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);
}
@@ -9032,6 +9042,17 @@ void HOptimizedGraphBuilder::VisitLogicalExpression(BinaryOperation* expr) {
} 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();
@@ -9039,8 +9060,8 @@ void HOptimizedGraphBuilder::VisitLogicalExpression(BinaryOperation* expr) {
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);
« no previous file with comments | « no previous file | src/hydrogen-instructions.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698