[turbofan] Fix incorrect minus zero handling in the unit tests.

TEST=unittests
R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#25956}
This commit is contained in:
bmeurer 2015-01-05 04:29:04 -08:00 committed by Commit bot
parent f087cc5f4d
commit c329a49d69
6 changed files with 85 additions and 38 deletions

View File

@ -15,6 +15,7 @@
using testing::_;
using testing::AllOf;
using testing::BitEq;
using testing::Capture;
using testing::CaptureEq;
@ -78,7 +79,8 @@ class ChangeLoweringTest : public GraphTest {
const Matcher<Node*>& control_matcher) {
return IsCall(_, IsHeapConstant(Unique<HeapObject>::CreateImmovable(
AllocateHeapNumberStub(isolate()).GetCode())),
IsNumberConstant(0.0), effect_matcher, control_matcher);
IsNumberConstant(BitEq(0.0)), effect_matcher,
control_matcher);
}
Matcher<Node*> IsLoadHeapNumber(const Matcher<Node*>& value_matcher,
const Matcher<Node*>& control_matcher) {

View File

@ -10,6 +10,7 @@
#include "test/unittests/compiler/node-test-utils.h"
#include "testing/gmock-support.h"
using testing::BitEq;
using testing::Capture;
namespace v8 {
@ -83,9 +84,11 @@ TEST_F(JSBuiltinReducerTest, MathAbs) {
} else {
Capture<Node*> branch;
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsSelect(kMachNone, IsNumberLessThan(IsNumberConstant(0), p0),
p0, IsNumberSubtract(IsNumberConstant(0), p0)));
EXPECT_THAT(
r.replacement(),
IsSelect(kMachNone,
IsNumberLessThan(IsNumberConstant(BitEq(0.0)), p0), p0,
IsNumberSubtract(IsNumberConstant(BitEq(0.0)), p0)));
}
}
}

View File

