| 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 "src/compiler/instruction-selector-unittest.h" | 5 #include "src/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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 Stream s = m.Build(); | 68 Stream s = m.Build(); |
| 69 ASSERT_EQ(1U, s.size()); | 69 ASSERT_EQ(1U, s.size()); |
| 70 EXPECT_EQ(kIA32Sub, s[0]->arch_opcode()); | 70 EXPECT_EQ(kIA32Sub, s[0]->arch_opcode()); |
| 71 ASSERT_EQ(2U, s[0]->InputCount()); | 71 ASSERT_EQ(2U, s[0]->InputCount()); |
| 72 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); | 72 EXPECT_EQ(imm, s.ToInt32(s[0]->InputAt(1))); |
| 73 } | 73 } |
| 74 } | 74 } |
| 75 | 75 |
| 76 | 76 |
| 77 // ----------------------------------------------------------------------------- | 77 // ----------------------------------------------------------------------------- |
| 78 // Better left operand for commutative binops |
| 79 |
| 80 TEST_F(InstructionSelectorTest, BetterLeftOperandTestAddBinop) { |
| 81 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 82 Node* param1 = m.Parameter(0); |
| 83 Node* param2 = m.Parameter(1); |
| 84 Node* add = m.Int32Add(param1, param2); |
| 85 m.Return(m.Int32Add(add, param1)); |
| 86 Stream s = m.Build(); |
| 87 ASSERT_EQ(2U, s.size()); |
| 88 EXPECT_EQ(kIA32Add, s[0]->arch_opcode()); |
| 89 ASSERT_EQ(2U, s[0]->InputCount()); |
| 90 ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated()); |
| 91 EXPECT_EQ(param2->id(), s.ToVreg(s[0]->InputAt(0))); |
| 92 } |
| 93 |
| 94 |
| 95 TEST_F(InstructionSelectorTest, BetterLeftOperandTestMulBinop) { |
| 96 StreamBuilder m(this, kMachInt32, kMachInt32, kMachInt32); |
| 97 Node* param1 = m.Parameter(0); |
| 98 Node* param2 = m.Parameter(1); |
| 99 Node* mul = m.Int32Mul(param1, param2); |
| 100 m.Return(m.Int32Mul(mul, param1)); |
| 101 Stream s = m.Build(); |
| 102 ASSERT_EQ(2U, s.size()); |
| 103 EXPECT_EQ(kIA32Imul, s[0]->arch_opcode()); |
| 104 ASSERT_EQ(2U, s[0]->InputCount()); |
| 105 ASSERT_TRUE(s[0]->InputAt(0)->IsUnallocated()); |
| 106 EXPECT_EQ(param2->id(), s.ToVreg(s[0]->InputAt(0))); |
| 107 } |
| 108 |
| 109 |
| 110 // ----------------------------------------------------------------------------- |
| 78 // Loads and stores | 111 // Loads and stores |
| 79 | 112 |
| 80 namespace { | 113 namespace { |
| 81 | 114 |
| 82 struct MemoryAccess { | 115 struct MemoryAccess { |
| 83 MachineType type; | 116 MachineType type; |
| 84 ArchOpcode load_opcode; | 117 ArchOpcode load_opcode; |
| 85 ArchOpcode store_opcode; | 118 ArchOpcode store_opcode; |
| 86 }; | 119 }; |
| 87 | 120 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 } | 235 } |
| 203 | 236 |
| 204 | 237 |
| 205 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, | 238 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
| 206 InstructionSelectorMemoryAccessTest, | 239 InstructionSelectorMemoryAccessTest, |
| 207 ::testing::ValuesIn(kMemoryAccesses)); | 240 ::testing::ValuesIn(kMemoryAccesses)); |
| 208 | 241 |
| 209 } // namespace compiler | 242 } // namespace compiler |
| 210 } // namespace internal | 243 } // namespace internal |
| 211 } // namespace v8 | 244 } // namespace v8 |
| OLD | NEW |