| 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/machine-operator-reducer.h" | 5 #include "src/compiler/machine-operator-reducer.h" |
| 6 #include "src/base/bits.h" | 6 #include "src/base/bits.h" |
| 7 #include "src/base/division-by-constant.h" | 7 #include "src/base/division-by-constant.h" |
| 8 #include "src/base/ieee754.h" | 8 #include "src/base/ieee754.h" |
| 9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
| 10 #include "src/compiler/typer.h" | 10 #include "src/compiler/typer.h" |
| (...skipping 1266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1277 ASSERT_TRUE(r2.Changed()); | 1277 ASSERT_TRUE(r2.Changed()); |
| 1278 EXPECT_THAT(r2.replacement(), IsInt32Sub(p0, p1)); | 1278 EXPECT_THAT(r2.replacement(), IsInt32Sub(p0, p1)); |
| 1279 } | 1279 } |
| 1280 | 1280 |
| 1281 | 1281 |
| 1282 // ----------------------------------------------------------------------------- | 1282 // ----------------------------------------------------------------------------- |
| 1283 // Int32AddWithOverflow | 1283 // Int32AddWithOverflow |
| 1284 | 1284 |
| 1285 | 1285 |
| 1286 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) { | 1286 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) { |
| 1287 Node* control = graph()->start(); |
| 1287 Node* p0 = Parameter(0); | 1288 Node* p0 = Parameter(0); |
| 1288 { | 1289 { |
| 1289 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), | 1290 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), |
| 1290 Int32Constant(0), p0); | 1291 Int32Constant(0), p0, control); |
| 1291 | 1292 |
| 1292 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add)); | 1293 Reduction r = |
| 1294 Reduce(graph()->NewNode(common()->Projection(1), add, control)); |
| 1293 ASSERT_TRUE(r.Changed()); | 1295 ASSERT_TRUE(r.Changed()); |
| 1294 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); | 1296 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); |
| 1295 | 1297 |
| 1296 r = Reduce(graph()->NewNode(common()->Projection(0), add)); | 1298 r = Reduce(graph()->NewNode(common()->Projection(0), add, control)); |
| 1297 ASSERT_TRUE(r.Changed()); | 1299 ASSERT_TRUE(r.Changed()); |
| 1298 EXPECT_EQ(p0, r.replacement()); | 1300 EXPECT_EQ(p0, r.replacement()); |
| 1299 } | 1301 } |
| 1300 { | 1302 { |
| 1301 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), p0, | 1303 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), p0, |
| 1302 Int32Constant(0)); | 1304 Int32Constant(0), control); |
| 1303 | 1305 |
| 1304 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add)); | 1306 Reduction r = |
| 1307 Reduce(graph()->NewNode(common()->Projection(1), add, control)); |
| 1305 ASSERT_TRUE(r.Changed()); | 1308 ASSERT_TRUE(r.Changed()); |
| 1306 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); | 1309 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); |
| 1307 | 1310 |
| 1308 r = Reduce(graph()->NewNode(common()->Projection(0), add)); | 1311 r = Reduce(graph()->NewNode(common()->Projection(0), add, control)); |
| 1309 ASSERT_TRUE(r.Changed()); | 1312 ASSERT_TRUE(r.Changed()); |
| 1310 EXPECT_EQ(p0, r.replacement()); | 1313 EXPECT_EQ(p0, r.replacement()); |
| 1311 } | 1314 } |
| 1312 } | 1315 } |
| 1313 | 1316 |
| 1314 | 1317 |
| 1315 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithConstant) { | 1318 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithConstant) { |
| 1319 Node* control = graph()->start(); |
| 1316 TRACED_FOREACH(int32_t, x, kInt32Values) { | 1320 TRACED_FOREACH(int32_t, x, kInt32Values) { |
| 1317 TRACED_FOREACH(int32_t, y, kInt32Values) { | 1321 TRACED_FOREACH(int32_t, y, kInt32Values) { |
| 1318 int32_t z; | 1322 int32_t z; |
| 1319 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), | 1323 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), |
| 1320 Int32Constant(x), Int32Constant(y)); | 1324 Int32Constant(x), Int32Constant(y), control); |
| 1321 | 1325 |
| 1322 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add)); | 1326 Reduction r = |
| 1327 Reduce(graph()->NewNode(common()->Projection(1), add, control)); |
| 1323 ASSERT_TRUE(r.Changed()); | 1328 ASSERT_TRUE(r.Changed()); |
| 1324 EXPECT_THAT(r.replacement(), | 1329 EXPECT_THAT(r.replacement(), |
| 1325 IsInt32Constant(base::bits::SignedAddOverflow32(x, y, &z))); | 1330 IsInt32Constant(base::bits::SignedAddOverflow32(x, y, &z))); |
| 1326 | 1331 |
| 1327 r = Reduce(graph()->NewNode(common()->Projection(0), add)); | 1332 r = Reduce(graph()->NewNode(common()->Projection(0), add, control)); |
| 1328 ASSERT_TRUE(r.Changed()); | 1333 ASSERT_TRUE(r.Changed()); |
| 1329 EXPECT_THAT(r.replacement(), IsInt32Constant(z)); | 1334 EXPECT_THAT(r.replacement(), IsInt32Constant(z)); |
| 1330 } | 1335 } |
| 1331 } | 1336 } |
| 1332 } | 1337 } |
| 1333 | 1338 |
| 1334 | 1339 |
| 1335 // ----------------------------------------------------------------------------- | 1340 // ----------------------------------------------------------------------------- |
| 1336 // Int32SubWithOverflow | 1341 // Int32SubWithOverflow |
| 1337 | 1342 |
| 1338 | 1343 |
| 1339 TEST_F(MachineOperatorReducerTest, Int32SubWithOverflowWithZero) { | 1344 TEST_F(MachineOperatorReducerTest, Int32SubWithOverflowWithZero) { |
| 1345 Node* control = graph()->start(); |
| 1340 Node* p0 = Parameter(0); | 1346 Node* p0 = Parameter(0); |
| 1341 Node* add = | 1347 Node* add = graph()->NewNode(machine()->Int32SubWithOverflow(), p0, |
| 1342 graph()->NewNode(machine()->Int32SubWithOverflow(), p0, Int32Constant(0)); | 1348 Int32Constant(0), control); |
| 1343 | 1349 |
| 1344 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add)); | 1350 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add, control)); |
| 1345 ASSERT_TRUE(r.Changed()); | 1351 ASSERT_TRUE(r.Changed()); |
| 1346 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); | 1352 EXPECT_THAT(r.replacement(), IsInt32Constant(0)); |
| 1347 | 1353 |
| 1348 r = Reduce(graph()->NewNode(common()->Projection(0), add)); | 1354 r = Reduce(graph()->NewNode(common()->Projection(0), add, control)); |
| 1349 ASSERT_TRUE(r.Changed()); | 1355 ASSERT_TRUE(r.Changed()); |
| 1350 EXPECT_EQ(p0, r.replacement()); | 1356 EXPECT_EQ(p0, r.replacement()); |
| 1351 } | 1357 } |
| 1352 | 1358 |
| 1353 | 1359 |
| 1354 TEST_F(MachineOperatorReducerTest, Int32SubWithOverflowWithConstant) { | 1360 TEST_F(MachineOperatorReducerTest, Int32SubWithOverflowWithConstant) { |
| 1361 Node* control = graph()->start(); |
| 1355 TRACED_FOREACH(int32_t, x, kInt32Values) { | 1362 TRACED_FOREACH(int32_t, x, kInt32Values) { |
| 1356 TRACED_FOREACH(int32_t, y, kInt32Values) { | 1363 TRACED_FOREACH(int32_t, y, kInt32Values) { |
| 1357 int32_t z; | 1364 int32_t z; |
| 1358 Node* add = graph()->NewNode(machine()->Int32SubWithOverflow(), | 1365 Node* add = graph()->NewNode(machine()->Int32SubWithOverflow(), |
| 1359 Int32Constant(x), Int32Constant(y)); | 1366 Int32Constant(x), Int32Constant(y), control); |
| 1360 | 1367 |
| 1361 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add)); | 1368 Reduction r = |
| 1369 Reduce(graph()->NewNode(common()->Projection(1), add, control)); |
| 1362 ASSERT_TRUE(r.Changed()); | 1370 ASSERT_TRUE(r.Changed()); |
| 1363 EXPECT_THAT(r.replacement(), | 1371 EXPECT_THAT(r.replacement(), |
| 1364 IsInt32Constant(base::bits::SignedSubOverflow32(x, y, &z))); | 1372 IsInt32Constant(base::bits::SignedSubOverflow32(x, y, &z))); |
| 1365 | 1373 |
| 1366 r = Reduce(graph()->NewNode(common()->Projection(0), add)); | 1374 r = Reduce(graph()->NewNode(common()->Projection(0), add, control)); |
| 1367 ASSERT_TRUE(r.Changed()); | 1375 ASSERT_TRUE(r.Changed()); |
| 1368 EXPECT_THAT(r.replacement(), IsInt32Constant(z)); | 1376 EXPECT_THAT(r.replacement(), IsInt32Constant(z)); |
| 1369 } | 1377 } |
| 1370 } | 1378 } |
| 1371 } | 1379 } |
| 1372 | 1380 |
| 1373 | 1381 |
| 1374 // ----------------------------------------------------------------------------- | 1382 // ----------------------------------------------------------------------------- |
| 1375 // Uint32LessThan | 1383 // Uint32LessThan |
| 1376 | 1384 |
| (...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1786 Reduction r = Reduce(node); | 1794 Reduction r = Reduce(node); |
| 1787 ASSERT_TRUE(r.Changed()); | 1795 ASSERT_TRUE(r.Changed()); |
| 1788 EXPECT_THAT(r.replacement(), | 1796 EXPECT_THAT(r.replacement(), |
| 1789 IsStore(rep, base, index, value, effect, control)); | 1797 IsStore(rep, base, index, value, effect, control)); |
| 1790 } | 1798 } |
| 1791 } | 1799 } |
| 1792 | 1800 |
| 1793 } // namespace compiler | 1801 } // namespace compiler |
| 1794 } // namespace internal | 1802 } // namespace internal |
| 1795 } // namespace v8 | 1803 } // namespace v8 |
| OLD | NEW |