| 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 "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 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 {{&RawMachineAssembler::Float32RoundDown, "Float32RoundDown", | 279 {{&RawMachineAssembler::Float32RoundDown, "Float32RoundDown", |
| 280 kMips64FloorWS, MachineType::Int32()}, | 280 kMips64FloorWS, MachineType::Int32()}, |
| 281 MachineType::Float32()}, | 281 MachineType::Float32()}, |
| 282 {{&RawMachineAssembler::Float32RoundTiesEven, "Float32RoundTiesEven", | 282 {{&RawMachineAssembler::Float32RoundTiesEven, "Float32RoundTiesEven", |
| 283 kMips64RoundWS, MachineType::Int32()}, | 283 kMips64RoundWS, MachineType::Int32()}, |
| 284 MachineType::Float32()}, | 284 MachineType::Float32()}, |
| 285 {{&RawMachineAssembler::Float32RoundTruncate, "Float32RoundTruncate", | 285 {{&RawMachineAssembler::Float32RoundTruncate, "Float32RoundTruncate", |
| 286 kMips64TruncWS, MachineType::Int32()}, | 286 kMips64TruncWS, MachineType::Int32()}, |
| 287 MachineType::Float32()}}; | 287 MachineType::Float32()}}; |
| 288 | 288 |
| 289 // MIPS64 instructions that clear the top 32 bits of the destination. |
| 290 const MachInst2 kCanElideChangeUint32ToUint64[] = { |
| 291 {&RawMachineAssembler::Uint32Div, "Uint32Div", kMips64DivU, |
| 292 MachineType::Uint32()}, |
| 293 {&RawMachineAssembler::Uint32Mod, "Uint32Mod", kMips64ModU, |
| 294 MachineType::Uint32()}, |
| 295 {&RawMachineAssembler::Uint32MulHigh, "Uint32MulHigh", kMips64MulHighU, |
| 296 MachineType::Uint32()}}; |
| 297 |
| 289 } // namespace | 298 } // namespace |
| 290 | 299 |
| 291 | 300 |
| 292 typedef InstructionSelectorTestWithParam<FPCmp> InstructionSelectorFPCmpTest; | 301 typedef InstructionSelectorTestWithParam<FPCmp> InstructionSelectorFPCmpTest; |
| 293 | 302 |
| 294 TEST_P(InstructionSelectorFPCmpTest, Parameter) { | 303 TEST_P(InstructionSelectorFPCmpTest, Parameter) { |
| 295 const FPCmp cmp = GetParam(); | 304 const FPCmp cmp = GetParam(); |
| 296 StreamBuilder m(this, MachineType::Int32(), cmp.mi.machine_type, | 305 StreamBuilder m(this, MachineType::Int32(), cmp.mi.machine_type, |
| 297 cmp.mi.machine_type); | 306 cmp.mi.machine_type); |
| 298 m.Return((m.*cmp.mi.constructor)(m.Parameter(0), m.Parameter(1))); | 307 m.Return((m.*cmp.mi.constructor)(m.Parameter(0), m.Parameter(1))); |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1137 m.Load(MachineType::Int32(), m.Parameter(0), m.Parameter(1)))); | 1146 m.Load(MachineType::Int32(), m.Parameter(0), m.Parameter(1)))); |
| 1138 Stream s = m.Build(); | 1147 Stream s = m.Build(); |
| 1139 ASSERT_EQ(2U, s.size()); | 1148 ASSERT_EQ(2U, s.size()); |
| 1140 EXPECT_EQ(kMips64Lw, s[1]->arch_opcode()); | 1149 EXPECT_EQ(kMips64Lw, s[1]->arch_opcode()); |
| 1141 EXPECT_EQ(kMode_MRI, s[1]->addressing_mode()); | 1150 EXPECT_EQ(kMode_MRI, s[1]->addressing_mode()); |
| 1142 EXPECT_EQ(2U, s[1]->InputCount()); | 1151 EXPECT_EQ(2U, s[1]->InputCount()); |
| 1143 EXPECT_EQ(1U, s[1]->OutputCount()); | 1152 EXPECT_EQ(1U, s[1]->OutputCount()); |
| 1144 } | 1153 } |
| 1145 } | 1154 } |
| 1146 | 1155 |
| 1156 typedef InstructionSelectorTestWithParam<MachInst2> |
| 1157 InstructionSelectorElidedChangeUint32ToUint64Test; |
| 1158 |
| 1159 TEST_P(InstructionSelectorElidedChangeUint32ToUint64Test, Parameter) { |
| 1160 const MachInst2 binop = GetParam(); |
| 1161 StreamBuilder m(this, MachineType::Uint64(), binop.machine_type, |
| 1162 binop.machine_type); |
| 1163 m.Return(m.ChangeUint32ToUint64( |
| 1164 (m.*binop.constructor)(m.Parameter(0), m.Parameter(1)))); |
| 1165 Stream s = m.Build(); |
| 1166 // Make sure the `ChangeUint32ToUint64` node turned into a no-op. |
| 1167 ASSERT_EQ(1U, s.size()); |
| 1168 EXPECT_EQ(binop.arch_opcode, s[0]->arch_opcode()); |
| 1169 EXPECT_EQ(2U, s[0]->InputCount()); |
| 1170 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1171 } |
| 1172 |
| 1173 INSTANTIATE_TEST_CASE_P(InstructionSelectorTest, |
| 1174 InstructionSelectorElidedChangeUint32ToUint64Test, |
| 1175 ::testing::ValuesIn(kCanElideChangeUint32ToUint64)); |
| 1176 |
| 1177 TEST_F(InstructionSelectorTest, ChangeUint32ToUint64AfterLoad) { |
| 1178 // For each case, make sure the `ChangeUint32ToUint64` node turned into a |
| 1179 // no-op. |
| 1180 |
| 1181 // Lbu |
| 1182 { |
| 1183 StreamBuilder m(this, MachineType::Uint64(), MachineType::Pointer(), |
| 1184 MachineType::Int32()); |
| 1185 m.Return(m.ChangeUint32ToUint64( |
| 1186 m.Load(MachineType::Uint8(), m.Parameter(0), m.Parameter(1)))); |
| 1187 Stream s = m.Build(); |
| 1188 ASSERT_EQ(2U, s.size()); |
| 1189 EXPECT_EQ(kMips64Dadd, s[0]->arch_opcode()); |
| 1190 EXPECT_EQ(kMode_None, s[0]->addressing_mode()); |
| 1191 EXPECT_EQ(2U, s[0]->InputCount()); |
| 1192 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1193 EXPECT_EQ(kMips64Lbu, s[1]->arch_opcode()); |
| 1194 EXPECT_EQ(kMode_MRI, s[1]->addressing_mode()); |
| 1195 EXPECT_EQ(2U, s[1]->InputCount()); |
| 1196 EXPECT_EQ(1U, s[1]->OutputCount()); |
| 1197 } |
| 1198 // Lhu |
| 1199 { |
| 1200 StreamBuilder m(this, MachineType::Uint64(), MachineType::Pointer(), |
| 1201 MachineType::Int32()); |
| 1202 m.Return(m.ChangeUint32ToUint64( |
| 1203 m.Load(MachineType::Uint16(), m.Parameter(0), m.Parameter(1)))); |
| 1204 Stream s = m.Build(); |
| 1205 ASSERT_EQ(2U, s.size()); |
| 1206 EXPECT_EQ(kMips64Dadd, s[0]->arch_opcode()); |
| 1207 EXPECT_EQ(kMode_None, s[0]->addressing_mode()); |
| 1208 EXPECT_EQ(2U, s[0]->InputCount()); |
| 1209 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1210 EXPECT_EQ(kMips64Lhu, s[1]->arch_opcode()); |
| 1211 EXPECT_EQ(kMode_MRI, s[1]->addressing_mode()); |
| 1212 EXPECT_EQ(2U, s[1]->InputCount()); |
| 1213 EXPECT_EQ(1U, s[1]->OutputCount()); |
| 1214 } |
| 1215 // Lwu |
| 1216 { |
| 1217 StreamBuilder m(this, MachineType::Uint64(), MachineType::Pointer(), |
| 1218 MachineType::Int32()); |
| 1219 m.Return(m.ChangeUint32ToUint64( |
| 1220 m.Load(MachineType::Uint32(), m.Parameter(0), m.Parameter(1)))); |
| 1221 Stream s = m.Build(); |
| 1222 ASSERT_EQ(2U, s.size()); |
| 1223 EXPECT_EQ(kMips64Dadd, s[0]->arch_opcode()); |
| 1224 EXPECT_EQ(kMode_None, s[0]->addressing_mode()); |
| 1225 EXPECT_EQ(2U, s[0]->InputCount()); |
| 1226 EXPECT_EQ(1U, s[0]->OutputCount()); |
| 1227 EXPECT_EQ(kMips64Lwu, s[1]->arch_opcode()); |
| 1228 EXPECT_EQ(kMode_MRI, s[1]->addressing_mode()); |
| 1229 EXPECT_EQ(2U, s[1]->InputCount()); |
| 1230 EXPECT_EQ(1U, s[1]->OutputCount()); |
| 1231 } |
| 1232 } |
| 1147 | 1233 |
| 1148 // ---------------------------------------------------------------------------- | 1234 // ---------------------------------------------------------------------------- |
| 1149 // Loads and stores. | 1235 // Loads and stores. |
| 1150 // ---------------------------------------------------------------------------- | 1236 // ---------------------------------------------------------------------------- |
| 1151 | 1237 |
| 1152 | 1238 |
| 1153 namespace { | 1239 namespace { |
| 1154 | 1240 |
| 1155 struct MemoryAccess { | 1241 struct MemoryAccess { |
| 1156 MachineType type; | 1242 MachineType type; |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1821 #endif | 1907 #endif |
| 1822 | 1908 |
| 1823 ASSERT_EQ(1U, s[0]->OutputCount()); | 1909 ASSERT_EQ(1U, s[0]->OutputCount()); |
| 1824 } | 1910 } |
| 1825 } | 1911 } |
| 1826 } | 1912 } |
| 1827 | 1913 |
| 1828 } // namespace compiler | 1914 } // namespace compiler |
| 1829 } // namespace internal | 1915 } // namespace internal |
| 1830 } // namespace v8 | 1916 } // namespace v8 |
| OLD | NEW |