Commit e19c945b authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm-gc] Skip null check for non-nullable arrays in generated code

Bug: v8:7748
Change-Id: Ic55c1aeb2bceb72dff1338c4d9cbde9aa799f25a
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2262914
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#68525}
parent 305e3dfc
...@@ -5347,10 +5347,12 @@ void WasmGraphBuilder::BoundsCheck(Node* array, Node* index, ...@@ -5347,10 +5347,12 @@ void WasmGraphBuilder::BoundsCheck(Node* array, Node* index,
Node* WasmGraphBuilder::ArrayGet(Node* array_object, Node* WasmGraphBuilder::ArrayGet(Node* array_object,
const wasm::ArrayType* type, Node* index, const wasm::ArrayType* type, Node* index,
bool is_signed, CheckForNull null_check, bool is_signed,
wasm::WasmCodePosition position) { wasm::WasmCodePosition position) {
TrapIfTrue(wasm::kTrapNullDereference, if (null_check == kWithNullCheck) {
gasm_->WordEqual(array_object, RefNull()), position); TrapIfTrue(wasm::kTrapNullDereference,
gasm_->WordEqual(array_object, RefNull()), position);
}
BoundsCheck(array_object, index, position); BoundsCheck(array_object, index, position);
MachineType machine_type = MachineType::TypeForRepresentation( MachineType machine_type = MachineType::TypeForRepresentation(
type->element_type().machine_representation(), is_signed); type->element_type().machine_representation(), is_signed);
...@@ -5361,9 +5363,12 @@ Node* WasmGraphBuilder::ArrayGet(Node* array_object, ...@@ -5361,9 +5363,12 @@ Node* WasmGraphBuilder::ArrayGet(Node* array_object,
Node* WasmGraphBuilder::ArraySet(Node* array_object, Node* WasmGraphBuilder::ArraySet(Node* array_object,
const wasm::ArrayType* type, Node* index, const wasm::ArrayType* type, Node* index,
Node* value, wasm::WasmCodePosition position) { Node* value, CheckForNull null_check,
TrapIfTrue(wasm::kTrapNullDereference, wasm::WasmCodePosition position) {
gasm_->WordEqual(array_object, RefNull()), position); if (null_check == kWithNullCheck) {
TrapIfTrue(wasm::kTrapNullDereference,
gasm_->WordEqual(array_object, RefNull()), position);
}
BoundsCheck(array_object, index, position); BoundsCheck(array_object, index, position);
Node* offset = ArrayElementOffset(gasm_.get(), index, type->element_type()); Node* offset = ArrayElementOffset(gasm_.get(), index, type->element_type());
return StoreWithTaggedAlignment(gasm_.get(), array_object, offset, value, return StoreWithTaggedAlignment(gasm_.get(), array_object, offset, value,
......
...@@ -393,9 +393,11 @@ class WasmGraphBuilder { ...@@ -393,9 +393,11 @@ class WasmGraphBuilder {
Node* length, Node* initial_value); Node* length, Node* initial_value);
void BoundsCheck(Node* array, Node* index, wasm::WasmCodePosition position); void BoundsCheck(Node* array, Node* index, wasm::WasmCodePosition position);
Node* ArrayGet(Node* array_object, const wasm::ArrayType* type, Node* index, Node* ArrayGet(Node* array_object, const wasm::ArrayType* type, Node* index,
bool is_signed, wasm::WasmCodePosition position); CheckForNull null_check, bool is_signed,
wasm::WasmCodePosition position);
Node* ArraySet(Node* array_object, const wasm::ArrayType* type, Node* index, Node* ArraySet(Node* array_object, const wasm::ArrayType* type, Node* index,
Node* value, wasm::WasmCodePosition position); Node* value, CheckForNull null_check,
wasm::WasmCodePosition position);
Node* ArrayLen(Node* array_object, wasm::WasmCodePosition position); Node* ArrayLen(Node* array_object, wasm::WasmCodePosition position);
Node* RttCanon(wasm::HeapType type); Node* RttCanon(wasm::HeapType type);
......
...@@ -657,9 +657,9 @@ class WasmGraphBuildingInterface { ...@@ -657,9 +657,9 @@ class WasmGraphBuildingInterface {
const FieldIndexImmediate<validate>& field, bool is_signed, const FieldIndexImmediate<validate>& field, bool is_signed,
Value* result) { Value* result) {
using CheckForNull = compiler::WasmGraphBuilder::CheckForNull; using CheckForNull = compiler::WasmGraphBuilder::CheckForNull;
CheckForNull null_check = struct_object.type.kind() == ValueType::kRef CheckForNull null_check = struct_object.type.is_nullable()
? CheckForNull::kWithoutNullCheck ? CheckForNull::kWithNullCheck
: CheckForNull::kWithNullCheck; : CheckForNull::kWithoutNullCheck;
result->node = result->node =
BUILD(StructGet, struct_object.node, field.struct_index.struct_type, BUILD(StructGet, struct_object.node, field.struct_index.struct_type,
field.index, null_check, is_signed, decoder->position()); field.index, null_check, is_signed, decoder->position());
...@@ -669,9 +669,9 @@ class WasmGraphBuildingInterface { ...@@ -669,9 +669,9 @@ class WasmGraphBuildingInterface {
const FieldIndexImmediate<validate>& field, const FieldIndexImmediate<validate>& field,
const Value& field_value) { const Value& field_value) {
using CheckForNull = compiler::WasmGraphBuilder::CheckForNull; using CheckForNull = compiler::WasmGraphBuilder::CheckForNull;
CheckForNull null_check = struct_object.type.kind() == ValueType::kRef CheckForNull null_check = struct_object.type.is_nullable()
? CheckForNull::kWithoutNullCheck ? CheckForNull::kWithNullCheck
: CheckForNull::kWithNullCheck; : CheckForNull::kWithoutNullCheck;
BUILD(StructSet, struct_object.node, field.struct_index.struct_type, BUILD(StructSet, struct_object.node, field.struct_index.struct_type,
field.index, field_value.node, null_check, decoder->position()); field.index, field_value.node, null_check, decoder->position());
} }
...@@ -686,15 +686,23 @@ class WasmGraphBuildingInterface { ...@@ -686,15 +686,23 @@ class WasmGraphBuildingInterface {
void ArrayGet(FullDecoder* decoder, const Value& array_obj, void ArrayGet(FullDecoder* decoder, const Value& array_obj,
const ArrayIndexImmediate<validate>& imm, const Value& index, const ArrayIndexImmediate<validate>& imm, const Value& index,
bool is_signed, Value* result) { bool is_signed, Value* result) {
using CheckForNull = compiler::WasmGraphBuilder::CheckForNull;
CheckForNull null_check = array_obj.type.is_nullable()
? CheckForNull::kWithNullCheck
: CheckForNull::kWithoutNullCheck;
result->node = BUILD(ArrayGet, array_obj.node, imm.array_type, index.node, result->node = BUILD(ArrayGet, array_obj.node, imm.array_type, index.node,
is_signed, decoder->position()); null_check, is_signed, decoder->position());
} }
void ArraySet(FullDecoder* decoder, const Value& array_obj, void ArraySet(FullDecoder* decoder, const Value& array_obj,
const ArrayIndexImmediate<validate>& imm, const Value& index, const ArrayIndexImmediate<validate>& imm, const Value& index,
const Value& value) { const Value& value) {
using CheckForNull = compiler::WasmGraphBuilder::CheckForNull;
CheckForNull null_check = array_obj.type.is_nullable()
? CheckForNull::kWithNullCheck
: CheckForNull::kWithoutNullCheck;
BUILD(ArraySet, array_obj.node, imm.array_type, index.node, value.node, BUILD(ArraySet, array_obj.node, imm.array_type, index.node, value.node,
decoder->position()); null_check, decoder->position());
} }
void ArrayLen(FullDecoder* decoder, const Value& array_obj, Value* result) { void ArrayLen(FullDecoder* decoder, const Value& array_obj, Value* result) {
......
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