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

Unified Diff: runtime/vm/flow_graph_optimizer.cc

Issue 102973007: Constant propagation in LoadIndexed when inputs are array/string and index constants. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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 | tests/language/guess_cid_test.dart » ('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 31147)
+++ runtime/vm/flow_graph_optimizer.cc (working copy)
@@ -6630,7 +6630,37 @@
void ConstantPropagator::VisitLoadIndexed(LoadIndexedInstr* instr) {
- SetValue(instr, non_constant_);
+ const Object& array_obj = instr->array()->definition()->constant_value();
+ const Object& index_obj = instr->index()->definition()->constant_value();
+ if (IsNonConstant(array_obj) || IsNonConstant(index_obj)) {
+ SetValue(instr, non_constant_);
+ } else if (IsConstant(array_obj) && IsConstant(index_obj)) {
+ // Need index to be Smi and array to be either String or an immutable array.
+ if (!index_obj.IsSmi()) {
+ // Should not occur.
+ SetValue(instr, non_constant_);
+ return;
+ }
+ const intptr_t index = Smi::Cast(index_obj).Value();
+ if (index >= 0) {
+ if (array_obj.IsString()) {
+ const String& str = String::Cast(array_obj);
+ if (str.Length() > index) {
+ SetValue(instr, Smi::Handle(Smi::New(str.CharAt(index))));
+ return;
+ }
+ } else if (array_obj.IsArray()) {
+ const Array& a = Array::Cast(array_obj);
+ if ((a.Length() > index) && a.IsImmutable()) {
Cutch 2013/12/18 05:21:19 Is IsImmutable needed for a constant array?
srdjan 2013/12/18 16:40:01 I believe it could be possible for constant propag
+ Instance& result = Instance::Handle();
+ result ^= a.At(index);
+ SetValue(instr, result);
+ return;
+ }
+ }
+ }
+ SetValue(instr, non_constant_);
+ }
}
« no previous file with comments | « no previous file | tests/language/guess_cid_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698