@ -12,6 +12,10 @@
#include "test/unittests/compiler/compiler-test-utils.h"
#include "test/unittests/compiler/graph-unittest.h"
#include "test/unittests/compiler/node-test-utils.h"
#include "testing/gmock-support.h"
using testing::BitEq;
namespace v8 {
namespace internal {
@ -135,7 +139,7 @@ TEST_F(JSTypedLoweringTest, JSToBooleanWithOrderedNumber) {
Reduce(graph()->NewNode(javascript()->ToBoolean(), input, context));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsBooleanNot(IsNumberEqual(input, IsNumberConstant(0))));
IsBooleanNot(IsNumberEqual(input, IsNumberConstant(BitEq(0.0)))));
}
@ -150,7 +154,7 @@ TEST_F(JSTypedLoweringTest, JSToBooleanWithString) {
IsBooleanNot(IsNumberEqual(
IsLoadField(AccessBuilder::ForStringLength(), input,
graph()->start(), graph()->start()),
IsNumberConstant(0))));
IsNumberConstant(BitEq(0.0)))));
}
@ -165,10 +169,10 @@ TEST_F(JSTypedLoweringTest, JSToBooleanWithPhi) {
graph()->NewNode(common()->Phi(kMachAnyTagged, 2), p0, p1, control),
context));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(
r.replacement(),
IsPhi(kMachAnyTagged,
IsBooleanNot(IsNumberEqual(p0, IsNumberConstant(0))), p1, control));
EXPECT_THAT(r.replacement(),
IsPhi(kMachAnyTagged, IsBooleanNot(IsNumberEqual(
p0, IsNumberConstant(BitEq(0.0)))),
p1, control));
}
@ -184,9 +188,10 @@ TEST_F(JSTypedLoweringTest, JSToBooleanWithSelect) {
p1, p2),
context));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsSelect(kMachAnyTagged, p0, IsTrueConstant(),
IsBooleanNot(IsNumberEqual(p2, IsNumberConstant(0)))));
EXPECT_THAT(
r.replacement(),
IsSelect(kMachAnyTagged, p0, IsTrueConstant(),
IsBooleanNot(IsNumberEqual(p2, IsNumberConstant(BitEq(0.0))))));
}
@ -202,7 +207,7 @@ TEST_F(JSTypedLoweringTest, JSToNumberWithPlainPrimitive) {
Reduction r = Reduce(graph()->NewNode(javascript()->ToNumber(), input,
context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsToNumber(input, IsNumberConstant(0),
EXPECT_THAT(r.replacement(), IsToNumber(input, IsNumberConstant(BitEq(0.0)),
graph()->start(), control));
}
@ -235,12 +240,13 @@ TEST_F(JSTypedLoweringTest, JSShiftLeftWithSigned32AndConstant) {
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
TRACED_FORRANGE(int32_t, rhs, 0, 31) {
TRACED_FORRANGE(double, rhs, 0, 31) {
Reduction r =
Reduce(graph()->NewNode(javascript()->ShiftLeft(), lhs,
NumberConstant(rhs), context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsWord32Shl(lhs, IsNumberConstant(rhs)));
EXPECT_THAT(r.replacement(),
IsWord32Shl(lhs, IsNumberConstant(BitEq(rhs))));
}
}
@ -268,12 +274,13 @@ TEST_F(JSTypedLoweringTest, JSShiftRightWithSigned32AndConstant) {
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
TRACED_FORRANGE(int32_t, rhs, 0, 31) {
TRACED_FORRANGE(double, rhs, 0, 31) {
Reduction r =
Reduce(graph()->NewNode(javascript()->ShiftRight(), lhs,
NumberConstant(rhs), context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsWord32Sar(lhs, IsNumberConstant(rhs)));
EXPECT_THAT(r.replacement(),
IsWord32Sar(lhs, IsNumberConstant(BitEq(rhs))));
}
}
@ -301,12 +308,13 @@ TEST_F(JSTypedLoweringTest, JSShiftRightLogicalWithUnsigned32AndConstant) {
Node* const context = UndefinedConstant();
Node* const effect = graph()->start();
Node* const control = graph()->start();
TRACED_FORRANGE(int32_t, rhs, 0, 31) {
TRACED_FORRANGE(double, rhs, 0, 31) {
Reduction r =
Reduce(graph()->NewNode(javascript()->ShiftRightLogical(), lhs,
NumberConstant(rhs), context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsWord32Shr(lhs, IsNumberConstant(rhs)));
EXPECT_THAT(r.replacement(),
IsWord32Shr(lhs, IsNumberConstant(BitEq(rhs))));
}
}

View File

@ -12,6 +12,7 @@
#include "testing/gmock-support.h"
using testing::AllOf;
using testing::BitEq;
using testing::Capture;
using testing::CaptureEq;
@ -291,7 +292,7 @@ TEST_F(MachineOperatorReducerTest, ChangeFloat64ToFloat32WithConstant) {
Reduction reduction = Reduce(graph()->NewNode(
machine()->ChangeFloat32ToFloat64(), Float32Constant(x)));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsFloat64Constant(x));
EXPECT_THAT(reduction.replacement(), IsFloat64Constant(BitEq<double>(x)));
}
}
@ -355,7 +356,7 @@ TEST_F(MachineOperatorReducerTest, ChangeInt32ToFloat64WithConstant) {
Reduction reduction = Reduce(
graph()->NewNode(machine()->ChangeInt32ToFloat64(), Int32Constant(x)));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsFloat64Constant(FastI2D(x)));
EXPECT_THAT(reduction.replacement(), IsFloat64Constant(BitEq(FastI2D(x))));
}
}
@ -384,7 +385,7 @@ TEST_F(MachineOperatorReducerTest, ChangeUint32ToFloat64WithConstant) {
Reduce(graph()->NewNode(machine()->ChangeUint32ToFloat64(),
Int32Constant(bit_cast<int32_t>(x))));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsFloat64Constant(FastUI2D(x)));
EXPECT_THAT(reduction.replacement(), IsFloat64Constant(BitEq(FastUI2D(x))));
}
}
@ -425,7 +426,8 @@ TEST_F(MachineOperatorReducerTest, TruncateFloat64ToFloat32WithConstant) {
Reduction reduction = Reduce(graph()->NewNode(
machine()->TruncateFloat64ToFloat32(), Float64Constant(x)));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsFloat32Constant(DoubleToFloat32(x)));
EXPECT_THAT(reduction.replacement(),
IsFloat32Constant(BitEq(DoubleToFloat32(x))));
}
}
@ -1268,13 +1270,15 @@ TEST_F(MachineOperatorReducerTest, Float64MulWithMinusOne) {
Reduction r = Reduce(
graph()->NewNode(machine()->Float64Mul(), p0, Float64Constant(-1.0)));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsFloat64Sub(IsFloat64Constant(-0.0), p0));
EXPECT_THAT(r.replacement(),
IsFloat64Sub(IsFloat64Constant(BitEq(-0.0)), p0));
}
{
Reduction r = Reduce(
graph()->NewNode(machine()->Float64Mul(), Float64Constant(-1.0), p0));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsFloat64Sub(IsFloat64Constant(-0.0), p0));
EXPECT_THAT(r.replacement(),
IsFloat64Sub(IsFloat64Constant(BitEq(-0.0)), p0));
}
}

View File

