Chromium Code Reviews| Index: runtime/vm/flow_graph_optimizer.cc |
| =================================================================== |
| --- runtime/vm/flow_graph_optimizer.cc (revision 20429) |
| +++ runtime/vm/flow_graph_optimizer.cc (working copy) |
| @@ -2110,6 +2110,32 @@ |
| } |
| + |
| +// Check if this StrictCompare can be merged with its input: |
| +// x = (a === b); y = (x !== true) -> y = a !== b. |
| +// This is a common occurence for !identical(a, b). |
| +void FlowGraphOptimizer::HandleStrictCompare(StrictCompareInstr* comp, |
| + BranchInstr* instr) { |
| + if ((comp->kind() != Token::kNE_STRICT) || |
| + !comp->right()->BindsToConstant() || |
| + (comp->right()->BoundConstant().raw() != Bool::True().raw())) { |
| + return; |
| + } |
| + StrictCompareInstr* left = comp->left()->definition()->AsStrictCompare(); |
| + if (left == NULL) { |
| + return; |
| + } |
| + Token::Kind reverted_kind = (left->kind() == Token::kNE_STRICT) ? |
| + Token::kEQ_STRICT : Token::kNE_STRICT; |
|
Kevin Millikin (Google)
2013/03/25 09:58:08
We should probably have a generic way to do this,
srdjan
2013/03/25 21:12:11
Extended NegateComparison and moved that functiona
|
| + StrictCompareInstr* reverted_comp = |
| + new StrictCompareInstr(reverted_kind, |
| + left->left()->Copy(), |
| + left->right()->Copy()); |
| + instr->ReplaceWith(reverted_comp, current_iterator()); |
|
Kevin Millikin (Google)
2013/03/25 09:58:08
I still think it's nuts that BranchInstr::ReplaceW
srdjan
2013/03/25 21:12:11
Done.
|
| + left->RemoveFromGraph(); |
|
Kevin Millikin (Google)
2013/03/25 09:58:08
You can't remove this if it has uses, even environ
srdjan
2013/03/25 21:12:11
Thanks. Adding tests to catch that. Would it be us
|
| +} |
| + |
| + |
| void FlowGraphOptimizer::VisitBranch(BranchInstr* instr) { |
| ComparisonInstr* comparison = instr->comparison(); |
| if (comparison->IsRelationalOp()) { |
| @@ -2118,7 +2144,7 @@ |
| HandleEqualityCompare(comparison->AsEqualityCompare(), instr); |
| } else { |
| ASSERT(comparison->IsStrictCompare()); |
| - // Nothing to do. |
| + HandleStrictCompare(comparison->AsStrictCompare(), instr); |
|
Kevin Millikin (Google)
2013/03/25 09:58:08
I feel that this belongs better in the canonicaliz
srdjan
2013/03/25 21:12:11
I agree, moved.
|
| } |
| } |