Commit 1a183417 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[turbofan] Avoid widening type when reducing JSStrictEqual

We don't ever want a node's type to become less precise.

Also move a part of JSTypedLowering::ReduceJSStrictEqual that
can be expressed solely in terms of types into the typer, where
it generalizes an existing case.

Change-Id: I37c58fed48f606f6fe34e98e5f066434e50cb6c1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2106204
Auto-Submit: Georg Neis <neis@chromium.org>
Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66763}
parent 94611e8a
......@@ -848,24 +848,19 @@ Reduction JSTypedLowering::ReduceJSEqual(Node* node) {
Reduction JSTypedLowering::ReduceJSStrictEqual(Node* node) {
JSBinopReduction r(this, node);
if (r.type().IsSingleton()) {
// Let ConstantFoldingReducer handle this.
return NoChange();
}
if (r.left() == r.right()) {
// x === x is always true if x != NaN
Node* replacement = graph()->NewNode(
simplified()->BooleanNot(),
graph()->NewNode(simplified()->ObjectIsNaN(), r.left()));
DCHECK(NodeProperties::GetType(replacement).Is(r.type()));
ReplaceWithValue(node, replacement);
return Replace(replacement);
}
if (r.OneInputCannotBe(Type::NumericOrString())) {
// For values with canonical representation (i.e. neither String nor
// Numeric) an empty type intersection means the values cannot be strictly
// equal.
if (!r.left_type().Maybe(r.right_type())) {
Node* replacement = jsgraph()->FalseConstant();
ReplaceWithValue(node, replacement);
return Replace(replacement);
}
}
if (r.BothInputsAre(Type::Unique())) {
return r.ChangeToPureOperator(simplified()->ReferenceEqual());
......
......@@ -1239,9 +1239,6 @@ Type OperationTyper::StrictEqual(Type lhs, Type rhs) {
(lhs.Max() < rhs.Min() || lhs.Min() > rhs.Max())) {
return singleton_false();
}
if ((lhs.Is(Type::Hole()) || rhs.Is(Type::Hole())) && !lhs.Maybe(rhs)) {
return singleton_false();
}
if (lhs.IsSingleton() && rhs.Is(lhs)) {
// Types are equal and are inhabited only by a single semantic value,
// which is not nan due to the earlier check.
......@@ -1249,6 +1246,12 @@ Type OperationTyper::StrictEqual(Type lhs, Type rhs) {
DCHECK(lhs.Is(Type::NonInternal()) || lhs.Is(Type::Hole()));
return singleton_true();
}
if ((!lhs.Maybe(Type::NumericOrString()) ||
!rhs.Maybe(Type::NumericOrString())) &&
!lhs.Maybe(rhs)) {
// One of the inputs has a canonical representation but types don't overlap.
return singleton_false();
}
return Type::Boolean();
}
......
......@@ -1593,7 +1593,7 @@ void Verifier::Visitor::Check(Node* node, const AllNodes& all) {
if (typing == TYPED) {
Type type = NodeProperties::GetType(node);
CHECK(type.IsSingleton());
CHECK(type.Is(NodeProperties::GetType(node->InputAt(0))));
CHECK(type.Equals(NodeProperties::GetType(node->InputAt(0))));
CHECK(type.Equals(NodeProperties::GetType(node->InputAt(1))));
}
break;
......
......@@ -174,8 +174,7 @@ TEST_F(JSTypedLoweringTest, JSStrictEqualWithTheHole) {
Reduction r = Reduce(
graph()->NewNode(javascript()->StrictEqual(CompareOperationHint::kAny),
lhs, the_hole, context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsFalseConstant());
ASSERT_FALSE(r.Changed());
}
}
......
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