OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include <limits> | 5 #include <limits> |
6 | 6 |
7 #include "src/compiler/access-builder.h" | 7 #include "src/compiler/access-builder.h" |
8 #include "src/compiler/control-builders.h" | 8 #include "src/compiler/control-builders.h" |
9 #include "src/compiler/generic-node-inl.h" | 9 #include "src/compiler/generic-node-inl.h" |
10 #include "src/compiler/graph-visualizer.h" | 10 #include "src/compiler/graph-visualizer.h" |
(...skipping 1511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1522 Node* phi = t.graph()->NewNode(t.common()->Phi(kMachAnyTagged, 2), load0, | 1522 Node* phi = t.graph()->NewNode(t.common()->Phi(kMachAnyTagged, 2), load0, |
1523 load1, t.start); | 1523 load1, t.start); |
1524 t.Return(t.Use(phi, kMachineTypes[i])); | 1524 t.Return(t.Use(phi, kMachineTypes[i])); |
1525 t.Lower(); | 1525 t.Lower(); |
1526 | 1526 |
1527 CHECK_EQ(IrOpcode::kPhi, phi->opcode()); | 1527 CHECK_EQ(IrOpcode::kPhi, phi->opcode()); |
1528 CHECK_EQ(RepresentationOf(kMachineTypes[i]), | 1528 CHECK_EQ(RepresentationOf(kMachineTypes[i]), |
1529 RepresentationOf(OpParameter<MachineType>(phi))); | 1529 RepresentationOf(OpParameter<MachineType>(phi))); |
1530 } | 1530 } |
1531 } | 1531 } |
| 1532 |
| 1533 |
| 1534 TEST(NumberMultiply_TruncatingToInt32) { |
| 1535 int32_t constants[] = {-100, -10, -1, 0, 1, 100, 1000}; |
| 1536 |
| 1537 for (size_t i = 0; i < arraysize(constants); i++) { |
| 1538 TestingGraph t(Type::Signed32()); |
| 1539 Node* k = t.jsgraph.Constant(constants[i]); |
| 1540 Node* mul = t.graph()->NewNode(t.simplified()->NumberMultiply(), t.p0, k); |
| 1541 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mul); |
| 1542 t.Return(trunc); |
| 1543 t.Lower(); |
| 1544 |
| 1545 CHECK_EQ(IrOpcode::kInt32Mul, mul->opcode()); |
| 1546 } |
| 1547 } |
| 1548 |
| 1549 |
| 1550 TEST(NumberMultiply_ConstantOutOfRange) { |
| 1551 TestingGraph t(Type::Signed32()); |
| 1552 Node* k = t.jsgraph.Constant(1000000023); |
| 1553 Node* mul = t.graph()->NewNode(t.simplified()->NumberMultiply(), t.p0, k); |
| 1554 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mul); |
| 1555 t.Return(trunc); |
| 1556 t.Lower(); |
| 1557 |
| 1558 CHECK_EQ(IrOpcode::kFloat64Mul, mul->opcode()); |
| 1559 } |
| 1560 |
| 1561 |
| 1562 TEST(NumberMultiply_NonTruncating) { |
| 1563 TestingGraph t(Type::Signed32()); |
| 1564 Node* k = t.jsgraph.Constant(111); |
| 1565 Node* mul = t.graph()->NewNode(t.simplified()->NumberMultiply(), t.p0, k); |
| 1566 t.Return(mul); |
| 1567 t.Lower(); |
| 1568 |
| 1569 CHECK_EQ(IrOpcode::kFloat64Mul, mul->opcode()); |
| 1570 } |
| 1571 |
| 1572 |
| 1573 TEST(NumberDivide_TruncatingToInt32) { |
| 1574 int32_t constants[] = {-100, -10, 1, 4, 100, 1000}; |
| 1575 |
| 1576 for (size_t i = 0; i < arraysize(constants); i++) { |
| 1577 TestingGraph t(Type::Signed32()); |
| 1578 Node* k = t.jsgraph.Constant(constants[i]); |
| 1579 Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k); |
| 1580 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), div); |
| 1581 t.Return(trunc); |
| 1582 t.Lower(); |
| 1583 |
| 1584 CHECK_EQ(IrOpcode::kInt32Div, div->opcode()); |
| 1585 } |
| 1586 } |
| 1587 |
| 1588 |
| 1589 TEST(NumberDivide_TruncatingToUint32) { |
| 1590 double constants[] = {1, 3, 100, 1000, 100998348}; |
| 1591 |
| 1592 for (size_t i = 0; i < arraysize(constants); i++) { |
| 1593 TestingGraph t(Type::Unsigned32()); |
| 1594 Node* k = t.jsgraph.Constant(constants[i]); |
| 1595 Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k); |
| 1596 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), div); |
| 1597 t.Return(trunc); |
| 1598 t.Lower(); |
| 1599 |
| 1600 CHECK_EQ(IrOpcode::kUint32Div, div->opcode()); |
| 1601 } |
| 1602 } |
| 1603 |
| 1604 |
| 1605 TEST(NumberDivide_BadConstants) { |
| 1606 int32_t constants[] = {-1, 0}; |
| 1607 |
| 1608 for (size_t i = 0; i < arraysize(constants); i++) { |
| 1609 TestingGraph t(Type::Signed32()); |
| 1610 Node* k = t.jsgraph.Constant(constants[i]); |
| 1611 Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k); |
| 1612 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), div); |
| 1613 t.Return(trunc); |
| 1614 t.Lower(); |
| 1615 |
| 1616 CHECK_EQ(IrOpcode::kFloat64Div, div->opcode()); |
| 1617 } |
| 1618 |
| 1619 { |
| 1620 TestingGraph t(Type::Unsigned32()); |
| 1621 Node* k = t.jsgraph.Constant(0); |
| 1622 Node* div = t.graph()->NewNode(t.simplified()->NumberDivide(), t.p0, k); |
| 1623 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), div); |
| 1624 t.Return(trunc); |
| 1625 t.Lower(); |
| 1626 |
| 1627 CHECK_EQ(IrOpcode::kFloat64Div, div->opcode()); |
| 1628 } |
| 1629 } |
| 1630 |
| 1631 |
| 1632 TEST(NumberModulus_TruncatingToInt32) { |
| 1633 int32_t constants[] = {-100, -10, 1, 4, 100, 1000}; |
| 1634 |
| 1635 for (size_t i = 0; i < arraysize(constants); i++) { |
| 1636 TestingGraph t(Type::Signed32()); |
| 1637 Node* k = t.jsgraph.Constant(constants[i]); |
| 1638 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); |
| 1639 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mod); |
| 1640 t.Return(trunc); |
| 1641 t.Lower(); |
| 1642 |
| 1643 CHECK_EQ(IrOpcode::kInt32Mod, mod->opcode()); |
| 1644 } |
| 1645 } |
| 1646 |
| 1647 |
| 1648 TEST(NumberModulus_TruncatingToUint32) { |
| 1649 double constants[] = {1, 3, 100, 1000, 100998348}; |
| 1650 |
| 1651 for (size_t i = 0; i < arraysize(constants); i++) { |
| 1652 TestingGraph t(Type::Unsigned32()); |
| 1653 Node* k = t.jsgraph.Constant(constants[i]); |
| 1654 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); |
| 1655 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), mod); |
| 1656 t.Return(trunc); |
| 1657 t.Lower(); |
| 1658 |
| 1659 CHECK_EQ(IrOpcode::kUint32Mod, mod->opcode()); |
| 1660 } |
| 1661 } |
| 1662 |
| 1663 |
| 1664 TEST(NumberModulus_Int32) { |
| 1665 int32_t constants[] = {-100, -10, 1, 4, 100, 1000}; |
| 1666 |
| 1667 for (size_t i = 0; i < arraysize(constants); i++) { |
| 1668 TestingGraph t(Type::Signed32()); |
| 1669 Node* k = t.jsgraph.Constant(constants[i]); |
| 1670 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); |
| 1671 t.Return(mod); |
| 1672 t.Lower(); |
| 1673 |
| 1674 CHECK_EQ(IrOpcode::kInt32Mod, mod->opcode()); |
| 1675 } |
| 1676 } |
| 1677 |
| 1678 |
| 1679 TEST(NumberModulus_Uint32) { |
| 1680 double constants[] = {1, 3, 100, 1000, 100998348}; |
| 1681 |
| 1682 for (size_t i = 0; i < arraysize(constants); i++) { |
| 1683 TestingGraph t(Type::Unsigned32()); |
| 1684 Node* k = t.jsgraph.Constant(constants[i]); |
| 1685 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); |
| 1686 t.Return(mod); |
| 1687 t.Lower(); |
| 1688 |
| 1689 CHECK_EQ(IrOpcode::kUint32Mod, mod->opcode()); |
| 1690 } |
| 1691 } |
| 1692 |
| 1693 |
| 1694 TEST(NumberModulus_BadConstants) { |
| 1695 int32_t constants[] = {-1, 0}; |
| 1696 |
| 1697 for (size_t i = 0; i < arraysize(constants); i++) { |
| 1698 TestingGraph t(Type::Signed32()); |
| 1699 Node* k = t.jsgraph.Constant(constants[i]); |
| 1700 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); |
| 1701 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToInt32(), mod); |
| 1702 t.Return(trunc); |
| 1703 t.Lower(); |
| 1704 |
| 1705 CHECK_EQ(IrOpcode::kFloat64Mod, mod->opcode()); |
| 1706 } |
| 1707 |
| 1708 { |
| 1709 TestingGraph t(Type::Unsigned32()); |
| 1710 Node* k = t.jsgraph.Constant(0); |
| 1711 Node* mod = t.graph()->NewNode(t.simplified()->NumberModulus(), t.p0, k); |
| 1712 Node* trunc = t.graph()->NewNode(t.simplified()->NumberToUint32(), mod); |
| 1713 t.Return(trunc); |
| 1714 t.Lower(); |
| 1715 |
| 1716 CHECK_EQ(IrOpcode::kFloat64Mod, mod->opcode()); |
| 1717 } |
| 1718 } |
OLD | NEW |