Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(772)

Side by Side Diff: test/unittests/compiler/arm64/instruction-selector-arm64-unittest.cc

Issue 1180863002: [turbofan] Prefer add/shift over madd on ARM64 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/compiler/arm64/instruction-selector-arm64.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "test/unittests/compiler/instruction-selector-unittest.h" 5 #include "test/unittests/compiler/instruction-selector-unittest.h"
6 6
7 namespace v8 { 7 namespace v8 {
8 namespace internal { 8 namespace internal {
9 namespace compiler { 9 namespace compiler {
10 10
(...skipping 1623 matching lines...) Expand 10 before | Expand all | Expand 10 after
1634 m.Return(m.Int32Mul(m.Int32Constant((1 << k) + 1), m.Parameter(0))); 1634 m.Return(m.Int32Mul(m.Int32Constant((1 << k) + 1), m.Parameter(0)));
1635 Stream s = m.Build(); 1635 Stream s = m.Build();
1636 ASSERT_EQ(1U, s.size()); 1636 ASSERT_EQ(1U, s.size());
1637 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode()); 1637 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
1638 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); 1638 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1639 ASSERT_EQ(3U, s[0]->InputCount()); 1639 ASSERT_EQ(3U, s[0]->InputCount());
1640 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); 1640 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1)));
1641 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2))); 1641 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2)));
1642 EXPECT_EQ(1U, s[0]->OutputCount()); 1642 EXPECT_EQ(1U, s[0]->OutputCount());
1643 } 1643 }
1644 // x * (2^k + 1) + c -> x + (x << k) + c
1645 TRACED_FORRANGE(int32_t, k, 1, 30) {
1646 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
1647 m.Return(
1648 m.Int32Add(m.Int32Mul(m.Parameter(0), m.Int32Constant((1 << k) + 1)),
1649 m.Parameter(1)));
1650 Stream s = m.Build();
1651 ASSERT_EQ(2U, s.size());
1652 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
1653 EXPECT_EQ(kArm64Add32, s[1]->arch_opcode());
1654 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1655 ASSERT_EQ(3U, s[0]->InputCount());
1656 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1)));
1657 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2)));
1658 EXPECT_EQ(1U, s[0]->OutputCount());
1659 }
1660 // (2^k + 1) * x + c -> x + (x << k) + c
1661 TRACED_FORRANGE(int32_t, k, 1, 30) {
1662 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
1663 m.Return(
1664 m.Int32Add(m.Int32Mul(m.Int32Constant((1 << k) + 1), m.Parameter(0)),
1665 m.Parameter(1)));
1666 Stream s = m.Build();
1667 ASSERT_EQ(2U, s.size());
1668 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
1669 EXPECT_EQ(kArm64Add32, s[1]->arch_opcode());
1670 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1671 ASSERT_EQ(3U, s[0]->InputCount());
1672 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1)));
1673 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2)));
1674 EXPECT_EQ(1U, s[0]->OutputCount());
1675 }
1676 // c + x * (2^k + 1) -> c + x + (x << k)
1677 TRACED_FORRANGE(int32_t, k, 1, 30) {
1678 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
1679 m.Return(
1680 m.Int32Add(m.Parameter(0),
1681 m.Int32Mul(m.Parameter(1), m.Int32Constant((1 << k) + 1))));
1682 Stream s = m.Build();
1683 ASSERT_EQ(2U, s.size());
1684 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
1685 EXPECT_EQ(kArm64Add32, s[1]->arch_opcode());
1686 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1687 ASSERT_EQ(3U, s[0]->InputCount());
1688 EXPECT_EQ(s.ToVreg(s[0]->InputAt(1)), s.ToVreg(s[0]->InputAt(1)));
1689 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2)));
1690 EXPECT_EQ(1U, s[0]->OutputCount());
1691 }
1692 // c + (2^k + 1) * x -> c + x + (x << k)
1693 TRACED_FORRANGE(int32_t, k, 1, 30) {
1694 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
1695 m.Return(
1696 m.Int32Add(m.Parameter(0),
1697 m.Int32Mul(m.Int32Constant((1 << k) + 1), m.Parameter(1))));
1698 Stream s = m.Build();
1699 ASSERT_EQ(2U, s.size());
1700 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
1701 EXPECT_EQ(kArm64Add32, s[1]->arch_opcode());
1702 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1703 ASSERT_EQ(3U, s[0]->InputCount());
1704 EXPECT_EQ(s.ToVreg(s[0]->InputAt(1)), s.ToVreg(s[0]->InputAt(1)));
1705 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2)));
1706 EXPECT_EQ(1U, s[0]->OutputCount());
1707 }
1708 // c - x * (2^k + 1) -> c - x + (x << k)
1709 TRACED_FORRANGE(int32_t, k, 1, 30) {
1710 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
1711 m.Return(
1712 m.Int32Sub(m.Parameter(0),
1713 m.Int32Mul(m.Parameter(1), m.Int32Constant((1 << k) + 1))));
1714 Stream s = m.Build();
1715 ASSERT_EQ(2U, s.size());
1716 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
1717 EXPECT_EQ(kArm64Sub32, s[1]->arch_opcode());
1718 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1719 ASSERT_EQ(3U, s[0]->InputCount());
1720 EXPECT_EQ(s.ToVreg(s[0]->InputAt(1)), s.ToVreg(s[0]->InputAt(1)));
1721 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2)));
1722 EXPECT_EQ(1U, s[0]->OutputCount());
1723 }
1724 // c - (2^k + 1) * x -> c - x + (x << k)
1725 TRACED_FORRANGE(int32_t, k, 1, 30) {
1726 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32);
1727 m.Return(
1728 m.Int32Sub(m.Parameter(0),
1729 m.Int32Mul(m.Int32Constant((1 << k) + 1), m.Parameter(1))));
1730 Stream s = m.Build();
1731 ASSERT_EQ(2U, s.size());
1732 EXPECT_EQ(kArm64Add32, s[0]->arch_opcode());
1733 EXPECT_EQ(kArm64Sub32, s[1]->arch_opcode());
1734 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1735 ASSERT_EQ(3U, s[0]->InputCount());
1736 EXPECT_EQ(s.ToVreg(s[0]->InputAt(1)), s.ToVreg(s[0]->InputAt(1)));
1737 EXPECT_EQ(k, s.ToInt32(s[0]->InputAt(2)));
1738 EXPECT_EQ(1U, s[0]->OutputCount());
1739 }
1644 } 1740 }
1645 1741
1646 1742
1647 TEST_F(InstructionSelectorTest, Int64MulWithImmediate) { 1743 TEST_F(InstructionSelectorTest, Int64MulWithImmediate) {
1648 // x * (2^k + 1) -> x + (x << k) 1744 // x * (2^k + 1) -> x + (x << k)
1649 TRACED_FORRANGE(int64_t, k, 1, 62) { 1745 TRACED_FORRANGE(int64_t, k, 1, 62) {
1650 StreamBuilder m(this, kMachInt64, kMachInt64); 1746 StreamBuilder m(this, kMachInt64, kMachInt64);
1651 m.Return(m.Int64Mul(m.Parameter(0), m.Int64Constant((1L << k) + 1))); 1747 m.Return(m.Int64Mul(m.Parameter(0), m.Int64Constant((1L << k) + 1)));
1652 Stream s = m.Build(); 1748 Stream s = m.Build();
1653 ASSERT_EQ(1U, s.size()); 1749 ASSERT_EQ(1U, s.size());
(...skipping 10 matching lines...) Expand all
1664 m.Return(m.Int64Mul(m.Int64Constant((1L << k) + 1), m.Parameter(0))); 1760 m.Return(m.Int64Mul(m.Int64Constant((1L << k) + 1), m.Parameter(0)));
1665 Stream s = m.Build(); 1761 Stream s = m.Build();
1666 ASSERT_EQ(1U, s.size()); 1762 ASSERT_EQ(1U, s.size());
1667 EXPECT_EQ(kArm64Add, s[0]->arch_opcode()); 1763 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
1668 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode()); 1764 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1669 ASSERT_EQ(3U, s[0]->InputCount()); 1765 ASSERT_EQ(3U, s[0]->InputCount());
1670 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1))); 1766 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1)));
1671 EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2))); 1767 EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2)));
1672 EXPECT_EQ(1U, s[0]->OutputCount()); 1768 EXPECT_EQ(1U, s[0]->OutputCount());
1673 } 1769 }
1770 // x * (2^k + 1) + c -> x + (x << k) + c
1771 TRACED_FORRANGE(int64_t, k, 1, 62) {
1772 StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64);
1773 m.Return(
1774 m.Int64Add(m.Int64Mul(m.Parameter(0), m.Int64Constant((1L << k) + 1)),
1775 m.Parameter(1)));
1776 Stream s = m.Build();
1777 ASSERT_EQ(2U, s.size());
1778 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
1779 EXPECT_EQ(kArm64Add, s[1]->arch_opcode());
1780 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1781 ASSERT_EQ(3U, s[0]->InputCount());
1782 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1)));
1783 EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2)));
1784 EXPECT_EQ(1U, s[0]->OutputCount());
1785 }
1786 // (2^k + 1) * x + c -> x + (x << k) + c
1787 TRACED_FORRANGE(int64_t, k, 1, 62) {
1788 StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64);
1789 m.Return(
1790 m.Int64Add(m.Int64Mul(m.Int64Constant((1L << k) + 1), m.Parameter(0)),
1791 m.Parameter(1)));
1792 Stream s = m.Build();
1793 ASSERT_EQ(2U, s.size());
1794 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
1795 EXPECT_EQ(kArm64Add, s[1]->arch_opcode());
1796 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1797 ASSERT_EQ(3U, s[0]->InputCount());
1798 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1)));
1799 EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2)));
1800 EXPECT_EQ(1U, s[0]->OutputCount());
1801 }
1802 // c + x * (2^k + 1) -> c + x + (x << k)
1803 TRACED_FORRANGE(int64_t, k, 1, 62) {
1804 StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64);
1805 m.Return(
1806 m.Int64Add(m.Parameter(0),
1807 m.Int64Mul(m.Parameter(1), m.Int64Constant((1L << k) + 1))));
1808 Stream s = m.Build();
1809 ASSERT_EQ(2U, s.size());
1810 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
1811 EXPECT_EQ(kArm64Add, s[1]->arch_opcode());
1812 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1813 ASSERT_EQ(3U, s[0]->InputCount());
1814 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1)));
1815 EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2)));
1816 EXPECT_EQ(1U, s[0]->OutputCount());
1817 }
1818 // c + (2^k + 1) * x -> c + x + (x << k)
1819 TRACED_FORRANGE(int64_t, k, 1, 62) {
1820 StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64);
1821 m.Return(
1822 m.Int64Add(m.Parameter(0),
1823 m.Int64Mul(m.Int64Constant((1L << k) + 1), m.Parameter(1))));
1824 Stream s = m.Build();
1825 ASSERT_EQ(2U, s.size());
1826 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
1827 EXPECT_EQ(kArm64Add, s[1]->arch_opcode());
1828 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1829 ASSERT_EQ(3U, s[0]->InputCount());
1830 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1)));
1831 EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2)));
1832 EXPECT_EQ(1U, s[0]->OutputCount());
1833 }
1834 // c - x * (2^k + 1) -> c - x + (x << k)
1835 TRACED_FORRANGE(int64_t, k, 1, 62) {
1836 StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64);
1837 m.Return(
1838 m.Int64Sub(m.Parameter(0),
1839 m.Int64Mul(m.Parameter(1), m.Int64Constant((1L << k) + 1))));
1840 Stream s = m.Build();
1841 ASSERT_EQ(2U, s.size());
1842 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
1843 EXPECT_EQ(kArm64Sub, s[1]->arch_opcode());
1844 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1845 ASSERT_EQ(3U, s[0]->InputCount());
1846 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1)));
1847 EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2)));
1848 EXPECT_EQ(1U, s[0]->OutputCount());
1849 }
1850 // c - (2^k + 1) * x -> c - x + (x << k)
1851 TRACED_FORRANGE(int64_t, k, 1, 62) {
1852 StreamBuilder m(this, kMachInt64, kMachInt64, kMachInt64);
1853 m.Return(
1854 m.Int64Sub(m.Parameter(0),
1855 m.Int64Mul(m.Int64Constant((1L << k) + 1), m.Parameter(1))));
1856 Stream s = m.Build();
1857 ASSERT_EQ(2U, s.size());
1858 EXPECT_EQ(kArm64Add, s[0]->arch_opcode());
1859 EXPECT_EQ(kArm64Sub, s[1]->arch_opcode());
1860 EXPECT_EQ(kMode_Operand2_R_LSL_I, s[0]->addressing_mode());
1861 ASSERT_EQ(3U, s[0]->InputCount());
1862 EXPECT_EQ(s.ToVreg(s[0]->InputAt(0)), s.ToVreg(s[0]->InputAt(1)));
1863 EXPECT_EQ(k, s.ToInt64(s[0]->InputAt(2)));
1864 EXPECT_EQ(1U, s[0]->OutputCount());
1865 }
1674 } 1866 }
1675 1867
1676 1868
1677 // ----------------------------------------------------------------------------- 1869 // -----------------------------------------------------------------------------
1678 // Floating point instructions. 1870 // Floating point instructions.
1679 1871
1680 typedef InstructionSelectorTestWithParam<MachInst2> 1872 typedef InstructionSelectorTestWithParam<MachInst2>
1681 InstructionSelectorFPArithTest; 1873 InstructionSelectorFPArithTest;
1682 1874
1683 1875
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after
2567 EXPECT_EQ(kArm64Float64Neg, s[0]->arch_opcode()); 2759 EXPECT_EQ(kArm64Float64Neg, s[0]->arch_opcode());
2568 ASSERT_EQ(1U, s[0]->InputCount()); 2760 ASSERT_EQ(1U, s[0]->InputCount());
2569 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0))); 2761 EXPECT_EQ(s.ToVreg(p0), s.ToVreg(s[0]->InputAt(0)));
2570 ASSERT_EQ(1U, s[0]->OutputCount()); 2762 ASSERT_EQ(1U, s[0]->OutputCount());
2571 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output())); 2763 EXPECT_EQ(s.ToVreg(n), s.ToVreg(s[0]->Output()));
2572 } 2764 }
2573 2765
2574 } // namespace compiler 2766 } // namespace compiler
2575 } // namespace internal 2767 } // namespace internal
2576 } // namespace v8 2768 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/arm64/instruction-selector-arm64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698