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

Unified Diff: runtime/vm/flow_graph_optimizer.cc

Issue 12852007: Improve code for !identical(a, b): (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 9 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 | « runtime/vm/flow_graph_optimizer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.
}
}
« no previous file with comments | « runtime/vm/flow_graph_optimizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698