[maglev] Support LogicalNot

Bug: v8:7700
Change-Id: Ia8a924d4254deb6782774b882b0abbc6e3f48fb5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3762568
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Auto-Submit: Victor Gomes <victorgomes@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81744}
This commit is contained in:
Victor Gomes 2022-07-15 09:02:11 +02:00 committed by V8 LUCI CQ
parent 2db0c1c6a2
commit dc0ef86bf8
4 changed files with 59 additions and 1 deletions

View File

@ -1265,7 +1265,21 @@ void MaglevGraphBuilder::VisitBitwiseNot() {
}
MAGLEV_UNIMPLEMENTED_BYTECODE(ToBooleanLogicalNot)
MAGLEV_UNIMPLEMENTED_BYTECODE(LogicalNot)
void MaglevGraphBuilder::VisitLogicalNot() {
// Invariant: accumulator must already be a boolean value.
ValueNode* value = GetAccumulatorTagged();
if (RootConstant* constant = value->TryCast<RootConstant>()) {
if (constant->index() == RootIndex::kTrueValue) {
SetAccumulator(GetRootConstant(RootIndex::kFalseValue));
} else {
DCHECK_EQ(constant->index(), RootIndex::kFalseValue);
SetAccumulator(GetRootConstant(RootIndex::kTrueValue));
}
}
SetAccumulator(AddNewNode<LogicalNot>({value}));
}
MAGLEV_UNIMPLEMENTED_BYTECODE(TypeOf)
MAGLEV_UNIMPLEMENTED_BYTECODE(DeletePropertyStrict)
MAGLEV_UNIMPLEMENTED_BYTECODE(DeletePropertySloppy)

View File

@ -105,6 +105,7 @@ class MaglevGraphVerifier {
case Opcode::kCreateFunctionContext:
case Opcode::kCreateClosure:
case Opcode::kFastCreateClosure:
case Opcode::kLogicalNot:
case Opcode::kTestUndetectable:
case Opcode::kReturn:
DCHECK_EQ(node->input_count(), 1);

View File

@ -1718,6 +1718,35 @@ void CheckedFloat64Unbox::GenerateCode(MaglevCodeGenState* code_gen_state,
__ bind(&done);
}
void LogicalNot::AllocateVreg(MaglevVregAllocationState* vreg_state) {
UseRegister(value());
DefineAsRegister(vreg_state, this);
}
void LogicalNot::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) {
Register object = ToRegister(value());
Register return_value = ToRegister(result());
Label not_equal_true;
// We load the constant true to the return value and we return it if the
// object is not equal to it. Otherwise we load the constant false.
__ LoadRoot(return_value, RootIndex::kTrueValue);
__ cmp_tagged(return_value, object);
__ j(not_equal, &not_equal_true);
__ LoadRoot(return_value, RootIndex::kFalseValue);
if (FLAG_debug_code) {
Label is_equal_true;
__ jmp(&is_equal_true);
__ bind(&not_equal_true);
// LogicalNot expects either the constants true or false.
// We know it is not true, so it must be false!
__ CompareRoot(object, RootIndex::kFalseValue);
__ Check(equal, AbortReason::kUnexpectedValue);
__ bind(&is_equal_true);
} else {
__ bind(&not_equal_true);
}
}
void TaggedEqual::AllocateVreg(MaglevVregAllocationState* vreg_state) {
UseRegister(lhs());
UseRegister(rhs());

View File

@ -145,6 +145,7 @@ class CompactInterpreterFrameState;
V(ChangeInt32ToFloat64) \
V(Float64Box) \
V(CheckedFloat64Unbox) \
V(LogicalNot) \
V(TaggedEqual) \
V(TestInstanceOf) \
V(TestUndetectable) \
@ -1544,6 +1545,19 @@ class CheckedFloat64Unbox
void PrintParams(std::ostream&, MaglevGraphLabeller*) const {}
};
class LogicalNot : public FixedInputValueNodeT<1, LogicalNot> {
using Base = FixedInputValueNodeT<1, LogicalNot>;
public:
explicit LogicalNot(uint64_t bitfield) : Base(bitfield) {}
Input& value() { return Node::input(0); }
void AllocateVreg(MaglevVregAllocationState*);
void GenerateCode(MaglevCodeGenState*, const ProcessingState&);
void PrintParams(std::ostream&, MaglevGraphLabeller*) const {}
};
class TaggedEqual : public FixedInputValueNodeT<2, TaggedEqual> {
using Base = FixedInputValueNodeT<2, TaggedEqual>;