Commit 5bd8407f authored by jarin's avatar jarin Committed by Commit bot

Reland of "Steps towards unification of number bitset and range types."

This reverts commit 76193749.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#26301}
parent aa609b54
...@@ -163,7 +163,7 @@ Reduction ChangeLowering::ChangeInt32ToTagged(Node* value, Node* control) { ...@@ -163,7 +163,7 @@ Reduction ChangeLowering::ChangeInt32ToTagged(Node* value, Node* control) {
machine()->Word64Shl(), machine()->Word64Shl(),
graph()->NewNode(machine()->ChangeInt32ToInt64(), value), graph()->NewNode(machine()->ChangeInt32ToInt64(), value),
SmiShiftBitsConstant())); SmiShiftBitsConstant()));
} else if (NodeProperties::GetBounds(value).upper->Is(Type::SignedSmall())) { } else if (NodeProperties::GetBounds(value).upper->Is(Type::Signed31())) {
return Replace( return Replace(
graph()->NewNode(machine()->WordShl(), value, SmiShiftBitsConstant())); graph()->NewNode(machine()->WordShl(), value, SmiShiftBitsConstant()));
} }
......
...@@ -895,12 +895,12 @@ Type* Typer::Visitor::JSBitwiseXorTyper(Type* lhs, Type* rhs, Typer* t) { ...@@ -895,12 +895,12 @@ Type* Typer::Visitor::JSBitwiseXorTyper(Type* lhs, Type* rhs, Typer* t) {
double rmax = rhs->Max(); double rmax = rhs->Max();
if ((lmin >= 0 && rmin >= 0) || (lmax < 0 && rmax < 0)) { if ((lmin >= 0 && rmin >= 0) || (lmax < 0 && rmax < 0)) {
// Xor-ing negative or non-negative values results in a non-negative value. // Xor-ing negative or non-negative values results in a non-negative value.
return Type::NonNegativeSigned32(); return Type::Unsigned31();
} }
if ((lmax < 0 && rmin >= 0) || (lmin >= 0 && rmax < 0)) { if ((lmax < 0 && rmin >= 0) || (lmin >= 0 && rmax < 0)) {
// Xor-ing a negative and a non-negative value results in a negative value. // Xor-ing a negative and a non-negative value results in a negative value.
// TODO(jarin) Use a range here. // TODO(jarin) Use a range here.
return Type::NegativeSigned32(); return Type::Negative32();
} }
return Type::Signed32(); return Type::Signed32();
} }
...@@ -1271,9 +1271,22 @@ Bounds Typer::Visitor::TypeJSLoadNamed(Node* node) { ...@@ -1271,9 +1271,22 @@ Bounds Typer::Visitor::TypeJSLoadNamed(Node* node) {
// in the graph. In the current implementation, we are // in the graph. In the current implementation, we are
// increasing the limits to the closest power of two. // increasing the limits to the closest power of two.
Type* Typer::Visitor::Weaken(Type* current_type, Type* previous_type) { Type* Typer::Visitor::Weaken(Type* current_type, Type* previous_type) {
Type::RangeType* previous = previous_type->GetRange(); // If the types have nothing to do with integers, return the types.
Type::RangeType* current = current_type->GetRange(); if (!current_type->Maybe(typer_->integer) ||
if (previous != NULL && current != NULL) { !previous_type->Maybe(typer_->integer)) {
return current_type;
}
Type* previous_number =
Type::Intersect(previous_type, typer_->integer, zone());
Type* current_number = Type::Intersect(current_type, typer_->integer, zone());
if (!current_number->IsRange() || !previous_number->IsRange()) {
return current_type;
}
Type::RangeType* previous = previous_number->AsRange();
Type::RangeType* current = current_number->AsRange();
double current_min = current->Min()->Number(); double current_min = current->Min()->Number();
Handle<Object> new_min = current->Min(); Handle<Object> new_min = current->Min();
...@@ -1306,8 +1319,6 @@ Type* Typer::Visitor::Weaken(Type* current_type, Type* previous_type) { ...@@ -1306,8 +1319,6 @@ Type* Typer::Visitor::Weaken(Type* current_type, Type* previous_type) {
return Type::Union(current_type, return Type::Union(current_type,
Type::Range(new_min, new_max, typer_->zone()), Type::Range(new_min, new_max, typer_->zone()),
typer_->zone()); typer_->zone());
}
return current_type;
} }
......
...@@ -16,6 +16,19 @@ namespace internal { ...@@ -16,6 +16,19 @@ namespace internal {
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// TypeImpl // TypeImpl
template <class Config>
typename TypeImpl<Config>::bitset TypeImpl<Config>::BitsetType::SignedSmall() {
return i::SmiValuesAre31Bits() ? kSigned31 : kSigned32;
}
template <class Config>
typename TypeImpl<Config>::bitset
TypeImpl<Config>::BitsetType::UnsignedSmall() {
return i::SmiValuesAre31Bits() ? kUnsigned30 : kUnsigned31;
}
template<class Config> template<class Config>
TypeImpl<Config>* TypeImpl<Config>::cast(typename Config::Base* object) { TypeImpl<Config>* TypeImpl<Config>::cast(typename Config::Base* object) {
TypeImpl* t = static_cast<TypeImpl*>(object); TypeImpl* t = static_cast<TypeImpl*>(object);
......
This diff is collapsed.
This diff is collapsed.
...@@ -176,20 +176,17 @@ static Type* kStringTypes[] = {Type::InternalizedString(), Type::OtherString(), ...@@ -176,20 +176,17 @@ static Type* kStringTypes[] = {Type::InternalizedString(), Type::OtherString(),
Type::String()}; Type::String()};
static Type* kInt32Types[] = { static Type* kInt32Types[] = {Type::UnsignedSmall(), Type::Negative32(),
Type::UnsignedSmall(), Type::NegativeSigned32(), Type::Unsigned31(), Type::SignedSmall(),
Type::NonNegativeSigned32(), Type::SignedSmall(),
Type::Signed32(), Type::Unsigned32(), Type::Signed32(), Type::Unsigned32(),
Type::Integral32()}; Type::Integral32()};
static Type* kNumberTypes[] = { static Type* kNumberTypes[] = {
Type::UnsignedSmall(), Type::NegativeSigned32(), Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(),
Type::NonNegativeSigned32(), Type::SignedSmall(), Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(),
Type::Signed32(), Type::Unsigned32(), Type::Integral32(), Type::MinusZero(), Type::NaN(),
Type::Integral32(), Type::MinusZero(), Type::OrderedNumber(), Type::PlainNumber(), Type::Number()};
Type::NaN(), Type::OrderedNumber(),
Type::PlainNumber(), Type::Number()};
static Type* kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(), static Type* kJSTypes[] = {Type::Undefined(), Type::Null(), Type::Boolean(),
...@@ -316,12 +313,11 @@ class JSBitwiseShiftTypedLoweringTester : public JSTypedLoweringTester { ...@@ -316,12 +313,11 @@ class JSBitwiseShiftTypedLoweringTester : public JSTypedLoweringTester {
TEST(Int32BitwiseShifts) { TEST(Int32BitwiseShifts) {
JSBitwiseShiftTypedLoweringTester R; JSBitwiseShiftTypedLoweringTester R;
Type* types[] = {Type::SignedSmall(), Type::UnsignedSmall(), Type* types[] = {
Type::NegativeSigned32(), Type::NonNegativeSigned32(), Type::SignedSmall(), Type::UnsignedSmall(), Type::Negative32(),
Type::Unsigned32(), Type::Signed32(), Type::Unsigned31(), Type::Unsigned32(), Type::Signed32(),
Type::MinusZero(), Type::NaN(), Type::MinusZero(), Type::NaN(), Type::Undefined(),
Type::Undefined(), Type::Null(), Type::Null(), Type::Boolean(), Type::Number(),
Type::Boolean(), Type::Number(),
Type::PlainNumber(), Type::String()}; Type::PlainNumber(), Type::String()};
for (size_t i = 0; i < arraysize(types); ++i) { for (size_t i = 0; i < arraysize(types); ++i) {
......
...@@ -135,6 +135,14 @@ struct Tests : Rep { ...@@ -135,6 +135,14 @@ struct Tests : Rep {
} }
} }
void CheckSubOrEqual(TypeHandle type1, TypeHandle type2) {
CHECK(type1->Is(type2));
if (this->IsBitset(type1) && this->IsBitset(type2)) {
CHECK((this->AsBitset(type1) | this->AsBitset(type2))
== this->AsBitset(type2));
}
}
void CheckUnordered(TypeHandle type1, TypeHandle type2) { void CheckUnordered(TypeHandle type1, TypeHandle type2) {
CHECK(!type1->Is(type2)); CHECK(!type1->Is(type2));
CHECK(!type2->Is(type1)); CHECK(!type2->Is(type1));
...@@ -293,39 +301,33 @@ struct Tests : Rep { ...@@ -293,39 +301,33 @@ struct Tests : Rep {
CHECK(T.Constant(fac->NewNumber(0))->Is(T.UnsignedSmall)); CHECK(T.Constant(fac->NewNumber(0))->Is(T.UnsignedSmall));
CHECK(T.Constant(fac->NewNumber(1))->Is(T.UnsignedSmall)); CHECK(T.Constant(fac->NewNumber(1))->Is(T.UnsignedSmall));
CHECK(T.Constant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall)); CHECK(T.Constant(fac->NewNumber(0x3fffffff))->Is(T.UnsignedSmall));
CHECK(T.Constant(fac->NewNumber(-1))->Is(T.NegativeSignedSmall)); CHECK(T.Constant(fac->NewNumber(-1))->Is(T.Negative31));
CHECK(T.Constant(fac->NewNumber(-0x3fffffff))->Is(T.NegativeSignedSmall)); CHECK(T.Constant(fac->NewNumber(-0x3fffffff))->Is(T.Negative31));
CHECK(T.Constant(fac->NewNumber(-0x40000000))->Is(T.NegativeSignedSmall)); CHECK(T.Constant(fac->NewNumber(-0x40000000))->Is(T.Negative31));
CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.Unsigned31));
CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.Unsigned30));
CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned31));
CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.Unsigned30));
CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.Negative32));
CHECK(!T.Constant(fac->NewNumber(-0x40000001))->Is(T.Negative31));
CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.Negative32));
CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.Negative31));
if (SmiValuesAre31Bits()) { if (SmiValuesAre31Bits()) {
CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.NonNegativeSigned32));
CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); CHECK(!T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall));
CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.NonNegativeSigned32));
CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); CHECK(!T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall));
CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSigned32)); CHECK(!T.Constant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall));
CHECK( CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall));
!T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSignedSmall));
CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSigned32));
CHECK(!T.Constant(fac->NewNumber(-0x7fffffff - 1))
->Is(T.NegativeSignedSmall));
} else { } else {
CHECK(SmiValuesAre32Bits()); CHECK(SmiValuesAre32Bits());
CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall)); CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.UnsignedSmall));
CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall)); CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.UnsignedSmall));
CHECK(T.Constant(fac->NewNumber(0x40000000))->Is(T.NonNegativeSigned32)); CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.SignedSmall));
CHECK(T.Constant(fac->NewNumber(0x7fffffff))->Is(T.NonNegativeSigned32)); CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.SignedSmall));
CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSignedSmall));
CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSignedSmall));
CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 1))
->Is(T.NegativeSignedSmall));
CHECK(T.Constant(fac->NewNumber(-0x40000001))->Is(T.NegativeSigned32));
CHECK(T.Constant(fac->NewNumber(-0x7fffffff))->Is(T.NegativeSigned32));
CHECK(
T.Constant(fac->NewNumber(-0x7fffffff - 1))->Is(T.NegativeSigned32));
} }
CHECK(T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned32)); CHECK(T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned32));
CHECK(!T.Constant(fac->NewNumber(0x80000000u))->Is(T.NonNegativeSigned32)); CHECK(!T.Constant(fac->NewNumber(0x80000000u))->Is(T.Unsigned31));
CHECK(T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned32)); CHECK(T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned32));
CHECK(!T.Constant(fac->NewNumber(0xffffffffu))->Is(T.NonNegativeSigned32)); CHECK(!T.Constant(fac->NewNumber(0xffffffffu))->Is(T.Unsigned31));
CHECK(T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.PlainNumber)); CHECK(T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.PlainNumber));
CHECK(!T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.Integral32)); CHECK(!T.Constant(fac->NewNumber(0xffffffffu + 1.0))->Is(T.Integral32));
CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.PlainNumber)); CHECK(T.Constant(fac->NewNumber(-0x7fffffff - 2.0))->Is(T.PlainNumber));
...@@ -795,6 +797,7 @@ struct Tests : Rep { ...@@ -795,6 +797,7 @@ struct Tests : Rep {
(type1->IsClass() && type2->IsClass()) || (type1->IsClass() && type2->IsClass()) ||
(type1->IsConstant() && type2->IsConstant()) || (type1->IsConstant() && type2->IsConstant()) ||
(type1->IsConstant() && type2->IsRange()) || (type1->IsConstant() && type2->IsRange()) ||
(this->IsBitset(type1) && type2->IsRange()) ||
(type1->IsRange() && type2->IsRange()) || (type1->IsRange() && type2->IsRange()) ||
(type1->IsContext() && type2->IsContext()) || (type1->IsContext() && type2->IsContext()) ||
(type1->IsArray() && type2->IsArray()) || (type1->IsArray() && type2->IsArray()) ||
...@@ -933,7 +936,7 @@ struct Tests : Rep { ...@@ -933,7 +936,7 @@ struct Tests : Rep {
CheckSub(T.SignedSmall, T.Number); CheckSub(T.SignedSmall, T.Number);
CheckSub(T.Signed32, T.Number); CheckSub(T.Signed32, T.Number);
CheckSub(T.SignedSmall, T.Signed32); CheckSubOrEqual(T.SignedSmall, T.Signed32);
CheckUnordered(T.SignedSmall, T.MinusZero); CheckUnordered(T.SignedSmall, T.MinusZero);
CheckUnordered(T.Signed32, T.Unsigned32); CheckUnordered(T.Signed32, T.Unsigned32);
...@@ -1477,8 +1480,8 @@ struct Tests : Rep { ...@@ -1477,8 +1480,8 @@ struct Tests : Rep {
CheckDisjoint(T.Union(T.NumberFunction1, T.String), T.Number); CheckDisjoint(T.Union(T.NumberFunction1, T.String), T.Number);
// Bitset-class // Bitset-class
CheckSub( CheckSub(T.Union(T.ObjectClass, T.SignedSmall),
T.Union(T.ObjectClass, T.SignedSmall), T.Union(T.Object, T.Number)); T.Union(T.Object, T.Number));
CheckSub(T.Union(T.ObjectClass, T.Array), T.Object); CheckSub(T.Union(T.ObjectClass, T.Array), T.Object);
CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array); CheckUnordered(T.Union(T.ObjectClass, T.String), T.Array);
CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object); CheckOverlap(T.Union(T.ObjectClass, T.String), T.Object);
...@@ -1548,9 +1551,7 @@ struct Tests : Rep { ...@@ -1548,9 +1551,7 @@ struct Tests : Rep {
T.Union(T.ObjectConstant2, T.ObjectConstant1), T.Union(T.ObjectConstant2, T.ObjectConstant1),
T.Union(T.ObjectConstant1, T.ObjectConstant2)), T.Union(T.ObjectConstant1, T.ObjectConstant2)),
T.Union(T.ObjectConstant2, T.ObjectConstant1)); T.Union(T.ObjectConstant2, T.ObjectConstant1));
CheckEqual( CheckEqual(T.Union(T.Union(T.Number, T.ArrayClass),
T.Union(
T.Union(T.Number, T.ArrayClass),
T.Union(T.SignedSmall, T.Array)), T.Union(T.SignedSmall, T.Array)),
T.Union(T.Number, T.Array)); T.Union(T.Number, T.Array));
} }
...@@ -1766,9 +1767,7 @@ struct Tests : Rep { ...@@ -1766,9 +1767,7 @@ struct Tests : Rep {
->IsInhabited()); // !!! ->IsInhabited()); // !!!
// Union-union // Union-union
CheckEqual( CheckEqual(T.Intersect(T.Union(T.Number, T.ArrayClass),
T.Intersect(
T.Union(T.Number, T.ArrayClass),
T.Union(T.SignedSmall, T.Array)), T.Union(T.SignedSmall, T.Array)),
T.Union(T.SignedSmall, T.ArrayClass)); T.Union(T.SignedSmall, T.ArrayClass));
CheckEqual( CheckEqual(
......
...@@ -45,6 +45,9 @@ class Types { ...@@ -45,6 +45,9 @@ class Types {
PROPER_BITSET_TYPE_LIST(DECLARE_TYPE) PROPER_BITSET_TYPE_LIST(DECLARE_TYPE)
#undef DECLARE_TYPE #undef DECLARE_TYPE
SignedSmall = Type::SignedSmall(region);
UnsignedSmall = Type::UnsignedSmall(region);
object_map = isolate->factory()->NewMap( object_map = isolate->factory()->NewMap(
JS_OBJECT_TYPE, JSObject::kHeaderSize); JS_OBJECT_TYPE, JSObject::kHeaderSize);
array_map = isolate->factory()->NewMap( array_map = isolate->factory()->NewMap(
...@@ -130,6 +133,8 @@ class Types { ...@@ -130,6 +133,8 @@ class Types {
#define DECLARE_TYPE(name, value) TypeHandle name; #define DECLARE_TYPE(name, value) TypeHandle name;
PROPER_BITSET_TYPE_LIST(DECLARE_TYPE) PROPER_BITSET_TYPE_LIST(DECLARE_TYPE)
#undef DECLARE_TYPE #undef DECLARE_TYPE
TypeHandle SignedSmall;
TypeHandle UnsignedSmall;
TypeHandle ObjectClass; TypeHandle ObjectClass;
TypeHandle ArrayClass; TypeHandle ArrayClass;
......
...@@ -211,7 +211,7 @@ TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTagged) { ...@@ -211,7 +211,7 @@ TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTagged) {
TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTaggedSmall) { TARGET_TEST_F(ChangeLowering32Test, ChangeInt32ToTaggedSmall) {
Node* val = Parameter(0); Node* val = Parameter(0);
Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val); Node* node = graph()->NewNode(simplified()->ChangeInt32ToTagged(), val);
NodeProperties::SetBounds(val, Bounds(Type::None(), Type::SignedSmall())); NodeProperties::SetBounds(val, Bounds(Type::None(), Type::Signed31()));
Reduction reduction = Reduce(node); Reduction reduction = Reduce(node);
ASSERT_TRUE(reduction.Changed()); ASSERT_TRUE(reduction.Changed());
......
...@@ -53,12 +53,10 @@ namespace { ...@@ -53,12 +53,10 @@ namespace {
// TODO(mstarzinger): Find a common place and unify with test-js-typed-lowering. // TODO(mstarzinger): Find a common place and unify with test-js-typed-lowering.
Type* const kNumberTypes[] = { Type* const kNumberTypes[] = {
Type::UnsignedSmall(), Type::NegativeSigned32(), Type::UnsignedSmall(), Type::Negative32(), Type::Unsigned31(),
Type::NonNegativeSigned32(), Type::SignedSmall(), Type::SignedSmall(), Type::Signed32(), Type::Unsigned32(),
Type::Signed32(), Type::Unsigned32(), Type::Integral32(), Type::MinusZero(), Type::NaN(),
Type::Integral32(), Type::MinusZero(), Type::OrderedNumber(), Type::PlainNumber(), Type::Number()};
Type::NaN(), Type::OrderedNumber(),
Type::PlainNumber(), Type::Number()};
} // namespace } // namespace
......
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