@ -9,6 +9,10 @@
#include "src/types.h"
#include "test/unittests/compiler/graph-unittest.h"
#include "test/unittests/compiler/node-test-utils.h"
#include "testing/gmock-support.h"
using testing::BitEq;
namespace v8 {
namespace internal {
@ -114,11 +118,6 @@ static const uint32_t kUint32Values[] = {
0xbeb15c0d, 0xc171c53d, 0xc743dd38, 0xc8e2af50, 0xc98e2df0, 0xd9d1cdf9,
0xdcc91049, 0xe46f396d, 0xee991950, 0xef64e521, 0xf7aeefc9, 0xffffffff};
MATCHER(IsNaN, std::string(negation ? "isn't" : "is") + " NaN") {
return std::isnan(arg);
}
} // namespace
@ -271,7 +270,7 @@ TEST_F(SimplifiedOperatorReducerTest, ChangeFloat64ToTaggedWithConstant) {
Reduction reduction = Reduce(graph()->NewNode(
simplified()->ChangeFloat64ToTagged(), Float64Constant(n)));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsNumberConstant(n));
EXPECT_THAT(reduction.replacement(), IsNumberConstant(BitEq(n)));
}
}
@ -285,7 +284,7 @@ TEST_F(SimplifiedOperatorReducerTest, ChangeInt32ToTaggedWithConstant) {
Reduction reduction = Reduce(graph()->NewNode(
simplified()->ChangeInt32ToTagged(), Int32Constant(n)));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsNumberConstant(FastI2D(n)));
EXPECT_THAT(reduction.replacement(), IsNumberConstant(BitEq(FastI2D(n))));
}
}
@ -332,7 +331,7 @@ TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToFloat64WithConstant) {
Reduction reduction = Reduce(graph()->NewNode(
simplified()->ChangeTaggedToFloat64(), NumberConstant(n)));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsFloat64Constant(n));
EXPECT_THAT(reduction.replacement(), IsFloat64Constant(BitEq(n)));
}
}
@ -342,7 +341,8 @@ TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToFloat64WithNaNConstant1) {
Reduce(graph()->NewNode(simplified()->ChangeTaggedToFloat64(),
NumberConstant(-base::OS::nan_value())));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsFloat64Constant(IsNaN()));
EXPECT_THAT(reduction.replacement(),
IsFloat64Constant(BitEq(-base::OS::nan_value())));
}
@ -351,7 +351,8 @@ TEST_F(SimplifiedOperatorReducerTest, ChangeTaggedToFloat64WithNaNConstant2) {
Reduce(graph()->NewNode(simplified()->ChangeTaggedToFloat64(),
NumberConstant(base::OS::nan_value())));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsFloat64Constant(IsNaN()));
EXPECT_THAT(reduction.replacement(),
IsFloat64Constant(BitEq(base::OS::nan_value())));
}
@ -474,7 +475,7 @@ TEST_F(SimplifiedOperatorReducerTest, ChangeUint32ToTagged) {
Reduce(graph()->NewNode(simplified()->ChangeUint32ToTagged(),
Int32Constant(bit_cast<int32_t>(n))));
ASSERT_TRUE(reduction.Changed());
EXPECT_THAT(reduction.replacement(), IsNumberConstant(FastUI2D(n)));
EXPECT_THAT(reduction.replacement(), IsNumberConstant(BitEq(FastUI2D(n))));
}
}

View File

@ -5,6 +5,8 @@
#ifndef V8_TESTING_GMOCK_SUPPORT_H_
#define V8_TESTING_GMOCK_SUPPORT_H_
#include <cstring>
#include "testing/gmock/include/gmock/gmock.h"
namespace testing {
@ -31,6 +33,25 @@ class Capture {
namespace internal {
struct AnyBitEq {
template <typename A, typename B>
bool operator()(A const& a, B const& b) const {
if (sizeof(A) != sizeof(B)) return false;
return std::memcmp(&a, &b, sizeof(A)) == 0;
}
};
template <typename Rhs>
class BitEqMatcher : public ComparisonBase<BitEqMatcher<Rhs>, Rhs, AnyBitEq> {
public:
explicit BitEqMatcher(Rhs const& rhs)
: ComparisonBase<BitEqMatcher<Rhs>, Rhs, AnyBitEq>(rhs) {}
static const char* Desc() { return "is bitwise equal to"; }
static const char* NegatedDesc() { return "isn't bitwise equal to"; }
};
template <typename T>
class CaptureEqMatcher : public MatcherInterface<T> {
public:
@ -60,10 +81,18 @@ class CaptureEqMatcher : public MatcherInterface<T> {
} // namespace internal
// Creates a polymorphic matcher that matches anything whose bit representation
// is equal to that of x.
template <typename T>
inline internal::BitEqMatcher<T> BitEq(T const& x) {
return internal::BitEqMatcher<T>(x);
}
// CaptureEq(capture) captures the value passed in during matching as long as it
// is unset, and once set, compares the value for equality with the argument.
template <typename T>
Matcher<T> CaptureEq(Capture<T>* capture) {
inline Matcher<T> CaptureEq(Capture<T>* capture) {
return MakeMatcher(new internal::CaptureEqMatcher<T>(capture));
}