Skip to content

Commit bd7d425

Browse files
dtigCommit Bot
authored andcommitted
[wasm] Fix Int64-lowering to handle non-const index for I64Atomic ops
Bug: chromium:925244 Change-Id: If9c00f85b1dece93057b541bf0fe1b0a05b81ceb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1565032 Commit-Queue: Deepti Gandluri <[email protected]> Reviewed-by: Ben Titzer <[email protected]> Cr-Commit-Position: refs/heads/master@{#60795}
1 parent b47449d commit bd7d425

3 files changed

Lines changed: 49 additions & 5 deletions

File tree

src/compiler/int64-lowering.cc

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ int GetReturnCountAfterLowering(Signature<MachineRepresentation>* signature) {
119119

120120
void Int64Lowering::LowerWord64AtomicBinop(Node* node, const Operator* op) {
121121
DCHECK_EQ(5, node->InputCount());
122+
LowerMemoryBaseAndIndex(node);
122123
Node* value = node->InputAt(2);
123124
node->ReplaceInput(2, GetReplacementLow(value));
124125
node->InsertInput(zone(), 3, GetReplacementHigh(value));
@@ -143,9 +144,6 @@ int Int64Lowering::GetParameterCountAfterLowering(
143144

144145
void Int64Lowering::GetIndexNodes(Node* index, Node*& index_low,
145146
Node*& index_high) {
146-
if (HasReplacementLow(index)) {
147-
index = GetReplacementLow(index);
148-
}
149147
#if defined(V8_TARGET_LITTLE_ENDIAN)
150148
index_low = index;
151149
index_high = graph()->NewNode(machine()->Int32Add(), index,
@@ -179,6 +177,7 @@ void Int64Lowering::LowerNode(Node* node) {
179177
}
180178

181179
if (rep == MachineRepresentation::kWord64) {
180+
LowerMemoryBaseAndIndex(node);
182181
Node* base = node->InputAt(0);
183182
Node* index = node->InputAt(1);
184183
Node* index_low;
@@ -228,6 +227,7 @@ void Int64Lowering::LowerNode(Node* node) {
228227
// a new store node to store the high word. The effect and control edges
229228
// are copied from the original store to the new store node, the effect
230229
// edge of the original store is redirected to the new store.
230+
LowerMemoryBaseAndIndex(node);
231231
Node* base = node->InputAt(0);
232232
Node* index = node->InputAt(1);
233233
Node* index_low;
@@ -900,6 +900,7 @@ void Int64Lowering::LowerNode(Node* node) {
900900
DCHECK_EQ(5, node->InputCount());
901901
MachineRepresentation rep = AtomicStoreRepresentationOf(node->op());
902902
if (rep == MachineRepresentation::kWord64) {
903+
LowerMemoryBaseAndIndex(node);
903904
Node* value = node->InputAt(2);
904905
node->ReplaceInput(2, GetReplacementLow(value));
905906
node->InsertInput(zone(), 3, GetReplacementHigh(value));
@@ -930,6 +931,7 @@ void Int64Lowering::LowerNode(Node* node) {
930931
case IrOpcode::kWord64AtomicCompareExchange: {
931932
MachineType type = AtomicOpType(node->op());
932933
if (type == MachineType::Uint64()) {
934+
LowerMemoryBaseAndIndex(node);
933935
Node* old_value = node->InputAt(2);
934936
Node* new_value = node->InputAt(3);
935937
node->ReplaceInput(2, GetReplacementLow(old_value));
@@ -1051,6 +1053,19 @@ void Int64Lowering::ReplaceNodeWithProjections(Node* node) {
10511053
ReplaceNode(node, low_node, high_node);
10521054
}
10531055

1056+
void Int64Lowering::LowerMemoryBaseAndIndex(Node* node) {
1057+
DCHECK(node != nullptr);
1058+
// Low word only replacements for memory operands for 32-bit address space.
1059+
Node* base = node->InputAt(0);
1060+
Node* index = node->InputAt(1);
1061+
if (HasReplacementLow(base)) {
1062+
node->ReplaceInput(0, GetReplacementLow(base));
1063+
}
1064+
if (HasReplacementLow(index)) {
1065+
node->ReplaceInput(1, GetReplacementLow(index));
1066+
}
1067+
}
1068+
10541069
} // namespace compiler
10551070
} // namespace internal
10561071
} // namespace v8

src/compiler/int64-lowering.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class V8_EXPORT_PRIVATE Int64Lowering {
6161
void PreparePhiReplacement(Node* phi);
6262
void GetIndexNodes(Node* index, Node*& index_low, Node*& index_high);
6363
void ReplaceNodeWithProjections(Node* node);
64+
void LowerMemoryBaseAndIndex(Node* node);
6465

6566
struct NodeState {
6667
Node* node;

test/cctest/wasm/test-run-wasm-atomics64.cc

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,14 +541,23 @@ void RunNonConstIndexTest(ExecutionTier execution_tier, WasmOpcode wasm_op,
541541
static_cast<uint32_t>(r.builder().ReadMemory(&memory[0])));
542542
}
543543

544+
// Test a set of Narrow operations
544545
#define TEST_OPERATION(Name) \
545-
WASM_EXEC_TEST(I64AtomicConstIndex##Name) { \
546+
WASM_EXEC_TEST(I64AtomicConstIndex##Name##Narrow) { \
546547
RunNonConstIndexTest(execution_tier, kExprI64Atomic##Name##32U, Name); \
547548
}
548549
OPERATION_LIST(TEST_OPERATION)
549550
#undef TEST_OPERATION
550551

551-
WASM_EXEC_TEST(I64AtomicNonConstIndexCompareExchange) {
552+
// Test a set of Regular operations
553+
#define TEST_OPERATION(Name) \
554+
WASM_EXEC_TEST(I64AtomicConstIndex##Name) { \
555+
RunNonConstIndexTest(execution_tier, kExprI64Atomic##Name, Name); \
556+
}
557+
OPERATION_LIST(TEST_OPERATION)
558+
#undef TEST_OPERATION
559+
560+
WASM_EXEC_TEST(I64AtomicNonConstIndexCompareExchangeNarrow) {
552561
EXPERIMENTAL_FLAG_SCOPE(threads);
553562
WasmRunner<uint32_t, uint64_t, uint64_t> r(execution_tier);
554563
uint64_t* memory =
@@ -567,6 +576,25 @@ WASM_EXEC_TEST(I64AtomicNonConstIndexCompareExchange) {
567576
static_cast<uint16_t>(r.builder().ReadMemory(&memory[0])));
568577
}
569578

579+
WASM_EXEC_TEST(I64AtomicNonConstIndexCompareExchange) {
580+
EXPERIMENTAL_FLAG_SCOPE(threads);
581+
WasmRunner<uint32_t, uint64_t, uint64_t> r(execution_tier);
582+
uint64_t* memory =
583+
r.builder().AddMemoryElems<uint64_t>(kWasmPageSize / sizeof(uint64_t));
584+
r.builder().SetHasSharedMemory();
585+
586+
BUILD(r, WASM_I32_CONVERT_I64(WASM_ATOMICS_TERNARY_OP(
587+
kExprI64AtomicCompareExchange,
588+
WASM_I64_EQ(WASM_I64V(1), WASM_I64V(0)), WASM_GET_LOCAL(0),
589+
WASM_GET_LOCAL(1), MachineRepresentation::kWord16)));
590+
591+
uint64_t initial = 4444333322221111, local = 0x9999888877776666;
592+
r.builder().WriteMemory(&memory[0], initial);
593+
CHECK_EQ(static_cast<uint32_t>(initial), r.Call(initial, local));
594+
CHECK_EQ(CompareExchange(initial, initial, local),
595+
r.builder().ReadMemory(&memory[0]));
596+
}
597+
570598
WASM_EXEC_TEST(I64AtomicNonConstIndexLoad8U) {
571599
EXPERIMENTAL_FLAG_SCOPE(threads);
572600
WasmRunner<uint32_t> r(execution_tier);

0 commit comments

Comments
 (0)