Commit e92118bb authored by jarin's avatar jarin Committed by Commit bot

[turbofan] Optimize store to typed arrays only if the value is plain primitive.

BUG=v8:5756

Review-Url: https://codereview.chromium.org/2596843002
Cr-Commit-Position: refs/heads/master@{#41942}
parent 0d5561b6
...@@ -1254,6 +1254,9 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { ...@@ -1254,6 +1254,9 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) {
Node* value = NodeProperties::GetValueInput(node, 2); Node* value = NodeProperties::GetValueInput(node, 2);
Type* key_type = NodeProperties::GetType(key); Type* key_type = NodeProperties::GetType(key);
Type* value_type = NodeProperties::GetType(value); Type* value_type = NodeProperties::GetType(value);
if (!value_type->Is(Type::PlainPrimitive())) return NoChange();
HeapObjectMatcher mbase(base); HeapObjectMatcher mbase(base);
if (mbase.HasValue() && mbase.Value()->IsJSTypedArray()) { if (mbase.HasValue() && mbase.Value()->IsJSTypedArray()) {
Handle<JSTypedArray> const array = Handle<JSTypedArray> const array =
...@@ -1272,7 +1275,6 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { ...@@ -1272,7 +1275,6 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) {
Handle<FixedTypedArrayBase>::cast(handle(array->elements())); Handle<FixedTypedArrayBase>::cast(handle(array->elements()));
Node* buffer = jsgraph()->PointerConstant(elements->external_pointer()); Node* buffer = jsgraph()->PointerConstant(elements->external_pointer());
Node* length = jsgraph()->Constant(byte_length); Node* length = jsgraph()->Constant(byte_length);
Node* context = NodeProperties::GetContextInput(node);
Node* effect = NodeProperties::GetEffectInput(node); Node* effect = NodeProperties::GetEffectInput(node);
Node* control = NodeProperties::GetControlInput(node); Node* control = NodeProperties::GetControlInput(node);
// Convert to a number first. // Convert to a number first.
...@@ -1281,12 +1283,8 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) { ...@@ -1281,12 +1283,8 @@ Reduction JSTypedLowering::ReduceJSStoreProperty(Node* node) {
if (number_reduction.Changed()) { if (number_reduction.Changed()) {
value = number_reduction.replacement(); value = number_reduction.replacement();
} else { } else {
Node* frame_state_for_to_number = value =
NodeProperties::FindFrameStateBefore(node); graph()->NewNode(simplified()->PlainPrimitiveToNumber(), value);
value = effect =
graph()->NewNode(javascript()->ToNumber(), value, context,
frame_state_for_to_number, effect, control);
control = graph()->NewNode(common()->IfSuccess(), value);
} }
} }
// Check if we can avoid the bounds check. // Check if we can avoid the bounds check.
......
// Copyright 2016 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
z = {};
t = new Uint8Array(3);
var m = 0;
var x = 10;
function k() {
++m;
if (m % 10 != 9) {
if (m > 20) // This if is to just force it to deoptimize.
x = '1'; // this deoptimizes during the second invocation of k.
// This causes two deopts, one eager at x = 1 and the
// other lazy at t[2] = z.
t[2] = z; // since we are assigning to Uint8Array, ToNumber
// is called which calls this funciton again.
}
}
function f1() {
z.toString = k;
z.toString();
z.toString();
%OptimizeFunctionOnNextCall(k);
z.toString();
}
f1();
...@@ -717,7 +717,7 @@ TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) { ...@@ -717,7 +717,7 @@ TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) {
Node* key = Parameter( Node* key = Parameter(
Type::Range(kMinInt / element_size, kMaxInt / element_size, zone())); Type::Range(kMinInt / element_size, kMaxInt / element_size, zone()));
Node* base = HeapConstant(array); Node* base = HeapConstant(array);
Node* value = Parameter(Type::Any()); Node* value = Parameter(Type::PlainPrimitive());
Node* context = UndefinedConstant(); Node* context = UndefinedConstant();
Node* effect = graph()->start(); Node* effect = graph()->start();
Node* control = graph()->start(); Node* control = graph()->start();
...@@ -737,10 +737,7 @@ TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) { ...@@ -737,10 +737,7 @@ TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) {
: IsNumberShiftLeft( : IsNumberShiftLeft(
key, IsNumberConstant(WhichPowerOf2(element_size))); key, IsNumberConstant(WhichPowerOf2(element_size)));
Matcher<Node*> value_matcher = Matcher<Node*> value_matcher = IsPlainPrimitiveToNumber(value);
IsToNumber(value, context, checkpoint, control);
Matcher<Node*> effect_matcher = value_matcher;
Matcher<Node*> control_matcher = IsIfSuccess(value_matcher);
ASSERT_TRUE(r.Changed()); ASSERT_TRUE(r.Changed());
EXPECT_THAT( EXPECT_THAT(
...@@ -749,7 +746,7 @@ TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) { ...@@ -749,7 +746,7 @@ TEST_F(JSTypedLoweringTest, JSStorePropertyToExternalTypedArrayWithConversion) {
BufferAccess(type), BufferAccess(type),
IsPointerConstant(bit_cast<intptr_t>(&backing_store[0])), IsPointerConstant(bit_cast<intptr_t>(&backing_store[0])),
offset_matcher, IsNumberConstant(array->byte_length()->Number()), offset_matcher, IsNumberConstant(array->byte_length()->Number()),
value_matcher, effect_matcher, control_matcher)); value_matcher, checkpoint, control));
} }
} }
} }
......
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