Commit dd51dd92 authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] Change the default lowering of stores.

The int64-lowering only lowered store instructions with a word64 store
representation. For all other stores the default lowering applied. The
default lowering replaces all input nodes with both their replacement
nodes, which can change the number of input nodes of the lowered node.

In WebAssembly there exist stores which take an I64 input and store it
with a different representation, e.g. I32. In TurboFan this translates
to a store node with word32 store representation and a word64 value
input. The default lowering replaces the word64 value input to become
two word32 value inputs, which makes the number of inputs of the store
node invalid. This CL discards the high word replacement of the value
input so that the number of input nodes of a store node does not change
in the default lowering.

R=titzer@chromium.org
CC=rossberg@chromium.org

BUG=

Review-Url: https://codereview.chromium.org/2668023004
Cr-Commit-Position: refs/heads/master@{#42860}
parent 93f181b6
......@@ -237,7 +237,7 @@ void Int64Lowering::LowerNode(Node* node) {
NodeProperties::ChangeOp(node, store_op);
ReplaceNode(node, node, high_node);
} else {
DefaultLowering(node);
DefaultLowering(node, true);
}
break;
}
......@@ -826,7 +826,7 @@ void Int64Lowering::LowerComparison(Node* node, const Operator* high_word_op,
ReplaceNode(node, replacement, nullptr);
}
bool Int64Lowering::DefaultLowering(Node* node) {
bool Int64Lowering::DefaultLowering(Node* node, bool low_word_only) {
bool something_changed = false;
for (int i = NodeProperties::PastValueIndex(node) - 1; i >= 0; i--) {
Node* input = node->InputAt(i);
......@@ -834,7 +834,7 @@ bool Int64Lowering::DefaultLowering(Node* node) {
something_changed = true;
node->ReplaceInput(i, GetReplacementLow(input));
}
if (HasReplacementHigh(input)) {
if (!low_word_only && HasReplacementHigh(input)) {
something_changed = true;
node->InsertInput(zone(), i + 1, GetReplacementHigh(input));
}
......
......@@ -47,7 +47,7 @@ class V8_EXPORT_PRIVATE Int64Lowering {
void PrepareReplacements(Node* node);
void PushNode(Node* node);
void LowerNode(Node* node);
bool DefaultLowering(Node* node);
bool DefaultLowering(Node* node, bool low_word_only = false);
void LowerComparison(Node* node, const Operator* signed_op,
const Operator* unsigned_op);
void PrepareProjectionReplacements(Node* node);
......
......@@ -237,6 +237,38 @@ TEST_F(Int64LoweringTest, Int64Store) {
INT64_STORE_LOWERING(Store, rep32, rep64);
}
TEST_F(Int64LoweringTest, Int32Store) {
const StoreRepresentation rep32(MachineRepresentation::kWord32,
WriteBarrierKind::kNoWriteBarrier);
int32_t base = 1111;
int32_t index = 2222;
int32_t return_value = 0x5555;
Signature<MachineRepresentation>::Builder sig_builder(zone(), 1, 0);
sig_builder.AddReturn(MachineRepresentation::kWord32);
Node* store = graph()->NewNode(machine()->Store(rep32), Int32Constant(base),
Int32Constant(index), Int64Constant(value(0)),
start(), start());
Node* zero = graph()->NewNode(common()->Int32Constant(0));
Node* ret = graph()->NewNode(common()->Return(), zero,
Int32Constant(return_value), store, start());
NodeProperties::MergeControlToEnd(graph(), common(), ret);
Int64Lowering lowering(graph(), machine(), common(), zone(),
sig_builder.Build());
lowering.LowerGraph();
EXPECT_THAT(
graph()->end()->InputAt(1),
IsReturn(IsInt32Constant(return_value),
IsStore(rep32, IsInt32Constant(base), IsInt32Constant(index),
IsInt32Constant(low_word_value(0)), start(), start()),
start()));
}
TEST_F(Int64LoweringTest, Int64UnalignedStore) {
const UnalignedStoreRepresentation rep64(MachineRepresentation::kWord64);
const UnalignedStoreRepresentation rep32(MachineRepresentation::kWord32);
......
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