| Index: test/cctest/compiler/test-simplified-lowering.cc
|
| diff --git a/test/cctest/compiler/test-simplified-lowering.cc b/test/cctest/compiler/test-simplified-lowering.cc
|
| index 5cbc2d9613fabd31cbd3ddf0c0493af45f4465f2..59ff627f6b9b61c6fc5e8a8d33b01d3b14b0c6ac 100644
|
| --- a/test/cctest/compiler/test-simplified-lowering.cc
|
| +++ b/test/cctest/compiler/test-simplified-lowering.cc
|
| @@ -1529,3 +1529,190 @@ TEST(UpdatePhi) {
|
| RepresentationOf(OpParameter<MachineType>(phi)));
|
| }
|
| }
|
| +
|
| +
|
| +TEST(NumberMultiply_TruncatingToInt32) {
|
| + int32_t constants[] = {-100, -10, -1, 0, 1, 100, 1000};
|
| +
|
| + for (size_t i = 0; i < arraysize(constants); i++) {
|
| + TestingGraph t(Type::Signed32());
|
| + Node* k = t.jsgraph.Constant(constants[i]);
|
| + Node* mul = t.graph()->NewNode(t.simplified()->NumberMultiply(), t.p0, k);
|
| + Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mul);
|
| + t.Return(trunc);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kInt32Mul, mul->opcode());
|
| + }
|
| +}
|
| +
|
| +
|
| +TEST(NumberMultiply_ConstantOutOfRange) {
|
| + TestingGraph t(Type::Signed32());
|
| + Node* k = t.jsgraph.Constant(1000000023);
|
| + Node* mul = t.graph()->NewNode(t.simplified()->NumberMultiply(), t.p0, k);
|
| + Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mul);
|
| + t.Return(trunc);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kFloat64Mul, mul->opcode());
|
| +}
|
| +
|
| +
|
| +TEST(NumberMultiply_NonTruncating) {
|
| + TestingGraph t(Type::Signed32());
|
| + Node* k = t.jsgraph.Constant(111);
|
| + Node* mul = t.graph()->NewNode(t.simplified()->NumberMultiply(), t.p0, k);
|
| + t.Return(mul);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kFloat64Mul, mul->opcode());
|
| +}
|
| +
|
| +
|
| +TEST(NumberDivide_TruncatingToInt32) {
|
| + int32_t constants[] = {-100, -10, 1, 4, 100, 1000};
|
| +
|
| + for (size_t i = 0; i < arraysize(constants); i++) {
|
| + TestingGraph t(Type::Signed32());
|
| + Node* k = t.jsgraph.Constant(constants[i]);
|
| + Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k);
|
| + Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), div);
|
| + t.Return(trunc);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kInt32Div, div->opcode());
|
| + }
|
| +}
|
| +
|
| +
|
| +TEST(NumberDivide_TruncatingToUint32) {
|
| + double constants[] = {1, 3, 100, 1000, 100998348};
|
| +
|
| + for (size_t i = 0; i < arraysize(constants); i++) {
|
| + TestingGraph t(Type::Unsigned32());
|
| + Node* k = t.jsgraph.Constant(constants[i]);
|
| + Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k);
|
| + Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), div);
|
| + t.Return(trunc);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kUint32Div, div->opcode());
|
| + }
|
| +}
|
| +
|
| +
|
| +TEST(NumberDivide_BadConstants) {
|
| + int32_t constants[] = {-1, 0};
|
| +
|
| + for (size_t i = 0; i < arraysize(constants); i++) {
|
| + TestingGraph t(Type::Signed32());
|
| + Node* k = t.jsgraph.Constant(constants[i]);
|
| + Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k);
|
| + Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), div);
|
| + t.Return(trunc);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kFloat64Div, div->opcode());
|
| + }
|
| +
|
| + {
|
| + TestingGraph t(Type::Unsigned32());
|
| + Node* k = t.jsgraph.Constant(0);
|
| + Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k);
|
| + Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), div);
|
| + t.Return(trunc);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kFloat64Div, div->opcode());
|
| + }
|
| +}
|
| +
|
| +
|
| +TEST(NumberModulus_TruncatingToInt32) {
|
| + int32_t constants[] = {-100, -10, 1, 4, 100, 1000};
|
| +
|
| + for (size_t i = 0; i < arraysize(constants); i++) {
|
| + TestingGraph t(Type::Signed32());
|
| + Node* k = t.jsgraph.Constant(constants[i]);
|
| + Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k);
|
| + Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mod);
|
| + t.Return(trunc);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kInt32Mod, mod->opcode());
|
| + }
|
| +}
|
| +
|
| +
|
| +TEST(NumberModulus_TruncatingToUint32) {
|
| + double constants[] = {1, 3, 100, 1000, 100998348};
|
| +
|
| + for (size_t i = 0; i < arraysize(constants); i++) {
|
| + TestingGraph t(Type::Unsigned32());
|
| + Node* k = t.jsgraph.Constant(constants[i]);
|
| + Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k);
|
| + Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), mod);
|
| + t.Return(trunc);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kUint32Mod, mod->opcode());
|
| + }
|
| +}
|
| +
|
| +
|
| +TEST(NumberModulus_Int32) {
|
| + int32_t constants[] = {-100, -10, 1, 4, 100, 1000};
|
| +
|
| + for (size_t i = 0; i < arraysize(constants); i++) {
|
| + TestingGraph t(Type::Signed32());
|
| + Node* k = t.jsgraph.Constant(constants[i]);
|
| + Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k);
|
| + t.Return(mod);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kInt32Mod, mod->opcode());
|
| + }
|
| +}
|
| +
|
| +
|
| +TEST(NumberModulus_Uint32) {
|
| + double constants[] = {1, 3, 100, 1000, 100998348};
|
| +
|
| + for (size_t i = 0; i < arraysize(constants); i++) {
|
| + TestingGraph t(Type::Unsigned32());
|
| + Node* k = t.jsgraph.Constant(constants[i]);
|
| + Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k);
|
| + t.Return(mod);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kUint32Mod, mod->opcode());
|
| + }
|
| +}
|
| +
|
| +
|
| +TEST(NumberModulus_BadConstants) {
|
| + int32_t constants[] = {-1, 0};
|
| +
|
| + for (size_t i = 0; i < arraysize(constants); i++) {
|
| + TestingGraph t(Type::Signed32());
|
| + Node* k = t.jsgraph.Constant(constants[i]);
|
| + Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k);
|
| + Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mod);
|
| + t.Return(trunc);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kFloat64Mod, mod->opcode());
|
| + }
|
| +
|
| + {
|
| + TestingGraph t(Type::Unsigned32());
|
| + Node* k = t.jsgraph.Constant(0);
|
| + Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k);
|
| + Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), mod);
|
| + t.Return(trunc);
|
| + t.Lower();
|
| +
|
| + CHECK_EQ(IrOpcode::kFloat64Mod, mod->opcode());
|
| + }
|
| +}
|
|
|