Commit 3c36aacc authored by jarin's avatar jarin Committed by Commit bot

[turbofan] Fix handling of typed array loads in load elimination.

BUG=chromium:694088

Review-Url: https://codereview.chromium.org/2725593002
Cr-Commit-Position: refs/heads/master@{#43477}
parent 84ff6e4c
......@@ -798,23 +798,48 @@ Reduction LoadElimination::ReduceLoadElement(Node* node) {
Node* const control = NodeProperties::GetControlInput(node);
AbstractState const* state = node_states_.Get(effect);
if (state == nullptr) return NoChange();
if (Node* replacement = state->LookupElement(object, index)) {
// Make sure we don't resurrect dead {replacement} nodes.
if (!replacement->IsDead()) {
// We might need to guard the {replacement} if the type of the
// {node} is more precise than the type of the {replacement}.
Type* const node_type = NodeProperties::GetType(node);
if (!NodeProperties::GetType(replacement)->Is(node_type)) {
replacement = graph()->NewNode(common()->TypeGuard(node_type),
replacement, control);
NodeProperties::SetType(replacement, node_type);
// Only handle loads that do not require truncations.
ElementAccess const& access = ElementAccessOf(node->op());
switch (access.machine_type.representation()) {
case MachineRepresentation::kNone:
case MachineRepresentation::kSimd1x4:
case MachineRepresentation::kSimd1x8:
case MachineRepresentation::kSimd1x16:
case MachineRepresentation::kBit:
UNREACHABLE();
break;
case MachineRepresentation::kWord8:
case MachineRepresentation::kWord16:
case MachineRepresentation::kWord32:
case MachineRepresentation::kWord64:
case MachineRepresentation::kFloat32:
// TODO(turbofan): Add support for doing the truncations.
break;
case MachineRepresentation::kFloat64:
case MachineRepresentation::kSimd128:
case MachineRepresentation::kTaggedSigned:
case MachineRepresentation::kTaggedPointer:
case MachineRepresentation::kTagged:
if (Node* replacement = state->LookupElement(object, index)) {
// Make sure we don't resurrect dead {replacement} nodes.
if (!replacement->IsDead()) {
// We might need to guard the {replacement} if the type of the
// {node} is more precise than the type of the {replacement}.
Type* const node_type = NodeProperties::GetType(node);
if (!NodeProperties::GetType(replacement)->Is(node_type)) {
replacement = graph()->NewNode(common()->TypeGuard(node_type),
replacement, control);
NodeProperties::SetType(replacement, node_type);
}
ReplaceWithValue(node, replacement, effect);
return Replace(replacement);
}
}
ReplaceWithValue(node, replacement, effect);
return Replace(replacement);
}
state = state->AddElement(object, index, node, zone());
return UpdateState(node, state);
}
state = state->AddElement(object, index, node, zone());
return UpdateState(node, state);
return NoChange();
}
Reduction LoadElimination::ReduceStoreElement(Node* node) {
......
// Copyright 2017 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.
(function () {
var buffer = new ArrayBuffer(8);
var i32 = new Int32Array(buffer);
var f64 = new Float64Array(buffer);
function foo() {
f64[0] = 1;
var x = f64[0];
return i32[0];
}
assertEquals(0, foo());
})();
(function () {
var buffer = new ArrayBuffer(8);
var i16 = new Int16Array(buffer);
var i32 = new Int32Array(buffer);
function foo() {
i32[0] = 0x10001;
var x = i32[0];
return i16[0];
}
assertEquals(1, foo());
})();
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