Commit 09fb5686 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Properly recognize and optimize comparisons with the_hole.

We use comparisons with the_hole to implement temporal dead zones, so we
should also optimize those, as they currently turn into CompareIC calls.

R=jarin@chromium.org

Review URL: https://codereview.chromium.org/1473593002

Cr-Commit-Position: refs/heads/master@{#32198}
parent 4620a235
...@@ -427,6 +427,8 @@ JSTypedLowering::JSTypedLowering(Editor* editor, ...@@ -427,6 +427,8 @@ JSTypedLowering::JSTypedLowering(Editor* editor,
dependencies_(dependencies), dependencies_(dependencies),
flags_(flags), flags_(flags),
jsgraph_(jsgraph), jsgraph_(jsgraph),
the_hole_type_(
Type::Constant(factory()->the_hole_value(), graph()->zone())),
type_cache_(TypeCache::Get()) { type_cache_(TypeCache::Get()) {
for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) { for (size_t k = 0; k < arraysize(shifted_int32_ranges_); ++k) {
double min = kMinInt / (1 << k); double min = kMinInt / (1 << k);
...@@ -657,6 +659,10 @@ Reduction JSTypedLowering::ReduceJSStrictEqual(Node* node, bool invert) { ...@@ -657,6 +659,10 @@ Reduction JSTypedLowering::ReduceJSStrictEqual(Node* node, bool invert) {
return Replace(replacement); return Replace(replacement);
} }
} }
if (r.OneInputIs(the_hole_type_)) {
return r.ChangeToPureOperator(simplified()->ReferenceEqual(the_hole_type_),
invert);
}
if (r.OneInputIs(Type::Undefined())) { if (r.OneInputIs(Type::Undefined())) {
return r.ChangeToPureOperator( return r.ChangeToPureOperator(
simplified()->ReferenceEqual(Type::Undefined()), invert); simplified()->ReferenceEqual(Type::Undefined()), invert);
......
...@@ -118,6 +118,7 @@ class JSTypedLowering final : public AdvancedReducer { ...@@ -118,6 +118,7 @@ class JSTypedLowering final : public AdvancedReducer {
Flags flags_; Flags flags_;
JSGraph* jsgraph_; JSGraph* jsgraph_;
Type* shifted_int32_ranges_[4]; Type* shifted_int32_ranges_[4];
Type* const the_hole_type_;
TypeCache const& type_cache_; TypeCache const& type_cache_;
}; };
......
...@@ -54,12 +54,15 @@ Typer::Typer(Isolate* isolate, Graph* graph, Flags flags, ...@@ -54,12 +54,15 @@ Typer::Typer(Isolate* isolate, Graph* graph, Flags flags,
singleton_false_ = Type::Constant(factory->false_value(), zone); singleton_false_ = Type::Constant(factory->false_value(), zone);
singleton_true_ = Type::Constant(factory->true_value(), zone); singleton_true_ = Type::Constant(factory->true_value(), zone);
singleton_the_hole_ = Type::Constant(factory->the_hole_value(), zone);
signed32ish_ = Type::Union(Type::Signed32(), truncating_to_zero, zone); signed32ish_ = Type::Union(Type::Signed32(), truncating_to_zero, zone);
unsigned32ish_ = Type::Union(Type::Unsigned32(), truncating_to_zero, zone); unsigned32ish_ = Type::Union(Type::Unsigned32(), truncating_to_zero, zone);
falsish_ = Type::Union( falsish_ = Type::Union(
Type::Undetectable(), Type::Undetectable(),
Type::Union(Type::Union(singleton_false_, cache_.kZeroish, zone), Type::Union(
Type::NullOrUndefined(), zone), Type::Union(Type::Union(singleton_false_, cache_.kZeroish, zone),
Type::NullOrUndefined(), zone),
singleton_the_hole_, zone),
zone); zone);
truish_ = Type::Union( truish_ = Type::Union(
singleton_true_, singleton_true_,
...@@ -697,6 +700,10 @@ Type* Typer::Visitor::JSStrictEqualTyper(Type* lhs, Type* rhs, Typer* t) { ...@@ -697,6 +700,10 @@ Type* Typer::Visitor::JSStrictEqualTyper(Type* lhs, Type* rhs, Typer* t) {
(lhs->Max() < rhs->Min() || lhs->Min() > rhs->Max())) { (lhs->Max() < rhs->Min() || lhs->Min() > rhs->Max())) {
return t->singleton_false_; return t->singleton_false_;
} }
if ((lhs->Is(t->singleton_the_hole_) || rhs->Is(t->singleton_the_hole_)) &&
!lhs->Maybe(rhs)) {
return t->singleton_false_;
}
if (lhs->IsConstant() && rhs->Is(lhs)) { if (lhs->IsConstant() && rhs->Is(lhs)) {
// Types are equal and are inhabited only by a single semantic value, // Types are equal and are inhabited only by a single semantic value,
// which is not nan due to the earlier check. // which is not nan due to the earlier check.
......
...@@ -58,6 +58,7 @@ class Typer { ...@@ -58,6 +58,7 @@ class Typer {
Type* singleton_false_; Type* singleton_false_;
Type* singleton_true_; Type* singleton_true_;
Type* singleton_the_hole_;
Type* signed32ish_; Type* signed32ish_;
Type* unsigned32ish_; Type* unsigned32ish_;
Type* falsish_; Type* falsish_;
......
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