Commit c0ff58e0 authored by Victor Gomes's avatar Victor Gomes Committed by V8 LUCI CQ

[maglev] Support TestReferenceEqual, TestNull and TestUndefined

Bug: v8:7700
Change-Id: I07e63a33e1ef1ab8e423bf46be1d83b8724d924d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3760449
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81695}
parent 74289c46
......@@ -631,10 +631,46 @@ void MaglevGraphBuilder::VisitPopContext() {
SetContext(LoadRegisterTagged(0));
}
MAGLEV_UNIMPLEMENTED_BYTECODE(TestReferenceEqual)
void MaglevGraphBuilder::VisitTestReferenceEqual() {
ValueNode* lhs = LoadRegisterTagged(0);
ValueNode* rhs = GetAccumulatorTagged();
if (lhs == rhs) {
SetAccumulator(GetRootConstant(RootIndex::kTrueValue));
return;
}
SetAccumulator(AddNewNode<TaggedEqual>({lhs, rhs}));
}
MAGLEV_UNIMPLEMENTED_BYTECODE(TestUndetectable)
MAGLEV_UNIMPLEMENTED_BYTECODE(TestNull)
MAGLEV_UNIMPLEMENTED_BYTECODE(TestUndefined)
void MaglevGraphBuilder::VisitTestNull() {
ValueNode* value = GetAccumulatorTagged();
if (RootConstant* constant = value->TryCast<RootConstant>()) {
if (constant->index() == RootIndex::kNullValue) {
SetAccumulator(GetRootConstant(RootIndex::kTrueValue));
} else {
SetAccumulator(GetRootConstant(RootIndex::kFalseValue));
}
return;
}
ValueNode* null_constant = GetRootConstant(RootIndex::kNullValue);
SetAccumulator(AddNewNode<TaggedEqual>({value, null_constant}));
}
void MaglevGraphBuilder::VisitTestUndefined() {
ValueNode* value = GetAccumulatorTagged();
if (RootConstant* constant = value->TryCast<RootConstant>()) {
if (constant->index() == RootIndex::kUndefinedValue) {
SetAccumulator(GetRootConstant(RootIndex::kTrueValue));
} else {
SetAccumulator(GetRootConstant(RootIndex::kFalseValue));
}
return;
}
ValueNode* undefined_constant = GetRootConstant(RootIndex::kUndefinedValue);
SetAccumulator(AddNewNode<TaggedEqual>({value, undefined_constant}));
}
MAGLEV_UNIMPLEMENTED_BYTECODE(TestTypeOf)
bool MaglevGraphBuilder::TryBuildPropertyCellAccess(
......
......@@ -138,6 +138,7 @@ class MaglevGraphVerifier {
case Opcode::kGenericLessThan:
case Opcode::kGenericLessThanOrEqual:
case Opcode::kGenericStrictEqual:
case Opcode::kTaggedEqual:
// TODO(victorgomes): Can we check that first input is an Object?
case Opcode::kStoreTaggedFieldNoWriteBarrier:
// TODO(victorgomes): Can we check that second input is a Smi?
......
......@@ -1708,6 +1708,23 @@ void CheckedFloat64Unbox::GenerateCode(MaglevCodeGenState* code_gen_state,
__ bind(&done);
}
void TaggedEqual::AllocateVreg(MaglevVregAllocationState* vreg_state) {
UseRegister(lhs());
UseRegister(rhs());
DefineAsRegister(vreg_state, this);
}
void TaggedEqual::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) {
Label done, if_equal;
__ cmp_tagged(ToRegister(lhs()), ToRegister(rhs()));
__ j(equal, &if_equal, Label::kNear);
__ LoadRoot(ToRegister(result()), RootIndex::kFalseValue);
__ jmp(&done, Label::kNear);
__ bind(&if_equal);
__ LoadRoot(ToRegister(result()), RootIndex::kTrueValue);
__ bind(&done);
}
void ChangeInt32ToFloat64::AllocateVreg(MaglevVregAllocationState* vreg_state) {
UseRegister(input());
DefineAsRegister(vreg_state, this);
......
......@@ -144,6 +144,7 @@ class CompactInterpreterFrameState;
V(ChangeInt32ToFloat64) \
V(Float64Box) \
V(CheckedFloat64Unbox) \
V(TaggedEqual) \
CONSTANT_VALUE_NODE_LIST(V) \
INT32_OPERATIONS_NODE_LIST(V) \
FLOAT64_OPERATIONS_NODE_LIST(V) \
......@@ -1539,6 +1540,20 @@ class CheckedFloat64Unbox
void PrintParams(std::ostream&, MaglevGraphLabeller*) const {}
};
class TaggedEqual : public FixedInputValueNodeT<2, TaggedEqual> {
using Base = FixedInputValueNodeT<2, TaggedEqual>;
public:
explicit TaggedEqual(uint64_t bitfield) : Base(bitfield) {}
Input& lhs() { return Node::input(0); }
Input& rhs() { return Node::input(1); }
void AllocateVreg(MaglevVregAllocationState*);
void GenerateCode(MaglevCodeGenState*, const ProcessingState&);
void PrintParams(std::ostream&, MaglevGraphLabeller*) const {}
};
class InitialValue : public FixedInputValueNodeT<0, InitialValue> {
using Base = FixedInputValueNodeT<0, InitialValue>;
......
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