Skip to content

Commit

Permalink
[maglev] Support LogicalNot
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
victorgomes authored and V8 LUCI CQ committed Jul 15, 2022
1 parent 2db0c1c commit dc0ef86
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/maglev/maglev-graph-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions src/maglev/maglev-graph-verifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
29 changes: 29 additions & 0 deletions src/maglev/maglev-ir.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
14 changes: 14 additions & 0 deletions src/maglev/maglev-ir.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class CompactInterpreterFrameState;
V(ChangeInt32ToFloat64) \
V(Float64Box) \
V(CheckedFloat64Unbox) \
V(LogicalNot) \
V(TaggedEqual) \
V(TestInstanceOf) \
V(TestUndetectable) \
Expand Down Expand Up @@ -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>;

Expand Down

0 comments on commit dc0ef86

Please sign in to comment.