2014-07-30 13:54:45 +00:00
|
|
|
// 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.
|
|
|
|
|
|
|
|
#include "src/base/utils/random-number-generator.h"
|
2014-09-30 10:42:44 +00:00
|
|
|
#include "src/codegen.h"
|
2014-09-02 05:08:54 +00:00
|
|
|
#include "src/compiler/js-graph.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "src/compiler/machine-operator-reducer.h"
|
2014-10-29 21:07:18 +00:00
|
|
|
#include "src/compiler/operator-properties.h"
|
2014-09-02 05:08:54 +00:00
|
|
|
#include "src/compiler/typer.h"
|
2017-02-23 11:46:29 +00:00
|
|
|
#include "src/objects-inl.h"
|
2015-10-28 13:32:17 +00:00
|
|
|
#include "test/cctest/cctest.h"
|
2014-07-30 13:54:45 +00:00
|
|
|
#include "test/cctest/compiler/value-helper.h"
|
|
|
|
|
2015-10-30 09:16:26 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
template <typename T>
|
2014-09-10 12:23:45 +00:00
|
|
|
const Operator* NewConstantOperator(CommonOperatorBuilder* common,
|
|
|
|
volatile T value);
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
template <>
|
2014-09-10 12:23:45 +00:00
|
|
|
const Operator* NewConstantOperator<int32_t>(CommonOperatorBuilder* common,
|
|
|
|
volatile int32_t value) {
|
2014-07-30 13:54:45 +00:00
|
|
|
return common->Int32Constant(value);
|
|
|
|
}
|
|
|
|
|
2016-08-04 12:36:39 +00:00
|
|
|
template <>
|
|
|
|
const Operator* NewConstantOperator<int64_t>(CommonOperatorBuilder* common,
|
|
|
|
volatile int64_t value) {
|
|
|
|
return common->Int64Constant(value);
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
template <>
|
2014-09-10 12:23:45 +00:00
|
|
|
const Operator* NewConstantOperator<double>(CommonOperatorBuilder* common,
|
|
|
|
volatile double value) {
|
2014-07-30 13:54:45 +00:00
|
|
|
return common->Float64Constant(value);
|
|
|
|
}
|
|
|
|
|
2016-08-08 08:39:38 +00:00
|
|
|
template <>
|
|
|
|
const Operator* NewConstantOperator<float>(CommonOperatorBuilder* common,
|
|
|
|
volatile float value) {
|
|
|
|
return common->Float32Constant(value);
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-09-08 09:16:11 +00:00
|
|
|
template <typename T>
|
|
|
|
T ValueOfOperator(const Operator* op);
|
|
|
|
|
|
|
|
template <>
|
|
|
|
int32_t ValueOfOperator<int32_t>(const Operator* op) {
|
|
|
|
CHECK_EQ(IrOpcode::kInt32Constant, op->opcode());
|
|
|
|
return OpParameter<int32_t>(op);
|
|
|
|
}
|
|
|
|
|
2016-08-04 12:36:39 +00:00
|
|
|
template <>
|
|
|
|
int64_t ValueOfOperator<int64_t>(const Operator* op) {
|
|
|
|
CHECK_EQ(IrOpcode::kInt64Constant, op->opcode());
|
|
|
|
return OpParameter<int64_t>(op);
|
|
|
|
}
|
|
|
|
|
2016-08-08 08:39:38 +00:00
|
|
|
template <>
|
|
|
|
float ValueOfOperator<float>(const Operator* op) {
|
|
|
|
CHECK_EQ(IrOpcode::kFloat32Constant, op->opcode());
|
|
|
|
return OpParameter<float>(op);
|
|
|
|
}
|
|
|
|
|
2014-09-08 09:16:11 +00:00
|
|
|
template <>
|
|
|
|
double ValueOfOperator<double>(const Operator* op) {
|
|
|
|
CHECK_EQ(IrOpcode::kFloat64Constant, op->opcode());
|
|
|
|
return OpParameter<double>(op);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
class ReducerTester : public HandleAndZoneScope {
|
|
|
|
public:
|
2016-08-08 08:39:38 +00:00
|
|
|
explicit ReducerTester(int num_parameters = 0,
|
|
|
|
MachineOperatorBuilder::Flags flags =
|
|
|
|
MachineOperatorBuilder::kAllOptionalOps)
|
2014-07-30 13:54:45 +00:00
|
|
|
: isolate(main_isolate()),
|
2017-10-13 16:33:03 +00:00
|
|
|
binop(nullptr),
|
|
|
|
unop(nullptr),
|
2015-12-10 09:03:30 +00:00
|
|
|
machine(main_zone(), MachineType::PointerRepresentation(), flags),
|
2014-07-30 13:54:45 +00:00
|
|
|
common(main_zone()),
|
|
|
|
graph(main_zone()),
|
2014-09-12 11:06:37 +00:00
|
|
|
javascript(main_zone()),
|
2015-10-16 12:38:46 +00:00
|
|
|
jsgraph(isolate, &graph, &common, &javascript, nullptr, &machine),
|
2014-08-05 08:47:39 +00:00
|
|
|
maxuint32(Constant<int32_t>(kMaxUInt32)) {
|
|
|
|
Node* s = graph.NewNode(common.Start(num_parameters));
|
|
|
|
graph.SetStart(s);
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
Isolate* isolate;
|
2014-09-10 12:23:45 +00:00
|
|
|
const Operator* binop;
|
|
|
|
const Operator* unop;
|
2014-07-30 13:54:45 +00:00
|
|
|
MachineOperatorBuilder machine;
|
|
|
|
CommonOperatorBuilder common;
|
|
|
|
Graph graph;
|
2014-09-12 11:06:37 +00:00
|
|
|
JSOperatorBuilder javascript;
|
2014-09-02 05:08:54 +00:00
|
|
|
JSGraph jsgraph;
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* maxuint32;
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
Node* Constant(volatile T value) {
|
|
|
|
return graph.NewNode(NewConstantOperator<T>(&common, value));
|
|
|
|
}
|
|
|
|
|
2014-09-08 09:16:11 +00:00
|
|
|
template <typename T>
|
|
|
|
const T ValueOf(const Operator* op) {
|
|
|
|
return ValueOfOperator<T>(op);
|
|
|
|
}
|
|
|
|
|
2014-07-30 13:54:45 +00:00
|
|
|
// Check that the reduction of this binop applied to constants {a} and {b}
|
|
|
|
// yields the {expect} value.
|
|
|
|
template <typename T>
|
|
|
|
void CheckFoldBinop(volatile T expect, volatile T a, volatile T b) {
|
|
|
|
CheckFoldBinop<T>(expect, Constant<T>(a), Constant<T>(b));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the reduction of this binop applied to {a} and {b} yields
|
|
|
|
// the {expect} value.
|
|
|
|
template <typename T>
|
|
|
|
void CheckFoldBinop(volatile T expect, Node* a, Node* b) {
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(binop);
|
2014-10-29 21:07:18 +00:00
|
|
|
Node* n = CreateBinopNode(a, b);
|
2014-09-02 05:08:54 +00:00
|
|
|
MachineOperatorReducer reducer(&jsgraph);
|
2014-07-30 13:54:45 +00:00
|
|
|
Reduction reduction = reducer.Reduce(n);
|
|
|
|
CHECK(reduction.Changed());
|
|
|
|
CHECK_NE(n, reduction.replacement());
|
2016-08-08 08:39:38 +00:00
|
|
|
// Deal with NaNs.
|
|
|
|
if (expect == expect) {
|
|
|
|
// We do not expect a NaN, check for equality.
|
|
|
|
CHECK_EQ(expect, ValueOf<T>(reduction.replacement()->op()));
|
|
|
|
} else {
|
|
|
|
// Check for NaN.
|
|
|
|
T result = ValueOf<T>(reduction.replacement()->op());
|
|
|
|
CHECK_NE(result, result);
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the reduction of this binop applied to {a} and {b} yields
|
|
|
|
// the {expect} node.
|
|
|
|
void CheckBinop(Node* expect, Node* a, Node* b) {
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(binop);
|
2014-10-29 21:07:18 +00:00
|
|
|
Node* n = CreateBinopNode(a, b);
|
2014-09-02 05:08:54 +00:00
|
|
|
MachineOperatorReducer reducer(&jsgraph);
|
2014-07-30 13:54:45 +00:00
|
|
|
Reduction reduction = reducer.Reduce(n);
|
|
|
|
CHECK(reduction.Changed());
|
|
|
|
CHECK_EQ(expect, reduction.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the reduction of this binop applied to {left} and {right} yields
|
|
|
|
// this binop applied to {left_expect} and {right_expect}.
|
|
|
|
void CheckFoldBinop(Node* left_expect, Node* right_expect, Node* left,
|
|
|
|
Node* right) {
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(binop);
|
2014-10-29 21:07:18 +00:00
|
|
|
Node* n = CreateBinopNode(left, right);
|
2014-09-02 05:08:54 +00:00
|
|
|
MachineOperatorReducer reducer(&jsgraph);
|
2014-07-30 13:54:45 +00:00
|
|
|
Reduction reduction = reducer.Reduce(n);
|
|
|
|
CHECK(reduction.Changed());
|
|
|
|
CHECK_EQ(binop, reduction.replacement()->op());
|
|
|
|
CHECK_EQ(left_expect, reduction.replacement()->InputAt(0));
|
|
|
|
CHECK_EQ(right_expect, reduction.replacement()->InputAt(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the reduction of this binop applied to {left} and {right} yields
|
|
|
|
// the {op_expect} applied to {left_expect} and {right_expect}.
|
|
|
|
template <typename T>
|
2014-09-10 12:23:45 +00:00
|
|
|
void CheckFoldBinop(volatile T left_expect, const Operator* op_expect,
|
2014-07-30 13:54:45 +00:00
|
|
|
Node* right_expect, Node* left, Node* right) {
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(binop);
|
2014-10-29 21:07:18 +00:00
|
|
|
Node* n = CreateBinopNode(left, right);
|
2014-09-02 05:08:54 +00:00
|
|
|
MachineOperatorReducer reducer(&jsgraph);
|
2014-07-30 13:54:45 +00:00
|
|
|
Reduction r = reducer.Reduce(n);
|
|
|
|
CHECK(r.Changed());
|
|
|
|
CHECK_EQ(op_expect->opcode(), r.replacement()->op()->opcode());
|
|
|
|
CHECK_EQ(left_expect, ValueOf<T>(r.replacement()->InputAt(0)->op()));
|
|
|
|
CHECK_EQ(right_expect, r.replacement()->InputAt(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that the reduction of this binop applied to {left} and {right} yields
|
|
|
|
// the {op_expect} applied to {left_expect} and {right_expect}.
|
|
|
|
template <typename T>
|
2014-09-10 12:23:45 +00:00
|
|
|
void CheckFoldBinop(Node* left_expect, const Operator* op_expect,
|
2014-07-30 13:54:45 +00:00
|
|
|
volatile T right_expect, Node* left, Node* right) {
|
2015-01-30 09:29:25 +00:00
|
|
|
CHECK(binop);
|
2014-10-29 21:07:18 +00:00
|
|
|
Node* n = CreateBinopNode(left, right);
|
2014-09-02 05:08:54 +00:00
|
|
|
MachineOperatorReducer reducer(&jsgraph);
|
2014-07-30 13:54:45 +00:00
|
|
|
Reduction r = reducer.Reduce(n);
|
|
|
|
CHECK(r.Changed());
|
|
|
|
CHECK_EQ(op_expect->opcode(), r.replacement()->op()->opcode());
|
2014-10-29 21:07:18 +00:00
|
|
|
CHECK_EQ(OperatorProperties::GetTotalInputCount(op_expect),
|
|
|
|
r.replacement()->InputCount());
|
2014-07-30 13:54:45 +00:00
|
|
|
CHECK_EQ(left_expect, r.replacement()->InputAt(0));
|
|
|
|
CHECK_EQ(right_expect, ValueOf<T>(r.replacement()->InputAt(1)->op()));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that if the given constant appears on the left, the reducer will
|
|
|
|
// swap it to be on the right.
|
|
|
|
template <typename T>
|
|
|
|
void CheckPutConstantOnRight(volatile T constant) {
|
|
|
|
// TODO(titzer): CHECK(binop->HasProperty(Operator::kCommutative));
|
|
|
|
Node* p = Parameter();
|
|
|
|
Node* k = Constant<T>(constant);
|
|
|
|
{
|
2014-10-29 21:07:18 +00:00
|
|
|
Node* n = CreateBinopNode(k, p);
|
2014-09-02 05:08:54 +00:00
|
|
|
MachineOperatorReducer reducer(&jsgraph);
|
2014-07-30 13:54:45 +00:00
|
|
|
Reduction reduction = reducer.Reduce(n);
|
|
|
|
CHECK(!reduction.Changed() || reduction.replacement() == n);
|
|
|
|
CHECK_EQ(p, n->InputAt(0));
|
|
|
|
CHECK_EQ(k, n->InputAt(1));
|
|
|
|
}
|
|
|
|
{
|
2014-10-29 21:07:18 +00:00
|
|
|
Node* n = CreateBinopNode(p, k);
|
2014-09-02 05:08:54 +00:00
|
|
|
MachineOperatorReducer reducer(&jsgraph);
|
2014-07-30 13:54:45 +00:00
|
|
|
Reduction reduction = reducer.Reduce(n);
|
|
|
|
CHECK(!reduction.Changed());
|
|
|
|
CHECK_EQ(p, n->InputAt(0));
|
|
|
|
CHECK_EQ(k, n->InputAt(1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check that if the given constant appears on the left, the reducer will
|
|
|
|
// *NOT* swap it to be on the right.
|
|
|
|
template <typename T>
|
|
|
|
void CheckDontPutConstantOnRight(volatile T constant) {
|
|
|
|
CHECK(!binop->HasProperty(Operator::kCommutative));
|
|
|
|
Node* p = Parameter();
|
|
|
|
Node* k = Constant<T>(constant);
|
2014-10-29 21:07:18 +00:00
|
|
|
Node* n = CreateBinopNode(k, p);
|
2014-09-02 05:08:54 +00:00
|
|
|
MachineOperatorReducer reducer(&jsgraph);
|
2014-07-30 13:54:45 +00:00
|
|
|
Reduction reduction = reducer.Reduce(n);
|
|
|
|
CHECK(!reduction.Changed());
|
|
|
|
CHECK_EQ(k, n->InputAt(0));
|
|
|
|
CHECK_EQ(p, n->InputAt(1));
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* Parameter(int32_t index = 0) {
|
2014-08-05 08:47:39 +00:00
|
|
|
return graph.NewNode(common.Parameter(index), graph.start());
|
2014-07-30 13:54:45 +00:00
|
|
|
}
|
2014-10-29 21:07:18 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
Node* CreateBinopNode(Node* left, Node* right) {
|
|
|
|
if (binop->ControlInputCount() > 0) {
|
|
|
|
return graph.NewNode(binop, left, right, graph.start());
|
|
|
|
} else {
|
|
|
|
return graph.NewNode(binop, left, right);
|
|
|
|
}
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceWord32And) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Word32And();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x & y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckPutConstantOnRight(33);
|
|
|
|
R.CheckPutConstantOnRight(44000);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
Node* minus_1 = R.Constant<int32_t>(-1);
|
|
|
|
|
|
|
|
R.CheckBinop(zero, x, zero); // x & 0 => 0
|
|
|
|
R.CheckBinop(zero, zero, x); // 0 & x => 0
|
|
|
|
R.CheckBinop(x, x, minus_1); // x & -1 => 0
|
|
|
|
R.CheckBinop(x, minus_1, x); // -1 & x => 0
|
|
|
|
R.CheckBinop(x, x, x); // x & x => x
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceWord32Or) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Word32Or();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x | y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckPutConstantOnRight(36);
|
|
|
|
R.CheckPutConstantOnRight(44001);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
Node* minus_1 = R.Constant<int32_t>(-1);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x & 0 => x
|
|
|
|
R.CheckBinop(x, zero, x); // 0 & x => x
|
|
|
|
R.CheckBinop(minus_1, x, minus_1); // x & -1 => -1
|
|
|
|
R.CheckBinop(minus_1, minus_1, x); // -1 & x => -1
|
|
|
|
R.CheckBinop(x, x, x); // x & x => x
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceWord32Xor) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Word32Xor();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x ^ y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckPutConstantOnRight(39);
|
|
|
|
R.CheckPutConstantOnRight(4403);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x ^ 0 => x
|
|
|
|
R.CheckBinop(x, zero, x); // 0 ^ x => x
|
|
|
|
R.CheckFoldBinop<int32_t>(0, x, x); // x ^ x => 0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceWord32Shl) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Word32Shl();
|
|
|
|
|
|
|
|
// TODO(titzer): out of range shifts
|
|
|
|
FOR_INT32_INPUTS(i) {
|
|
|
|
for (int y = 0; y < 32; y++) {
|
|
|
|
int32_t x = *i;
|
|
|
|
R.CheckFoldBinop<int32_t>(x << y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(44);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x << 0 => x
|
|
|
|
}
|
|
|
|
|
2016-08-04 12:36:39 +00:00
|
|
|
TEST(ReduceWord64Shl) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Word64Shl();
|
|
|
|
|
|
|
|
FOR_INT64_INPUTS(i) {
|
|
|
|
for (int64_t y = 0; y < 64; y++) {
|
|
|
|
int64_t x = *i;
|
|
|
|
R.CheckFoldBinop<int64_t>(x << y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(44);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int64_t>(0);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x << 0 => x
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
TEST(ReduceWord32Shr) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Word32Shr();
|
|
|
|
|
|
|
|
// TODO(titzer): test out of range shifts
|
|
|
|
FOR_UINT32_INPUTS(i) {
|
|
|
|
for (uint32_t y = 0; y < 32; y++) {
|
|
|
|
uint32_t x = *i;
|
|
|
|
R.CheckFoldBinop<int32_t>(x >> y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(44);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x >>> 0 => x
|
|
|
|
}
|
|
|
|
|
2016-08-04 12:36:39 +00:00
|
|
|
TEST(ReduceWord64Shr) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Word64Shr();
|
|
|
|
|
|
|
|
FOR_UINT64_INPUTS(i) {
|
|
|
|
for (uint64_t y = 0; y < 64; y++) {
|
|
|
|
uint64_t x = *i;
|
|
|
|
R.CheckFoldBinop<int64_t>(x >> y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(44);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int64_t>(0);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x >>> 0 => x
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
TEST(ReduceWord32Sar) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Word32Sar();
|
|
|
|
|
|
|
|
// TODO(titzer): test out of range shifts
|
|
|
|
FOR_INT32_INPUTS(i) {
|
|
|
|
for (int32_t y = 0; y < 32; y++) {
|
|
|
|
int32_t x = *i;
|
|
|
|
R.CheckFoldBinop<int32_t>(x >> y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(44);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x >> 0 => x
|
|
|
|
}
|
|
|
|
|
2016-08-04 12:36:39 +00:00
|
|
|
TEST(ReduceWord64Sar) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Word64Sar();
|
|
|
|
|
|
|
|
FOR_INT64_INPUTS(i) {
|
|
|
|
for (int64_t y = 0; y < 64; y++) {
|
|
|
|
int64_t x = *i;
|
|
|
|
R.CheckFoldBinop<int64_t>(x >> y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(44);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int64_t>(0);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x >> 0 => x
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
2014-11-20 13:09:04 +00:00
|
|
|
static void CheckJsShift(ReducerTester* R) {
|
2015-12-07 05:36:41 +00:00
|
|
|
CHECK(R->machine.Word32ShiftIsSafe());
|
2014-11-20 13:09:04 +00:00
|
|
|
|
|
|
|
Node* x = R->Parameter(0);
|
|
|
|
Node* y = R->Parameter(1);
|
2017-12-02 00:30:37 +00:00
|
|
|
Node* thirty_one = R->Constant<int32_t>(0x1F);
|
2014-11-20 13:09:04 +00:00
|
|
|
Node* y_and_thirty_one =
|
|
|
|
R->graph.NewNode(R->machine.Word32And(), y, thirty_one);
|
|
|
|
|
|
|
|
// If the underlying machine shift instructions 'and' their right operand
|
2017-12-02 00:30:37 +00:00
|
|
|
// with 0x1F then: x << (y & 0x1F) => x << y
|
2014-11-20 13:09:04 +00:00
|
|
|
R->CheckFoldBinop(x, y, x, y_and_thirty_one);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceJsShifts) {
|
|
|
|
ReducerTester R(0, MachineOperatorBuilder::kWord32ShiftIsSafe);
|
|
|
|
|
|
|
|
R.binop = R.machine.Word32Shl();
|
|
|
|
CheckJsShift(&R);
|
|
|
|
|
|
|
|
R.binop = R.machine.Word32Shr();
|
|
|
|
CheckJsShift(&R);
|
|
|
|
|
|
|
|
R.binop = R.machine.Word32Sar();
|
|
|
|
CheckJsShift(&R);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(Word32Equal) {
|
2014-07-30 13:54:45 +00:00
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Word32Equal();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x == y ? 1 : 0, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckPutConstantOnRight(48);
|
|
|
|
R.CheckPutConstantOnRight(-48);
|
|
|
|
|
|
|
|
Node* x = R.Parameter(0);
|
|
|
|
Node* y = R.Parameter(1);
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
Node* sub = R.graph.NewNode(R.machine.Int32Sub(), x, y);
|
|
|
|
|
|
|
|
R.CheckFoldBinop<int32_t>(1, x, x); // x == x => 1
|
|
|
|
R.CheckFoldBinop(x, y, sub, zero); // x - y == 0 => x == y
|
|
|
|
R.CheckFoldBinop(x, y, zero, sub); // 0 == x - y => x == y
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceInt32Add) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Int32Add();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x + y, x, y); // TODO(titzer): signed overflow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckPutConstantOnRight(41);
|
|
|
|
R.CheckPutConstantOnRight(4407);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x + 0 => x
|
|
|
|
R.CheckBinop(x, zero, x); // 0 + x => x
|
|
|
|
}
|
|
|
|
|
2016-08-04 12:36:39 +00:00
|
|
|
TEST(ReduceInt64Add) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Int64Add();
|
|
|
|
|
|
|
|
FOR_INT64_INPUTS(pl) {
|
|
|
|
FOR_INT64_INPUTS(pr) {
|
|
|
|
int64_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int64_t>(x + y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckPutConstantOnRight(41);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int64_t>(0);
|
|
|
|
R.CheckBinop(x, x, zero); // x + 0 => x
|
|
|
|
R.CheckBinop(x, zero, x); // 0 + x => x
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
TEST(ReduceInt32Sub) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Int32Sub();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x - y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(412);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x - 0 => x
|
|
|
|
}
|
|
|
|
|
2016-08-04 12:36:39 +00:00
|
|
|
TEST(ReduceInt64Sub) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Int64Sub();
|
|
|
|
|
|
|
|
FOR_INT64_INPUTS(pl) {
|
|
|
|
FOR_INT64_INPUTS(pr) {
|
|
|
|
int64_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int64_t>(x - y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(42);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int64_t>(0);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, zero); // x - 0 => x
|
|
|
|
R.CheckFoldBinop<int64_t>(0, x, x); // x - x => 0
|
|
|
|
|
|
|
|
Node* k = R.Constant<int64_t>(6);
|
|
|
|
|
|
|
|
R.CheckFoldBinop<int64_t>(x, R.machine.Int64Add(), -6, x,
|
|
|
|
k); // x - K => x + -K
|
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
TEST(ReduceInt32Mul) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Int32Mul();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x * y, x, y); // TODO(titzer): signed overflow
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckPutConstantOnRight(4111);
|
|
|
|
R.CheckPutConstantOnRight(-4407);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
Node* one = R.Constant<int32_t>(1);
|
|
|
|
Node* minus_one = R.Constant<int32_t>(-1);
|
|
|
|
|
|
|
|
R.CheckBinop(zero, x, zero); // x * 0 => 0
|
|
|
|
R.CheckBinop(zero, zero, x); // 0 * x => 0
|
|
|
|
R.CheckBinop(x, x, one); // x * 1 => x
|
|
|
|
R.CheckBinop(x, one, x); // 1 * x => x
|
|
|
|
R.CheckFoldBinop<int32_t>(0, R.machine.Int32Sub(), x, minus_one,
|
|
|
|
x); // -1 * x => 0 - x
|
|
|
|
R.CheckFoldBinop<int32_t>(0, R.machine.Int32Sub(), x, x,
|
|
|
|
minus_one); // x * -1 => 0 - x
|
|
|
|
|
|
|
|
for (int32_t n = 1; n < 31; ++n) {
|
|
|
|
Node* multiplier = R.Constant<int32_t>(1 << n);
|
|
|
|
R.CheckFoldBinop<int32_t>(x, R.machine.Word32Shl(), n, x,
|
|
|
|
multiplier); // x * 2^n => x << n
|
|
|
|
R.CheckFoldBinop<int32_t>(x, R.machine.Word32Shl(), n, multiplier,
|
|
|
|
x); // 2^n * x => x << n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceInt32Div) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Int32Div();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
if (y == 0) continue; // TODO(titzer): test / 0
|
|
|
|
int32_t r = y == -1 ? -x : x / y; // INT_MIN / -1 may explode in C
|
|
|
|
R.CheckFoldBinop<int32_t>(r, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(41111);
|
|
|
|
R.CheckDontPutConstantOnRight(-44071);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* one = R.Constant<int32_t>(1);
|
|
|
|
Node* minus_one = R.Constant<int32_t>(-1);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, one); // x / 1 => x
|
|
|
|
// TODO(titzer): // 0 / x => 0 if x != 0
|
|
|
|
// TODO(titzer): // x / 2^n => x >> n and round
|
|
|
|
R.CheckFoldBinop<int32_t>(0, R.machine.Int32Sub(), x, x,
|
|
|
|
minus_one); // x / -1 => 0 - x
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-01 10:39:11 +00:00
|
|
|
TEST(ReduceUint32Div) {
|
2014-07-30 13:54:45 +00:00
|
|
|
ReducerTester R;
|
2014-10-01 10:39:11 +00:00
|
|
|
R.binop = R.machine.Uint32Div();
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
FOR_UINT32_INPUTS(pl) {
|
|
|
|
FOR_UINT32_INPUTS(pr) {
|
|
|
|
uint32_t x = *pl, y = *pr;
|
|
|
|
if (y == 0) continue; // TODO(titzer): test / 0
|
|
|
|
R.CheckFoldBinop<int32_t>(x / y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(41311);
|
|
|
|
R.CheckDontPutConstantOnRight(-44371);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* one = R.Constant<int32_t>(1);
|
|
|
|
|
|
|
|
R.CheckBinop(x, x, one); // x / 1 => x
|
|
|
|
// TODO(titzer): // 0 / x => 0 if x != 0
|
|
|
|
|
|
|
|
for (uint32_t n = 1; n < 32; ++n) {
|
|
|
|
Node* divisor = R.Constant<int32_t>(1u << n);
|
|
|
|
R.CheckFoldBinop<int32_t>(x, R.machine.Word32Shr(), n, x,
|
|
|
|
divisor); // x / 2^n => x >> n
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceInt32Mod) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Int32Mod();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
if (y == 0) continue; // TODO(titzer): test % 0
|
|
|
|
int32_t r = y == -1 ? 0 : x % y; // INT_MIN % -1 may explode in C
|
|
|
|
R.CheckFoldBinop<int32_t>(r, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(413);
|
|
|
|
R.CheckDontPutConstantOnRight(-4401);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* one = R.Constant<int32_t>(1);
|
|
|
|
|
|
|
|
R.CheckFoldBinop<int32_t>(0, x, one); // x % 1 => 0
|
|
|
|
// TODO(titzer): // x % 2^n => x & 2^n-1 and round
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-01 10:39:11 +00:00
|
|
|
TEST(ReduceUint32Mod) {
|
2014-07-30 13:54:45 +00:00
|
|
|
ReducerTester R;
|
2014-10-01 10:39:11 +00:00
|
|
|
R.binop = R.machine.Uint32Mod();
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
uint32_t x = *pl, y = *pr;
|
|
|
|
if (y == 0) continue; // TODO(titzer): test x % 0
|
|
|
|
R.CheckFoldBinop<int32_t>(x % y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(417);
|
|
|
|
R.CheckDontPutConstantOnRight(-4371);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* one = R.Constant<int32_t>(1);
|
|
|
|
|
|
|
|
R.CheckFoldBinop<int32_t>(0, x, one); // x % 1 => 0
|
|
|
|
|
|
|
|
for (uint32_t n = 1; n < 32; ++n) {
|
|
|
|
Node* divisor = R.Constant<int32_t>(1u << n);
|
|
|
|
R.CheckFoldBinop<int32_t>(x, R.machine.Word32And(), (1u << n) - 1, x,
|
|
|
|
divisor); // x % 2^n => x & 2^n-1
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceInt32LessThan) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Int32LessThan();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x < y ? 1 : 0, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(41399);
|
|
|
|
R.CheckDontPutConstantOnRight(-440197);
|
|
|
|
|
|
|
|
Node* x = R.Parameter(0);
|
|
|
|
|
|
|
|
R.CheckFoldBinop<int32_t>(0, x, x); // x < x => 0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceInt32LessThanOrEqual) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Int32LessThanOrEqual();
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(pl) {
|
|
|
|
FOR_INT32_INPUTS(pr) {
|
|
|
|
int32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x <= y ? 1 : 0, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FOR_INT32_INPUTS(i) { R.CheckDontPutConstantOnRight<int32_t>(*i); }
|
|
|
|
|
|
|
|
Node* x = R.Parameter(0);
|
|
|
|
|
|
|
|
R.CheckFoldBinop<int32_t>(1, x, x); // x <= x => 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceUint32LessThan) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Uint32LessThan();
|
|
|
|
|
|
|
|
FOR_UINT32_INPUTS(pl) {
|
|
|
|
FOR_UINT32_INPUTS(pr) {
|
|
|
|
uint32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x < y ? 1 : 0, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(41399);
|
|
|
|
R.CheckDontPutConstantOnRight(-440197);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* max = R.maxuint32;
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
|
|
|
|
R.CheckFoldBinop<int32_t>(0, max, x); // M < x => 0
|
|
|
|
R.CheckFoldBinop<int32_t>(0, x, zero); // x < 0 => 0
|
|
|
|
R.CheckFoldBinop<int32_t>(0, x, x); // x < x => 0
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceUint32LessThanOrEqual) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Uint32LessThanOrEqual();
|
|
|
|
|
|
|
|
FOR_UINT32_INPUTS(pl) {
|
|
|
|
FOR_UINT32_INPUTS(pr) {
|
|
|
|
uint32_t x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<int32_t>(x <= y ? 1 : 0, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
R.CheckDontPutConstantOnRight(41399);
|
|
|
|
R.CheckDontPutConstantOnRight(-440197);
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* max = R.maxuint32;
|
|
|
|
Node* zero = R.Constant<int32_t>(0);
|
|
|
|
|
|
|
|
R.CheckFoldBinop<int32_t>(1, x, max); // x <= M => 1
|
|
|
|
R.CheckFoldBinop<int32_t>(1, zero, x); // 0 <= x => 1
|
|
|
|
R.CheckFoldBinop<int32_t>(1, x, x); // x <= x => 1
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST(ReduceLoadStore) {
|
|
|
|
ReducerTester R;
|
|
|
|
|
|
|
|
Node* base = R.Constant<int32_t>(11);
|
|
|
|
Node* index = R.Constant<int32_t>(4);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* load = R.graph.NewNode(R.machine.Load(MachineType::Int32()), base,
|
|
|
|
index, R.graph.start(), R.graph.start());
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
{
|
2014-09-02 05:08:54 +00:00
|
|
|
MachineOperatorReducer reducer(&R.jsgraph);
|
2014-07-30 13:54:45 +00:00
|
|
|
Reduction reduction = reducer.Reduce(load);
|
|
|
|
CHECK(!reduction.Changed()); // loads should not be reduced.
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2015-12-11 15:34:00 +00:00
|
|
|
Node* store =
|
|
|
|
R.graph.NewNode(R.machine.Store(StoreRepresentation(
|
|
|
|
MachineRepresentation::kWord32, kNoWriteBarrier)),
|
|
|
|
base, index, load, load, R.graph.start());
|
2014-09-02 05:08:54 +00:00
|
|
|
MachineOperatorReducer reducer(&R.jsgraph);
|
2014-07-30 13:54:45 +00:00
|
|
|
Reduction reduction = reducer.Reduce(store);
|
|
|
|
CHECK(!reduction.Changed()); // stores should not be reduced.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-08 08:39:38 +00:00
|
|
|
TEST(ReduceFloat32Sub) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Float32Sub();
|
|
|
|
|
|
|
|
FOR_FLOAT32_INPUTS(pl) {
|
|
|
|
FOR_FLOAT32_INPUTS(pr) {
|
|
|
|
float x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<float>(x - y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* nan = R.Constant<float>(std::numeric_limits<float>::quiet_NaN());
|
|
|
|
|
2017-01-26 12:45:33 +00:00
|
|
|
// nan - x => nan
|
|
|
|
R.CheckFoldBinop(std::numeric_limits<float>::quiet_NaN(), nan, x);
|
|
|
|
// x - nan => nan
|
|
|
|
R.CheckFoldBinop(std::numeric_limits<float>::quiet_NaN(), x, nan);
|
2016-08-08 08:39:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST(ReduceFloat64Sub) {
|
|
|
|
ReducerTester R;
|
|
|
|
R.binop = R.machine.Float64Sub();
|
|
|
|
|
|
|
|
FOR_FLOAT64_INPUTS(pl) {
|
|
|
|
FOR_FLOAT64_INPUTS(pr) {
|
|
|
|
double x = *pl, y = *pr;
|
|
|
|
R.CheckFoldBinop<double>(x - y, x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Node* x = R.Parameter();
|
|
|
|
Node* nan = R.Constant<double>(std::numeric_limits<double>::quiet_NaN());
|
|
|
|
|
2017-01-26 12:45:33 +00:00
|
|
|
// nan - x => nan
|
|
|
|
R.CheckFoldBinop(std::numeric_limits<double>::quiet_NaN(), nan, x);
|
|
|
|
// x - nan => nan
|
|
|
|
R.CheckFoldBinop(std::numeric_limits<double>::quiet_NaN(), x, nan);
|
2016-08-08 08:39:38 +00:00
|
|
|
}
|
2014-07-30 13:54:45 +00:00
|
|
|
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Word64And
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Word64Or
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Word64Xor
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Word64Equal
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Word64Not
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Int64Mul
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Int64UMul
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Int64Div
|
2014-10-01 10:39:11 +00:00
|
|
|
// TODO(titzer): test MachineOperatorReducer for Uint64Div
|
2014-07-30 13:54:45 +00:00
|
|
|
// TODO(titzer): test MachineOperatorReducer for Int64Mod
|
2014-10-01 10:39:11 +00:00
|
|
|
// TODO(titzer): test MachineOperatorReducer for Uint64Mod
|
2014-07-30 13:54:45 +00:00
|
|
|
// TODO(titzer): test MachineOperatorReducer for Int64Neg
|
2014-08-01 10:54:58 +00:00
|
|
|
// TODO(titzer): test MachineOperatorReducer for ChangeInt32ToFloat64
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for ChangeFloat64ToInt32
|
2014-07-30 13:54:45 +00:00
|
|
|
// TODO(titzer): test MachineOperatorReducer for Float64Compare
|
2015-01-30 09:29:25 +00:00
|
|
|
// TODO(titzer): test MachineOperatorReducer for Float64Add
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Float64Sub
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Float64Mul
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Float64Div
|
|
|
|
// TODO(titzer): test MachineOperatorReducer for Float64Mod
|
2015-10-30 09:16:26 +00:00
|
|
|
|
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|