Commit 95db8643 authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Improve typing rules for NumberFloor and NumberDivide.

Also rule out -0 for NumberDivide if possible, and rule out NaN and -0
for NumberFloor if possible.

R=jarin@chromium.org
BUG=v8:5267

Review-Url: https://codereview.chromium.org/2609373002
Cr-Commit-Position: refs/heads/master@{#42059}
parent c1a0e856
......@@ -366,8 +366,9 @@ Type* OperationTyper::NumberExpm1(Type* type) {
Type* OperationTyper::NumberFloor(Type* type) {
DCHECK(type->Is(Type::Number()));
if (type->Is(cache_.kIntegerOrMinusZeroOrNaN)) return type;
// TODO(bmeurer): We could infer a more precise type here.
return cache_.kIntegerOrMinusZeroOrNaN;
type = Type::Intersect(type, Type::MinusZeroOrNaN(), zone());
type = Type::Union(type, cache_.kInteger, zone());
return type;
}
Type* OperationTyper::NumberFround(Type* type) {
......@@ -624,12 +625,19 @@ Type* OperationTyper::NumberDivide(Type* lhs, Type* rhs) {
}
if (lhs->Is(Type::NaN()) || rhs->Is(Type::NaN())) return Type::NaN();
// Division is tricky, so all we do is try ruling out nan.
// Division is tricky, so all we do is try ruling out -0 and NaN.
bool maybe_minuszero = !lhs->Is(cache_.kPositiveIntegerOrNaN) ||
!rhs->Is(cache_.kPositiveIntegerOrNaN);
bool maybe_nan =
lhs->Maybe(Type::NaN()) || rhs->Maybe(cache_.kZeroish) ||
((lhs->Min() == -V8_INFINITY || lhs->Max() == +V8_INFINITY) &&
(rhs->Min() == -V8_INFINITY || rhs->Max() == +V8_INFINITY));
return maybe_nan ? Type::Number() : Type::OrderedNumber();
// Take into account the -0 and NaN information computed earlier.
Type* type = Type::PlainNumber();
if (maybe_minuszero) type = Type::Union(type, Type::MinusZero(), zone());
if (maybe_nan) type = Type::Union(type, Type::NaN(), zone());
return type;
}
Type* OperationTyper::NumberModulus(Type* lhs, Type* rhs) {
......
......@@ -64,6 +64,8 @@ class TypeCache final {
Type* const kPositiveInteger = CreateRange(0.0, V8_INFINITY);
Type* const kPositiveIntegerOrMinusZero =
Type::Union(kPositiveInteger, Type::MinusZero(), zone());
Type* const kPositiveIntegerOrNaN =
Type::Union(kPositiveInteger, Type::NaN(), zone());
Type* const kPositiveIntegerOrMinusZeroOrNaN =
Type::Union(kPositiveIntegerOrMinusZero, Type::NaN(), zone());
......
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