Commit a1a0f465 authored by verwaest@chromium.org's avatar verwaest@chromium.org

Turn keyed loads with string-based (non-convertible to array-index) key into named loads

BUG=
R=ishell@chromium.org

Review URL: https://codereview.chromium.org/585433002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24032 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 63b1c190
......@@ -6436,8 +6436,8 @@ void HOptimizedGraphBuilder::BuildStore(Expression* expr,
HValue* key = environment()->ExpressionStackAt(1);
HValue* object = environment()->ExpressionStackAt(2);
bool has_side_effects = false;
HandleKeyedElementAccess(object, key, value, expr,
STORE, &has_side_effects);
HandleKeyedElementAccess(object, key, value, expr, return_id, STORE,
&has_side_effects);
Drop(3);
Push(value);
Add<HSimulate>(return_id, REMOVABLE_SIMULATE);
......@@ -7129,12 +7129,28 @@ HValue* HOptimizedGraphBuilder::HandlePolymorphicElementAccess(
HValue* HOptimizedGraphBuilder::HandleKeyedElementAccess(
HValue* obj,
HValue* key,
HValue* val,
Expression* expr,
PropertyAccessType access_type,
HValue* obj, HValue* key, HValue* val, Expression* expr,
BailoutId return_id, PropertyAccessType access_type,
bool* has_side_effects) {
if (key->ActualValue()->IsConstant()) {
Handle<Object> constant =
HConstant::cast(key->ActualValue())->handle(isolate());
uint32_t array_index;
if (constant->IsString() &&
!Handle<String>::cast(constant)->AsArrayIndex(&array_index)) {
HInstruction* instr =
BuildNamedAccess(access_type, expr->id(), return_id, expr, obj,
Handle<String>::cast(constant), val, false);
if (instr == NULL || instr->IsLinked()) {
*has_side_effects = false;
} else {
AddInstruction(instr);
*has_side_effects = instr->HasObservableSideEffects();
}
return instr;
}
}
DCHECK(!expr->IsPropertyName());
HInstruction* instr = NULL;
......@@ -7345,7 +7361,7 @@ void HOptimizedGraphBuilder::BuildLoad(Property* expr,
bool has_side_effects = false;
HValue* load = HandleKeyedElementAccess(
obj, key, NULL, expr, LOAD, &has_side_effects);
obj, key, NULL, expr, expr->LoadId(), LOAD, &has_side_effects);
if (has_side_effects) {
if (ast_context()->IsEffect()) {
Add<HSimulate>(ast_id, REMOVABLE_SIMULATE);
......@@ -7355,6 +7371,7 @@ void HOptimizedGraphBuilder::BuildLoad(Property* expr,
Drop(1);
}
}
if (load == NULL) return;
return ast_context()->ReturnValue(load);
}
return ast_context()->ReturnInstruction(instr, ast_id);
......
......@@ -2647,10 +2647,8 @@ class HOptimizedGraphBuilder : public HGraphBuilder, public AstVisitor {
KeyedAccessStoreMode store_mode,
bool* has_side_effects);
HValue* HandleKeyedElementAccess(HValue* obj,
HValue* key,
HValue* val,
Expression* expr,
HValue* HandleKeyedElementAccess(HValue* obj, HValue* key, HValue* val,
Expression* expr, BailoutId return_id,
PropertyAccessType access_type,
bool* has_side_effects);
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
var k = "x";
var o1 = {x: 10};
var o2 = {x: 11, y: 20};
var o3 = {x: 12, y: 20, z: 100};
function f(o) {
var result = 0;
for (var i = 0; i < 100; i++) {
result += o[k];
}
return result;
}
f(o1);
f(o1);
f(o1);
%OptimizeFunctionOnNextCall(f);
assertEquals(1000, f(o1));
f(o2);
f(o2);
f(o2);
%OptimizeFunctionOnNextCall(f);
assertEquals(1100, f(o2));
f(o3);
f(o3);
f(o3);
%OptimizeFunctionOnNextCall(f);
assertEquals(1200, f(o3));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment