Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(367)

Unified Diff: src/compiler/typer.cc

Issue 786703002: [turbofan] Improve typing of JSToNumber. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/typer.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/typer.cc
diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc
index e5b7b839708ec537d23ce6978b99712ea45dc148..710487134edeff341d94e6b06b0f783962fe229c 100644
--- a/src/compiler/typer.cc
+++ b/src/compiler/typer.cc
@@ -162,11 +162,13 @@ Typer::Typer(Graph* graph, MaybeHandle<Context> context)
Type::Constant(minusinfinity, zone), zone),
nan_or_minuszero, zone);
+ boolean_or_number = Type::Union(Type::Boolean(), Type::Number(), zone);
+ undefined_or_null = Type::Union(Type::Undefined(), Type::Null(), zone);
+ undefined_or_number = Type::Union(Type::Undefined(), Type::Number(), zone);
negative_signed32 = Type::Union(
Type::SignedSmall(), Type::OtherSigned32(), zone);
non_negative_signed32 = Type::Union(
Type::UnsignedSmall(), Type::OtherUnsigned31(), zone);
- undefined_or_null = Type::Union(Type::Undefined(), Type::Null(), zone);
singleton_false = Type::Constant(f->false_value(), zone);
singleton_true = Type::Constant(f->true_value(), zone);
singleton_zero = Type::Range(zero, zero, zone);
@@ -520,10 +522,22 @@ Type* Typer::Visitor::ToBoolean(Type* type, Typer* t) {
Type* Typer::Visitor::ToNumber(Type* type, Typer* t) {
if (type->Is(Type::Number())) return type;
+ if (type->Is(Type::Null())) return t->singleton_zero;
if (type->Is(Type::Undefined())) return Type::NaN();
+ if (type->Is(t->undefined_or_null)) {
+ return Type::Union(Type::NaN(), t->singleton_zero, t->zone());
+ }
+ if (type->Is(t->undefined_or_number)) {
+ return Type::Union(Type::Intersect(type, Type::Number(), t->zone()),
+ Type::NaN(), t->zone());
+ }
if (type->Is(t->singleton_false)) return t->singleton_zero;
if (type->Is(t->singleton_true)) return t->singleton_one;
if (type->Is(Type::Boolean())) return t->zero_or_one;
+ if (type->Is(t->boolean_or_number)) {
+ return Type::Union(Type::Intersect(type, Type::Number(), t->zone()),
+ t->zero_or_one, t->zone());
+ }
return Type::Number();
}
@@ -1172,7 +1186,7 @@ Bounds Typer::Visitor::TypeJSToBoolean(Node* node) {
Bounds Typer::Visitor::TypeJSToNumber(Node* node) {
- return Bounds(Type::None(zone()), Type::Number(zone()));
+ return TypeUnaryOp(node, ToNumber);
}
« no previous file with comments | « src/compiler/typer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698