Commit a148861c authored by Michael Starzinger's avatar Michael Starzinger Committed by Commit Bot

[turbofan] Handle equality comparison in early lowering.

This handles non-strict equality comparison operations having number
feedback during the early type-hint lowering (i.e. during graph
construction).

R=jarin@chromium.org

Change-Id: I1db67e78312934bbb20aee775979797420ff2581
Reviewed-on: https://chromium-review.googlesource.com/455796Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#43824}
parent b7b2975e
......@@ -112,6 +112,8 @@ class JSSpeculativeBinopBuilder final {
const Operator* SpeculativeCompareOp(NumberOperationHint hint) {
switch (op_->opcode()) {
case IrOpcode::kJSEqual:
return simplified()->SpeculativeNumberEqual(hint);
case IrOpcode::kJSLessThan:
return simplified()->SpeculativeNumberLessThan(hint);
case IrOpcode::kJSGreaterThan:
......@@ -188,9 +190,9 @@ Reduction JSTypeHintLowering::ReduceBinaryOperation(const Operator* op,
Node* effect, Node* control,
FeedbackSlot slot) {
switch (op->opcode()) {
case IrOpcode::kJSEqual:
case IrOpcode::kJSStrictEqual:
break;
case IrOpcode::kJSEqual:
case IrOpcode::kJSLessThan:
case IrOpcode::kJSGreaterThan:
case IrOpcode::kJSLessThanOrEqual:
......
......@@ -312,6 +312,8 @@ class JSBinopReduction final {
const Operator* NumberOpFromSpeculativeNumberOp() {
switch (node_->opcode()) {
case IrOpcode::kSpeculativeNumberEqual:
return simplified()->NumberEqual();
case IrOpcode::kSpeculativeNumberLessThan:
return simplified()->NumberLessThan();
case IrOpcode::kSpeculativeNumberLessThanOrEqual:
......@@ -923,13 +925,9 @@ Reduction JSTypedLowering::ReduceJSEqual(Node* node) {
return Changed(node);
}
NumberOperationHint hint;
if (r.BothInputsAre(Type::Signed32()) ||
r.BothInputsAre(Type::Unsigned32())) {
return r.ChangeToPureOperator(simplified()->NumberEqual());
} else if (r.GetCompareNumberOperationHint(&hint)) {
return r.ChangeToSpeculativeOperator(
simplified()->SpeculativeNumberEqual(hint), Type::Boolean());
} else if (r.BothInputsAre(Type::Number())) {
return r.ChangeToPureOperator(simplified()->NumberEqual());
} else if (r.IsReceiverCompareOperation()) {
......@@ -2404,6 +2402,7 @@ Reduction JSTypedLowering::Reduce(Node* node) {
case IrOpcode::kSpeculativeNumberDivide:
case IrOpcode::kSpeculativeNumberModulus:
return ReduceSpeculativeNumberBinop(node);
case IrOpcode::kSpeculativeNumberEqual:
case IrOpcode::kSpeculativeNumberLessThan:
case IrOpcode::kSpeculativeNumberLessThanOrEqual:
return ReduceSpeculativeNumberComparison(node);
......
......@@ -302,6 +302,7 @@ class Typer::Visitor : public Reducer {
static Type* JSCallTyper(Type*, Typer*);
static Type* NumberEqualTyper(Type*, Type*, Typer*);
static Type* NumberLessThanTyper(Type*, Type*, Typer*);
static Type* NumberLessThanOrEqualTyper(Type*, Type*, Typer*);
static Type* ReferenceEqualTyper(Type*, Type*, Typer*);
......@@ -1697,7 +1698,10 @@ Type* Typer::Visitor::TypeJSDebugger(Node* node) { return Type::Any(); }
Type* Typer::Visitor::TypeBooleanNot(Node* node) { return Type::Boolean(); }
Type* Typer::Visitor::TypeNumberEqual(Node* node) { return Type::Boolean(); }
// static
Type* Typer::Visitor::NumberEqualTyper(Type* lhs, Type* rhs, Typer* t) {
return JSEqualTyper(ToNumber(lhs, t), ToNumber(rhs, t), t);
}
// static
Type* Typer::Visitor::NumberLessThanTyper(Type* lhs, Type* rhs, Typer* t) {
......@@ -1712,6 +1716,10 @@ Type* Typer::Visitor::NumberLessThanOrEqualTyper(Type* lhs, Type* rhs,
Invert(JSCompareTyper(ToNumber(rhs, t), ToNumber(lhs, t), t), t), t);
}
Type* Typer::Visitor::TypeNumberEqual(Node* node) {
return TypeBinaryOp(node, NumberEqualTyper);
}
Type* Typer::Visitor::TypeNumberLessThan(Node* node) {
return TypeBinaryOp(node, NumberLessThanTyper);
}
......@@ -1721,7 +1729,7 @@ Type* Typer::Visitor::TypeNumberLessThanOrEqual(Node* node) {
}
Type* Typer::Visitor::TypeSpeculativeNumberEqual(Node* node) {
return Type::Boolean();
return TypeBinaryOp(node, NumberEqualTyper);
}
Type* Typer::Visitor::TypeSpeculativeNumberLessThan(Node* node) {
......
......@@ -352,6 +352,15 @@ TEST_F(TyperTest, TypeJSEqual) {
std::equal_to<double>());
}
TEST_F(TyperTest, TypeNumberEqual) {
TestBinaryCompareOp(simplified_.NumberEqual(), std::equal_to<double>());
}
TEST_F(TyperTest, TypeSpeculativeNumberEqual) {
TestBinaryCompareOp(
simplified_.SpeculativeNumberEqual(NumberOperationHint::kNumberOrOddball),
std::equal_to<double>());
}
// For numbers there's no difference between strict and non-strict equality.
TEST_F(TyperTest, TypeJSStrictEqual) {
......
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