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

Unified Diff: runtime/vm/flow_graph_optimizer.cc

Issue 554543003: VM: Add constant propagation for binary double operations. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 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 | 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 39856)
+++ runtime/vm/flow_graph_optimizer.cc (working copy)
@@ -8415,8 +8415,31 @@
if (IsNonConstant(left) || IsNonConstant(right)) {
SetValue(instr, non_constant_);
} else if (IsConstant(left) && IsConstant(right)) {
- // TODO(kmillikin): Handle binary operation.
- SetValue(instr, non_constant_);
+ ASSERT(left.IsSmi() || left.IsDouble());
+ ASSERT(right.IsSmi() || right.IsDouble());
+ double left_val = left.IsSmi()
+ ? Smi::Cast(left).AsDoubleValue() : Double::Cast(left).value();
+ double right_val = right.IsSmi()
+ ? Smi::Cast(right).AsDoubleValue() : Double::Cast(right).value();
+ double result_val = 0.0;
+ switch (instr->op_kind()) {
+ case Token::kADD:
+ result_val = left_val + right_val;
+ break;
+ case Token::kSUB:
+ result_val = left_val - right_val;
+ break;
+ case Token::kMUL:
+ result_val = left_val * right_val;
+ break;
+ case Token::kDIV:
+ result_val = left_val / right_val;
+ break;
+ default:
+ UNREACHABLE();
+ }
+ const Double& result = Double::ZoneHandle(Double::NewCanonical(result_val));
+ SetValue(instr, result);
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698