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

Side by Side Diff: test/unittests/compiler/machine-operator-reducer-unittest.cc

Issue 2139733003: [turbofan] Strength reduction for Int32MulWithOverflow. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@2101123005
Patch Set: Created 4 years, 5 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/machine-operator-reducer.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | 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 "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 1362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1373 1373
1374 r = Reduce(graph()->NewNode(common()->Projection(0), add, control)); 1374 r = Reduce(graph()->NewNode(common()->Projection(0), add, control));
1375 ASSERT_TRUE(r.Changed()); 1375 ASSERT_TRUE(r.Changed());
1376 EXPECT_THAT(r.replacement(), IsInt32Constant(z)); 1376 EXPECT_THAT(r.replacement(), IsInt32Constant(z));
1377 } 1377 }
1378 } 1378 }
1379 } 1379 }
1380 1380
1381 1381
1382 // ----------------------------------------------------------------------------- 1382 // -----------------------------------------------------------------------------
1383 // Int32MulWithOverflow
1384
1385 TEST_F(MachineOperatorReducerTest, Int32MulWithOverflowWithZero) {
1386 Node* control = graph()->start();
1387 Node* p0 = Parameter(0);
1388 {
1389 Node* mul = graph()->NewNode(machine()->Int32MulWithOverflow(),
1390 Int32Constant(0), p0, control);
1391
1392 Reduction r =
1393 Reduce(graph()->NewNode(common()->Projection(1), mul, control));
1394 ASSERT_TRUE(r.Changed());
1395 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
1396
1397 r = Reduce(graph()->NewNode(common()->Projection(0), mul, control));
1398 ASSERT_TRUE(r.Changed());
1399 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
1400 }
1401 {
1402 Node* mul = graph()->NewNode(machine()->Int32MulWithOverflow(), p0,
1403 Int32Constant(0), control);
1404
1405 Reduction r =
1406 Reduce(graph()->NewNode(common()->Projection(1), mul, control));
1407 ASSERT_TRUE(r.Changed());
1408 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
1409
1410 r = Reduce(graph()->NewNode(common()->Projection(0), mul, control));
1411 ASSERT_TRUE(r.Changed());
1412 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
1413 }
1414 }
1415
1416 TEST_F(MachineOperatorReducerTest, Int32MulWithOverflowWithOne) {
1417 Node* control = graph()->start();
1418 Node* p0 = Parameter(0);
1419 {
1420 Node* mul = graph()->NewNode(machine()->Int32MulWithOverflow(),
1421 Int32Constant(1), p0, control);
1422
1423 Reduction r =
1424 Reduce(graph()->NewNode(common()->Projection(1), mul, control));
1425 ASSERT_TRUE(r.Changed());
1426 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
1427
1428 r = Reduce(graph()->NewNode(common()->Projection(0), mul, control));
1429 ASSERT_TRUE(r.Changed());
1430 EXPECT_EQ(p0, r.replacement());
1431 }
1432 {
1433 Node* mul = graph()->NewNode(machine()->Int32MulWithOverflow(), p0,
1434 Int32Constant(1), control);
1435
1436 Reduction r =
1437 Reduce(graph()->NewNode(common()->Projection(1), mul, control));
1438 ASSERT_TRUE(r.Changed());
1439 EXPECT_THAT(r.replacement(), IsInt32Constant(0));
1440
1441 r = Reduce(graph()->NewNode(common()->Projection(0), mul, control));
1442 ASSERT_TRUE(r.Changed());
1443 EXPECT_EQ(p0, r.replacement());
1444 }
1445 }
1446
1447 TEST_F(MachineOperatorReducerTest, Int32MulWithOverflowWithMinusOne) {
1448 Node* control = graph()->start();
1449 Node* p0 = Parameter(0);
1450
1451 {
1452 Reduction r = Reduce(graph()->NewNode(machine()->Int32MulWithOverflow(),
1453 Int32Constant(-1), p0, control));
1454 ASSERT_TRUE(r.Changed());
1455 EXPECT_THAT(r.replacement(),
1456 IsInt32SubWithOverflow(IsInt32Constant(0), p0));
1457 }
1458
1459 {
1460 Reduction r = Reduce(graph()->NewNode(machine()->Int32MulWithOverflow(), p0,
1461 Int32Constant(-1), control));
1462 ASSERT_TRUE(r.Changed());
1463 EXPECT_THAT(r.replacement(),
1464 IsInt32SubWithOverflow(IsInt32Constant(0), p0));
1465 }
1466 }
1467
1468 TEST_F(MachineOperatorReducerTest, Int32MulWithOverflowWithTwo) {
1469 Node* control = graph()->start();
1470 Node* p0 = Parameter(0);
1471
1472 {
1473 Reduction r = Reduce(graph()->NewNode(machine()->Int32MulWithOverflow(),
1474 Int32Constant(2), p0, control));
1475 ASSERT_TRUE(r.Changed());
1476 EXPECT_THAT(r.replacement(), IsInt32AddWithOverflow(p0, p0));
1477 }
1478
1479 {
1480 Reduction r = Reduce(graph()->NewNode(machine()->Int32MulWithOverflow(), p0,
1481 Int32Constant(2), control));
1482 ASSERT_TRUE(r.Changed());
1483 EXPECT_THAT(r.replacement(), IsInt32AddWithOverflow(p0, p0));
1484 }
1485 }
1486
1487 TEST_F(MachineOperatorReducerTest, Int32MulWithOverflowWithConstant) {
1488 Node* control = graph()->start();
1489 TRACED_FOREACH(int32_t, x, kInt32Values) {
1490 TRACED_FOREACH(int32_t, y, kInt32Values) {
1491 int32_t z;
1492 Node* mul = graph()->NewNode(machine()->Int32MulWithOverflow(),
1493 Int32Constant(x), Int32Constant(y), control);
1494
1495 Reduction r =
1496 Reduce(graph()->NewNode(common()->Projection(1), mul, control));
1497 ASSERT_TRUE(r.Changed());
1498 EXPECT_THAT(r.replacement(),
1499 IsInt32Constant(base::bits::SignedMulOverflow32(x, y, &z)));
1500
1501 r = Reduce(graph()->NewNode(common()->Projection(0), mul, control));
1502 ASSERT_TRUE(r.Changed());
1503 EXPECT_THAT(r.replacement(), IsInt32Constant(z));
1504 }
1505 }
1506 }
1507
1508 // -----------------------------------------------------------------------------
1383 // Uint32LessThan 1509 // Uint32LessThan
1384 1510
1385
1386 TEST_F(MachineOperatorReducerTest, Uint32LessThanWithWord32Sar) { 1511 TEST_F(MachineOperatorReducerTest, Uint32LessThanWithWord32Sar) {
1387 Node* const p0 = Parameter(0); 1512 Node* const p0 = Parameter(0);
1388 TRACED_FORRANGE(uint32_t, shift, 1, 3) { 1513 TRACED_FORRANGE(uint32_t, shift, 1, 3) {
1389 const uint32_t limit = (kMaxInt >> shift) - 1; 1514 const uint32_t limit = (kMaxInt >> shift) - 1;
1390 Node* const node = graph()->NewNode( 1515 Node* const node = graph()->NewNode(
1391 machine()->Uint32LessThan(), 1516 machine()->Uint32LessThan(),
1392 graph()->NewNode(machine()->Word32Sar(), p0, Uint32Constant(shift)), 1517 graph()->NewNode(machine()->Word32Sar(), p0, Uint32Constant(shift)),
1393 Uint32Constant(limit)); 1518 Uint32Constant(limit));
1394 1519
1395 Reduction r = Reduce(node); 1520 Reduction r = Reduce(node);
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after
1905 Reduction r = Reduce(node); 2030 Reduction r = Reduce(node);
1906 ASSERT_TRUE(r.Changed()); 2031 ASSERT_TRUE(r.Changed());
1907 EXPECT_THAT(r.replacement(), 2032 EXPECT_THAT(r.replacement(),
1908 IsStore(rep, base, index, value, effect, control)); 2033 IsStore(rep, base, index, value, effect, control));
1909 } 2034 }
1910 } 2035 }
1911 2036
1912 } // namespace compiler 2037 } // namespace compiler
1913 } // namespace internal 2038 } // namespace internal
1914 } // namespace v8 2039 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/machine-operator-reducer.cc ('k') | test/unittests/compiler/node-test-utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698