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

Unified Diff: runtime/vm/flow_graph_optimizer.cc

Issue 11342014: Fold away x === null comparisons when propagated cid of x is not kDynamicCid. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: fix error in type recognition for List. call Created 8 years, 2 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_builder.cc ('k') | runtime/vm/intermediate_language.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/flow_graph_optimizer.cc
diff --git a/runtime/vm/flow_graph_optimizer.cc b/runtime/vm/flow_graph_optimizer.cc
index cc887c737a94364b56e2561f906af86a1406a0d4..4f9f56055607302f890bb8452db60a0cb859ca20 100644
--- a/runtime/vm/flow_graph_optimizer.cc
+++ b/runtime/vm/flow_graph_optimizer.cc
@@ -3066,8 +3066,18 @@ void ConstantPropagator::VisitStoreLocal(StoreLocalInstr* instr) {
void ConstantPropagator::VisitStrictCompare(StrictCompareInstr* instr) {
const Object& left = instr->left()->definition()->constant_value();
const Object& right = instr->right()->definition()->constant_value();
+
if (IsNonConstant(left) || IsNonConstant(right)) {
- SetValue(instr, non_constant_);
+ // TODO(vegorov): incorporate nullability information into the lattice.
+ if ((left.IsNull() && (instr->right()->ResultCid() != kDynamicCid)) ||
+ (right.IsNull() && (instr->left()->ResultCid() != kDynamicCid))) {
+ bool result = left.IsNull() ? (instr->right()->ResultCid() == kNullCid)
+ : (instr->left()->ResultCid() == kNullCid);
+ if (instr->kind() == Token::kNE_STRICT) result = !result;
+ SetValue(instr, Bool::ZoneHandle(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;
@@ -3404,6 +3414,8 @@ void ConstantPropagator::Transform() {
printer.PrintBlocks();
}
+ GrowableArray<PhiInstr*> redundant_phis(10);
+
// We will recompute dominators, block ordering, block ids, block last
// instructions, previous pointers, predecessors, etc. after eliminating
// unreachable code. We do not maintain those properties during the
@@ -3446,6 +3458,7 @@ void ConstantPropagator::Transform() {
PhiInstr* phi = (*phis)[phi_idx];
if (phi == NULL) continue;
phi->inputs_.TruncateTo(live_count);
+ if (live_count == 1) redundant_phis.Add(phi);
}
}
}
@@ -3521,6 +3534,12 @@ void ConstantPropagator::Transform() {
graph_->ComputeDominators(&dominance_frontier);
graph_->ComputeUseLists();
+ for (intptr_t i = 0; i < redundant_phis.length(); i++) {
+ PhiInstr* phi = redundant_phis[i];
+ phi->ReplaceUsesWith(phi->InputAt(0)->definition());
+ phi->mark_dead();
+ }
+
if (FLAG_trace_constant_propagation) {
OS::Print("\n==== After constant propagation ====\n");
FlowGraphPrinter printer(*graph_);
« no previous file with comments | « runtime/vm/flow_graph_builder.cc ('k') | runtime/vm/intermediate_language.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698