Commit 3f1ed699 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm-gc][liftoff] Fix array.get value register class

Bug: v8:7748, v8:11602
Change-Id: I007e80de0114cc651c8eb2ec825fc130a4b386c9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2790175Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#73704}
parent 806f79e4
...@@ -5049,7 +5049,8 @@ class LiftoffCompiler { ...@@ -5049,7 +5049,8 @@ class LiftoffCompiler {
if (elem_size_shift != 0) { if (elem_size_shift != 0) {
__ emit_i32_shli(index.gp(), index.gp(), elem_size_shift); __ emit_i32_shli(index.gp(), index.gp(), elem_size_shift);
} }
LiftoffRegister value = __ GetUnusedRegister(kGpReg, {array}, pinned); LiftoffRegister value =
__ GetUnusedRegister(reg_class_for(elem_kind), pinned);
LoadObjectField(value, array.gp(), index.gp(), LoadObjectField(value, array.gp(), index.gp(),
wasm::ObjectAccess::ToTagged(WasmArray::kHeaderSize), wasm::ObjectAccess::ToTagged(WasmArray::kHeaderSize),
elem_kind, is_signed, pinned); elem_kind, is_signed, pinned);
...@@ -5061,6 +5062,8 @@ class LiftoffCompiler { ...@@ -5061,6 +5062,8 @@ class LiftoffCompiler {
const Value& index_val, const Value& value_val) { const Value& index_val, const Value& value_val) {
LiftoffRegList pinned; LiftoffRegList pinned;
LiftoffRegister value = pinned.set(__ PopToRegister(pinned)); LiftoffRegister value = pinned.set(__ PopToRegister(pinned));
DCHECK_EQ(reg_class_for(imm.array_type->element_type().kind()),
value.reg_class());
LiftoffRegister index = pinned.set(__ PopToModifiableRegister(pinned)); LiftoffRegister index = pinned.set(__ PopToModifiableRegister(pinned));
LiftoffRegister array = pinned.set(__ PopToRegister(pinned)); LiftoffRegister array = pinned.set(__ PopToRegister(pinned));
MaybeEmitNullCheck(decoder, array.gp(), pinned, array_obj.type); MaybeEmitNullCheck(decoder, array.gp(), pinned, array_obj.type);
......
...@@ -609,6 +609,7 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) { ...@@ -609,6 +609,7 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) {
WasmGCTester tester(execution_tier); WasmGCTester tester(execution_tier);
const byte type_index = tester.DefineArray(wasm::kWasmI32, true); const byte type_index = tester.DefineArray(wasm::kWasmI32, true);
const byte fp_type_index = tester.DefineArray(wasm::kWasmF64, true);
ValueType kRefTypes[] = {ref(type_index)}; ValueType kRefTypes[] = {ref(type_index)};
FunctionSig sig_q_v(1, 0, kRefTypes); FunctionSig sig_q_v(1, 0, kRefTypes);
ValueType kOptRefType = optref(type_index); ValueType kOptRefType = optref(type_index);
...@@ -655,6 +656,20 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) { ...@@ -655,6 +656,20 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) {
WASM_RTT_CANON(type_index)), WASM_RTT_CANON(type_index)),
kExprEnd}); kExprEnd});
// Tests that fp arrays work properly.
// f: a = [10.0, 10.0, 10.0]; a[1] = 42.42; return static_cast<int64>(a[1]);
double result_value = 42.42;
const byte kTestFpArray = tester.DefineFunction(
tester.sigs.i_v(), {optref(fp_type_index)},
{WASM_LOCAL_SET(0, WASM_ARRAY_NEW_WITH_RTT(
fp_type_index, WASM_F64(10.0), WASM_I32V(3),
WASM_RTT_CANON(fp_type_index))),
WASM_ARRAY_SET(fp_type_index, WASM_LOCAL_GET(0), WASM_I32V(1),
WASM_F64(result_value)),
WASM_I32_SCONVERT_F64(
WASM_ARRAY_GET(fp_type_index, WASM_LOCAL_GET(0), WASM_I32V(1))),
kExprEnd});
tester.CompileModule(); tester.CompileModule();
tester.CheckResult(kGetElem, 12, 0); tester.CheckResult(kGetElem, 12, 0);
...@@ -663,6 +678,7 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) { ...@@ -663,6 +678,7 @@ WASM_COMPILED_EXEC_TEST(WasmBasicArray) {
tester.CheckHasThrown(kGetElem, 3); tester.CheckHasThrown(kGetElem, 3);
tester.CheckHasThrown(kGetElem, -1); tester.CheckHasThrown(kGetElem, -1);
tester.CheckResult(kGetLength, 42); tester.CheckResult(kGetLength, 42);
tester.CheckResult(kTestFpArray, static_cast<int32_t>(result_value));
MaybeHandle<Object> h_result = tester.GetResultObject(kAllocate); MaybeHandle<Object> h_result = tester.GetResultObject(kAllocate);
CHECK(h_result.ToHandleChecked()->IsWasmArray()); CHECK(h_result.ToHandleChecked()->IsWasmArray());
......
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