[wasm-atomics] Prevent atomic load operation to be optimized out

Bug: chromium:1339276
Change-Id: Ice60167660fa52e84c78bb0bd9d2a2c85e0c377a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3733027
Reviewed-by: Deepti Gandluri <gdeepti@chromium.org>
Commit-Queue: Ilya Rezvov <irezvov@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81478}
This commit is contained in:
Ilya Rezvov 2022-06-28 11:11:09 -06:00 committed by V8 LUCI CQ
parent 0d6e95b43e
commit 40daf5b14b
2 changed files with 16 additions and 4 deletions

View File

@ -1073,7 +1073,7 @@ struct MachineOperatorGlobalCache {
: public Operator1<AtomicLoadParameters> { \
Word32SeqCstLoad##Type##Kind##Operator() \
: Operator1<AtomicLoadParameters>( \
IrOpcode::kWord32AtomicLoad, Operator::kEliminatable, \
IrOpcode::kWord32AtomicLoad, Operator::kNoProperties, \
"Word32AtomicLoad", 2, 1, 1, 1, 1, 0, \
AtomicLoadParameters(MachineType::Type(), \
AtomicMemoryOrder::kSeqCst, \
@ -1092,7 +1092,7 @@ struct MachineOperatorGlobalCache {
: public Operator1<AtomicLoadParameters> { \
Word64SeqCstLoad##Type##Kind##Operator() \
: Operator1<AtomicLoadParameters>( \
IrOpcode::kWord64AtomicLoad, Operator::kEliminatable, \
IrOpcode::kWord64AtomicLoad, Operator::kNoProperties, \
"Word64AtomicLoad", 2, 1, 1, 1, 1, 0, \
AtomicLoadParameters(MachineType::Type(), \
AtomicMemoryOrder::kSeqCst, \
@ -1699,7 +1699,7 @@ const Operator* MachineOperatorBuilder::Word32AtomicLoad(
#define LOAD(Type) \
if (params.representation() == MachineType::Type()) { \
return zone_->New<Operator1<AtomicLoadParameters>>( \
IrOpcode::kWord32AtomicLoad, Operator::kEliminatable, \
IrOpcode::kWord32AtomicLoad, Operator::kNoProperties, \
"Word32AtomicLoad", 2, 1, 1, 1, 1, 0, params); \
}
ATOMIC_TYPE_LIST(LOAD)
@ -1826,7 +1826,7 @@ const Operator* MachineOperatorBuilder::Word64AtomicLoad(
#define LOAD(Type) \
if (params.representation() == MachineType::Type()) { \
return zone_->New<Operator1<AtomicLoadParameters>>( \
IrOpcode::kWord64AtomicLoad, Operator::kEliminatable, \
IrOpcode::kWord64AtomicLoad, Operator::kNoProperties, \
"Word64AtomicLoad", 2, 1, 1, 1, 1, 0, params); \
}
ATOMIC_U64_TYPE_LIST(LOAD)

View File

@ -412,6 +412,18 @@ WASM_EXEC_TEST(I64AtomicStore_trap) {
CHECK_TRAP(r.Call());
}
WASM_EXEC_TEST(I32AtomicLoad_NotOptOut) {
EXPERIMENTAL_FLAG_SCOPE(threads);
WasmRunner<uint32_t> r(execution_tier);
r.builder().SetHasSharedMemory();
r.builder().AddMemory(kWasmPageSize);
BUILD(r, WASM_I32_AND(
WASM_ATOMICS_LOAD_OP(kExprI32AtomicLoad, WASM_I32V_3(kWasmPageSize),
MachineRepresentation::kWord32),
WASM_ZERO));
CHECK_TRAP(r.Call());
}
} // namespace test_run_wasm_atomics
} // namespace wasm
} // namespace internal