Commit f574d93e authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Revert "Reland "Refine expression typing, esp. by propagating range information.""

This reverts commit r24609 for breaking the
cctest/test-js-typed-lowering/Int32BitwiseBinops test.

TBR=rossberg@chromium.org,neis@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24614 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 2de468e8
...@@ -383,6 +383,16 @@ Reduction JSTypedLowering::ReduceJSStrictEqual(Node* node, bool invert) { ...@@ -383,6 +383,16 @@ Reduction JSTypedLowering::ReduceJSStrictEqual(Node* node, bool invert) {
: jsgraph()->TrueConstant()); : jsgraph()->TrueConstant());
} }
} }
/* TODO(neis): This is currently unsound.
if (!r.left_type()->Maybe(r.right_type())) {
// Type intersection is empty; === is always false unless both
// inputs could be strings (one internalized and one not).
if (r.OneInputCannotBe(Type::String())) {
return ReplaceEagerly(node, invert ? jsgraph()->TrueConstant()
: jsgraph()->FalseConstant());
}
}
*/
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);
......
This diff is collapsed.
...@@ -36,17 +36,6 @@ class Typer { ...@@ -36,17 +36,6 @@ class Typer {
class WidenVisitor; class WidenVisitor;
Zone* zone_; Zone* zone_;
Type* negative_signed32;
Type* non_negative_signed32;
Type* undefined_or_null;
Type* singleton_false;
Type* singleton_true;
Type* singleton_zero;
Type* singleton_one;
Type* zero_or_one;
Type* zeroish;
Type* falsish;
Type* integer;
Type* number_fun0_; Type* number_fun0_;
Type* number_fun1_; Type* number_fun1_;
Type* number_fun2_; Type* number_fun2_;
......
...@@ -344,7 +344,7 @@ double TypeImpl<Config>::BitsetType::Max(bitset bits) { ...@@ -344,7 +344,7 @@ double TypeImpl<Config>::BitsetType::Max(bitset bits) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
DCHECK(Is(bits, kNumber)); DCHECK(Is(bits, kNumber));
const BitsetMin* mins = BitsetMins(); const BitsetMin* mins = BitsetMins();
bool mz = SEMANTIC(bits & kMinusZero); bool mz = bits & kMinusZero;
if (BitsetType::Is(mins[BitsetMinsSize()-1].bits, bits)) { if (BitsetType::Is(mins[BitsetMinsSize()-1].bits, bits)) {
return +V8_INFINITY; return +V8_INFINITY;
} }
......
...@@ -242,9 +242,6 @@ namespace internal { ...@@ -242,9 +242,6 @@ namespace internal {
* *
* E.g., OtherUnsigned32 (OU32) covers all integers from 2^31 to 2^32-1. * E.g., OtherUnsigned32 (OU32) covers all integers from 2^31 to 2^32-1.
* *
* NOTE: OtherSigned32 (OS32) and OU31 (OtherUnsigned31) are empty if Smis are
* 32-bit wide. They should thus never be used directly, only indirectly
* via e.g. Number.
*/ */
#define PROPER_BITSET_TYPE_LIST(V) \ #define PROPER_BITSET_TYPE_LIST(V) \
......
...@@ -86,7 +86,6 @@ ...@@ -86,7 +86,6 @@
'compiler/test-schedule.cc', 'compiler/test-schedule.cc',
'compiler/test-scheduler.cc', 'compiler/test-scheduler.cc',
'compiler/test-simplified-lowering.cc', 'compiler/test-simplified-lowering.cc',
'compiler/test-typer.cc',
'cctest.cc', 'cctest.cc',
'gay-fixed.cc', 'gay-fixed.cc',
'gay-precision.cc', 'gay-precision.cc',
......
...@@ -227,7 +227,7 @@ TEST(NumberTypes) { ...@@ -227,7 +227,7 @@ TEST(NumberTypes) {
FOR_FLOAT64_INPUTS(i) { FOR_FLOAT64_INPUTS(i) {
double value = *i; double value = *i;
Node* node = T.Constant(value); Node* node = T.Constant(value);
CHECK(T.upper(node)->Is(Type::Of(value, T.main_zone()))); CHECK(T.upper(node)->Equals(Type::Of(value, T.main_zone())));
} }
} }
......
...@@ -262,15 +262,16 @@ TEST(NumberBinops) { ...@@ -262,15 +262,16 @@ TEST(NumberBinops) {
static void CheckToI32(Node* old_input, Node* new_input, bool is_signed) { static void CheckToI32(Node* old_input, Node* new_input, bool is_signed) {
Type* old_type = NodeProperties::GetBounds(old_input).upper; Type* old_type = NodeProperties::GetBounds(old_input).upper;
Type* new_type = NodeProperties::GetBounds(new_input).upper;
Type* expected_type = I32Type(is_signed); Type* expected_type = I32Type(is_signed);
CHECK(new_type->Is(expected_type));
if (old_type->Is(expected_type)) { if (old_type->Is(expected_type)) {
CHECK_EQ(old_input, new_input); CHECK_EQ(old_input, new_input);
} else if (new_input->opcode() == IrOpcode::kNumberConstant) { } else if (new_input->opcode() == IrOpcode::kNumberConstant) {
CHECK(NodeProperties::GetBounds(new_input).upper->Is(expected_type));
double v = OpParameter<double>(new_input); double v = OpParameter<double>(new_input);
double e = static_cast<double>(is_signed ? FastD2I(v) : FastD2UI(v)); double e = static_cast<double>(is_signed ? FastD2I(v) : FastD2UI(v));
CHECK_EQ(e, v); CHECK_EQ(e, v);
} else {
CHECK_EQ(NumberToI32(is_signed), new_input->opcode());
} }
} }
......
// Copyright 2014 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This tests the correctness of the typer.
//
// For simplicity, it currently only tests it on expression operators that have
// a direct equivalent in C++. Also, testing is currently limited to ranges as
// input types.
#include <functional>
#include "src/compiler/node-properties-inl.h"
#include "src/compiler/typer.h"
#include "test/cctest/cctest.h"
#include "test/cctest/compiler/graph-builder-tester.h"
using namespace v8::internal;
using namespace v8::internal::compiler;
class TyperTester : public HandleAndZoneScope, public GraphAndBuilders {
public:
TyperTester()
: GraphAndBuilders(main_zone()),
typer_(main_zone()),
javascript_(main_zone()) {
Node* s = graph()->NewNode(common()->Start(3));
graph()->SetStart(s);
context_node_ = graph()->NewNode(common()->Parameter(2), graph()->start());
rng_ = isolate()->random_number_generator();
integers.push_back(0);
integers.push_back(0);
integers.push_back(-1);
integers.push_back(+1);
integers.push_back(-V8_INFINITY);
integers.push_back(+V8_INFINITY);
for (int i = 0; i < 5; ++i) {
double x = rng_->NextInt();
integers.push_back(x);
x *= rng_->NextInt();
if (!IsMinusZero(x)) integers.push_back(x);
}
int32s.push_back(0);
int32s.push_back(0);
int32s.push_back(-1);
int32s.push_back(+1);
int32s.push_back(kMinInt);
int32s.push_back(kMaxInt);
for (int i = 0; i < 10; ++i) {
int32s.push_back(rng_->NextInt());
}
}
Typer typer_;
JSOperatorBuilder javascript_;
Node* context_node_;
v8::base::RandomNumberGenerator* rng_;
std::vector<double> integers;
std::vector<double> int32s;
Isolate* isolate() { return main_isolate(); }
Graph* graph() { return main_graph_; }
CommonOperatorBuilder* common() { return &main_common_; }
Node* Parameter(int index = 0) {
return graph()->NewNode(common()->Parameter(index), graph()->start());
}
Type* TypeBinaryOp(const Operator* op, Type* lhs, Type* rhs) {
Node* p0 = Parameter(0);
Node* p1 = Parameter(1);
NodeProperties::SetBounds(p0, Bounds(lhs));
NodeProperties::SetBounds(p1, Bounds(rhs));
Node* n = graph()->NewNode(
op, p0, p1, context_node_, graph()->start(), graph()->start());
typer_.Init(n);
return NodeProperties::GetBounds(n).upper;
}
Type* RandomRange(bool int32 = false) {
std::vector<double>& numbers = int32 ? int32s : integers;
Factory* f = isolate()->factory();
int i = rng_->NextInt(static_cast<int>(numbers.size()));
int j = rng_->NextInt(static_cast<int>(numbers.size()));
i::Handle<i::Object> min = f->NewNumber(numbers[i]);
i::Handle<i::Object> max = f->NewNumber(numbers[j]);
if (min->Number() > max->Number()) std::swap(min, max);
return Type::Range(min, max, main_zone());
}
double RandomInt(double min, double max) {
switch (rng_->NextInt(4)) {
case 0: return min;
case 1: return max;
default: break;
}
if (min == +V8_INFINITY) return +V8_INFINITY;
if (max == -V8_INFINITY) return -V8_INFINITY;
if (min == -V8_INFINITY && max == +V8_INFINITY) {
return rng_->NextInt() * static_cast<double>(rng_->NextInt());
}
double result = nearbyint(min + (max - min) * rng_->NextDouble());
if (IsMinusZero(result)) return 0;
if (std::isnan(result)) return rng_->NextInt(2) ? min : max;
DCHECK(min <= result && result <= max);
return result;
}
double RandomInt(Type::RangeType* range) {
return RandomInt(range->Min()->Number(), range->Max()->Number());
}
template <class BinaryFunction>
void TestBinaryArithOp(const Operator* op, BinaryFunction opfun) {
for (int i = 0; i < 100; ++i) {
Type::RangeType* r1 = RandomRange()->AsRange();
Type::RangeType* r2 = RandomRange()->AsRange();
Type* expected_type = TypeBinaryOp(op, r1, r2);
double x1 = RandomInt(r1);
double x2 = RandomInt(r2);
double result_value = opfun(x1, x2);
Type* result_type = Type::Constant(
isolate()->factory()->NewNumber(result_value), main_zone());
CHECK(result_type->Is(expected_type));
}
}
template <class BinaryFunction>
void TestBinaryCompareOp(const Operator* op, BinaryFunction opfun) {
for (int i = 0; i < 100; ++i) {
Type::RangeType* r1 = RandomRange()->AsRange();
Type::RangeType* r2 = RandomRange()->AsRange();
Type* expected_type = TypeBinaryOp(op, r1, r2);
double x1 = RandomInt(r1);
double x2 = RandomInt(r2);
bool result_value = opfun(x1, x2);
Type* result_type = Type::Constant(result_value ?
isolate()->factory()->true_value() :
isolate()->factory()->false_value(), main_zone());
CHECK(result_type->Is(expected_type));
}
}
template <class BinaryFunction>
void TestBinaryBitOp(const Operator* op, BinaryFunction opfun) {
for (int i = 0; i < 100; ++i) {
Type::RangeType* r1 = RandomRange(true)->AsRange();
Type::RangeType* r2 = RandomRange(true)->AsRange();
Type* expected_type = TypeBinaryOp(op, r1, r2);
int32_t x1 = static_cast<int32_t>(RandomInt(r1));
int32_t x2 = static_cast<int32_t>(RandomInt(r2));
double result_value = opfun(x1, x2);
Type* result_type = Type::Constant(
isolate()->factory()->NewNumber(result_value), main_zone());
CHECK(result_type->Is(expected_type));
}
}
};
static int32_t shift_left(int32_t x, int32_t y) { return x << y; }
static int32_t shift_right(int32_t x, int32_t y) { return x >> y; }
static int32_t bit_or(int32_t x, int32_t y) { return x | y; }
static int32_t bit_and(int32_t x, int32_t y) { return x & y; }
static int32_t bit_xor(int32_t x, int32_t y) { return x ^ y; }
TEST(TypeJSAdd) {
TyperTester t;
t.TestBinaryArithOp(t.javascript_.Subtract(), std::plus<double>());
}
TEST(TypeJSSubtract) {
TyperTester t;
t.TestBinaryArithOp(t.javascript_.Subtract(), std::minus<double>());
}
TEST(TypeJSMultiply) {
TyperTester t;
t.TestBinaryArithOp(t.javascript_.Multiply(), std::multiplies<double>());
}
TEST(TypeJSDivide) {
TyperTester t;
t.TestBinaryArithOp(t.javascript_.Divide(), std::divides<double>());
}
TEST(TypeJSBitwiseOr) {
TyperTester t;
t.TestBinaryBitOp(t.javascript_.BitwiseOr(), bit_or);
}
TEST(TypeJSBitwiseAnd) {
TyperTester t;
t.TestBinaryBitOp(t.javascript_.BitwiseAnd(), bit_and);
}
TEST(TypeJSBitwiseXor) {
TyperTester t;
t.TestBinaryBitOp(t.javascript_.BitwiseXor(), bit_xor);
}
TEST(TypeJSShiftLeft) {
TyperTester t;
t.TestBinaryBitOp(t.javascript_.ShiftLeft(), shift_left);
}
TEST(TypeJSShiftRight) {
TyperTester t;
t.TestBinaryBitOp(t.javascript_.ShiftRight(), shift_right);
}
TEST(TypeJSLessThan) {
TyperTester t;
t.TestBinaryCompareOp(t.javascript_.LessThan(), std::less<double>());
}
TEST(TypeJSLessThanOrEqual) {
TyperTester t;
t.TestBinaryCompareOp(
t.javascript_.LessThanOrEqual(), std::less_equal<double>());
}
TEST(TypeJSGreaterThan) {
TyperTester t;
t.TestBinaryCompareOp(t.javascript_.GreaterThan(), std::greater<double>());
}
TEST(TypeJSGreaterThanOrEqual) {
TyperTester t;
t.TestBinaryCompareOp(
t.javascript_.GreaterThanOrEqual(), std::greater_equal<double>());
}
TEST(TypeJSEqual) {
TyperTester t;
t.TestBinaryCompareOp(t.javascript_.Equal(), std::equal_to<double>());
}
TEST(TypeJSNotEqual) {
TyperTester t;
t.TestBinaryCompareOp(t.javascript_.NotEqual(), std::not_equal_to<double>());
}
// For numbers there's no difference between strict and non-strict equality.
TEST(TypeJSStrictEqual) {
TyperTester t;
t.TestBinaryCompareOp(t.javascript_.StrictEqual(), std::equal_to<double>());
}
TEST(TypeJSStrictNotEqual) {
TyperTester t;
t.TestBinaryCompareOp(
t.javascript_.StrictNotEqual(), std::not_equal_to<double>());
}
...@@ -97,12 +97,7 @@ class Types { ...@@ -97,12 +97,7 @@ class Types {
: region_(region), rng_(isolate->random_number_generator()) { : region_(region), rng_(isolate->random_number_generator()) {
#define DECLARE_TYPE(name, value) \ #define DECLARE_TYPE(name, value) \
name = Type::name(region); \ name = Type::name(region); \
if (SmiValuesAre31Bits() || \ types.push_back(name);
(!Type::name(region)->Equals(Type::OtherSigned32()) && \
!Type::name(region)->Equals(Type::OtherUnsigned31()))) { \
/* Hack: Avoid generating those empty bitset types. */ \
types.push_back(name); \
}
PROPER_BITSET_TYPE_LIST(DECLARE_TYPE) PROPER_BITSET_TYPE_LIST(DECLARE_TYPE)
#undef DECLARE_TYPE #undef DECLARE_TYPE
...@@ -289,17 +284,11 @@ class Types { ...@@ -289,17 +284,11 @@ class Types {
int j = rng_->NextInt(n); int j = rng_->NextInt(n);
#define PICK_BITSET_TYPE(type, value) \ #define PICK_BITSET_TYPE(type, value) \
if (j-- == 0) { \ if (j-- == 0) { \
if (!SmiValuesAre31Bits() && \
(Type::type(region_)->Equals(Type::OtherSigned32()) || \
Type::type(region_)->Equals(Type::OtherUnsigned31()))) { \
/* Hack: Avoid generating those empty bitset types. */ \
continue; \
} \
TypeHandle tmp = Type::Intersect( \ TypeHandle tmp = Type::Intersect( \
result, Type::type(region_), region_); \ result, Type::type(region_), region_); \
if (tmp->Is(Type::None()) && i != 0) { \ if (tmp->Is(Type::None()) && i != 0) { \
break; \ break; \
} else { \ } { \
result = tmp; \ result = tmp; \
continue; \ continue; \
} \ } \
...@@ -2190,13 +2179,6 @@ TEST(NowOf) { ...@@ -2190,13 +2179,6 @@ TEST(NowOf) {
} }
TEST(MinMax) {
CcTest::InitializeVM();
ZoneTests().MinMax();
HeapTests().MinMax();
}
TEST(BitsetGlb) { TEST(BitsetGlb) {
CcTest::InitializeVM(); CcTest::InitializeVM();
ZoneTests().BitsetGlb(); ZoneTests().BitsetGlb();
......
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