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

Unified Diff: runtime/vm/flow_graph_optimizer.cc

Issue 57703004: Constant fold strict comparison based on incoming types: different (exact) types means that the res… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month 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/lib/integers.dart ('k') | runtime/vm/flow_graph_type_propagator.cc » ('j') | 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 30082)
+++ runtime/vm/flow_graph_optimizer.cc (working copy)
@@ -6313,14 +6313,28 @@
(right.IsNull() && instr->left()->Type()->HasDecidableNullability())) {
bool result = left.IsNull() ? instr->right()->Type()->IsNull()
: instr->left()->Type()->IsNull();
- if (instr->kind() == Token::kNE_STRICT) result = !result;
+ if (instr->kind() == Token::kNE_STRICT) {
+ result = !result;
+ }
SetValue(instr, Bool::Get(result));
} else {
- SetValue(instr, non_constant_);
+ const intptr_t left_cid = instr->left()->Type()->ToCid();
+ const intptr_t right_cid = instr->right()->Type()->ToCid();
+ // If exact classes (cids) are known and they differ, the result
+ // of strict compare can be computed.
+ if ((left_cid != kDynamicCid) && (right_cid != kDynamicCid) &&
+ (left_cid != right_cid)) {
+ const bool result = (instr->kind() != Token::kEQ_STRICT);
+ SetValue(instr, Bool::Get(result));
+ } else {
+ SetValue(instr, non_constant_);
+ }
}
} else if (IsConstant(left) && IsConstant(right)) {
bool result = (left.raw() == right.raw());
- if (instr->kind() == Token::kNE_STRICT) result = !result;
+ if (instr->kind() == Token::kNE_STRICT) {
+ result = !result;
+ }
SetValue(instr, Bool::Get(result));
}
}
« no previous file with comments | « runtime/lib/integers.dart ('k') | runtime/vm/flow_graph_type_propagator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698