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

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

Issue 1513543003: [turbofan] Make MachineType a pair of enums. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Moar rebase Created 5 years 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
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/base/bits.h" 5 #include "src/base/bits.h"
6 #include "src/base/division-by-constant.h" 6 #include "src/base/division-by-constant.h"
7 #include "src/compiler/js-graph.h" 7 #include "src/compiler/js-graph.h"
8 #include "src/compiler/machine-operator-reducer.h" 8 #include "src/compiler/machine-operator-reducer.h"
9 #include "src/compiler/typer.h" 9 #include "src/compiler/typer.h"
10 #include "src/conversions-inl.h" 10 #include "src/conversions-inl.h"
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 } 440 }
441 441
442 442
443 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithPhi) { 443 TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithPhi) {
444 Node* const p0 = Parameter(0); 444 Node* const p0 = Parameter(0);
445 Node* const p1 = Parameter(1); 445 Node* const p1 = Parameter(1);
446 Node* const merge = graph()->start(); 446 Node* const merge = graph()->start();
447 TRACED_FOREACH(TruncationMode, mode, kTruncationModes) { 447 TRACED_FOREACH(TruncationMode, mode, kTruncationModes) {
448 Reduction reduction = Reduce(graph()->NewNode( 448 Reduction reduction = Reduce(graph()->NewNode(
449 machine()->TruncateFloat64ToInt32(mode), 449 machine()->TruncateFloat64ToInt32(mode),
450 graph()->NewNode(common()->Phi(kMachFloat64, 2), p0, p1, merge))); 450 graph()->NewNode(common()->Phi(MachineRepresentation::kFloat64, 2), p0,
451 p1, merge)));
451 ASSERT_TRUE(reduction.Changed()); 452 ASSERT_TRUE(reduction.Changed());
452 EXPECT_THAT(reduction.replacement(), 453 EXPECT_THAT(
453 IsPhi(kMachInt32, IsTruncateFloat64ToInt32(p0), 454 reduction.replacement(),
454 IsTruncateFloat64ToInt32(p1), merge)); 455 IsPhi(MachineRepresentation::kWord32, IsTruncateFloat64ToInt32(p0),
456 IsTruncateFloat64ToInt32(p1), merge));
455 } 457 }
456 } 458 }
457 459
458 460
459 // ----------------------------------------------------------------------------- 461 // -----------------------------------------------------------------------------
460 // TruncateInt64ToInt32 462 // TruncateInt64ToInt32
461 463
462 464
463 TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithChangeInt32ToInt64) { 465 TEST_F(MachineOperatorReducerTest, TruncateInt64ToInt32WithChangeInt32ToInt64) {
464 Node* value = Parameter(0); 466 Node* value = Parameter(0);
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
821 ASSERT_TRUE(r.Changed()); 823 ASSERT_TRUE(r.Changed());
822 EXPECT_THAT(r.replacement(), IsInt32Sub(IsInt32Constant(0), cmp)); 824 EXPECT_THAT(r.replacement(), IsInt32Sub(IsInt32Constant(0), cmp));
823 } 825 }
824 } 826 }
825 827
826 828
827 TEST_F(MachineOperatorReducerTest, Word32SarWithWord32ShlAndLoad) { 829 TEST_F(MachineOperatorReducerTest, Word32SarWithWord32ShlAndLoad) {
828 Node* const p0 = Parameter(0); 830 Node* const p0 = Parameter(0);
829 Node* const p1 = Parameter(1); 831 Node* const p1 = Parameter(1);
830 { 832 {
831 Node* const l = graph()->NewNode(machine()->Load(kMachInt8), p0, p1, 833 Node* const l = graph()->NewNode(machine()->Load(MachineType::Int8()), p0,
832 graph()->start(), graph()->start()); 834 p1, graph()->start(), graph()->start());
833 Reduction const r = Reduce(graph()->NewNode( 835 Reduction const r = Reduce(graph()->NewNode(
834 machine()->Word32Sar(), 836 machine()->Word32Sar(),
835 graph()->NewNode(machine()->Word32Shl(), l, Int32Constant(24)), 837 graph()->NewNode(machine()->Word32Shl(), l, Int32Constant(24)),
836 Int32Constant(24))); 838 Int32Constant(24)));
837 ASSERT_TRUE(r.Changed()); 839 ASSERT_TRUE(r.Changed());
838 EXPECT_EQ(l, r.replacement()); 840 EXPECT_EQ(l, r.replacement());
839 } 841 }
840 { 842 {
841 Node* const l = graph()->NewNode(machine()->Load(kMachInt16), p0, p1, 843 Node* const l = graph()->NewNode(machine()->Load(MachineType::Int16()), p0,
842 graph()->start(), graph()->start()); 844 p1, graph()->start(), graph()->start());
843 Reduction const r = Reduce(graph()->NewNode( 845 Reduction const r = Reduce(graph()->NewNode(
844 machine()->Word32Sar(), 846 machine()->Word32Sar(),
845 graph()->NewNode(machine()->Word32Shl(), l, Int32Constant(16)), 847 graph()->NewNode(machine()->Word32Shl(), l, Int32Constant(16)),
846 Int32Constant(16))); 848 Int32Constant(16)));
847 ASSERT_TRUE(r.Changed()); 849 ASSERT_TRUE(r.Changed());
848 EXPECT_EQ(l, r.replacement()); 850 EXPECT_EQ(l, r.replacement());
849 } 851 }
850 } 852 }
851 853
852 854
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
1135 } 1137 }
1136 } 1138 }
1137 TRACED_FORRANGE(int32_t, shift, 1, 30) { 1139 TRACED_FORRANGE(int32_t, shift, 1, 30) {
1138 Reduction const r = 1140 Reduction const r =
1139 Reduce(graph()->NewNode(machine()->Int32Mod(), p0, 1141 Reduce(graph()->NewNode(machine()->Int32Mod(), p0,
1140 Int32Constant(1 << shift), graph()->start())); 1142 Int32Constant(1 << shift), graph()->start()));
1141 int32_t const mask = (1 << shift) - 1; 1143 int32_t const mask = (1 << shift) - 1;
1142 ASSERT_TRUE(r.Changed()); 1144 ASSERT_TRUE(r.Changed());
1143 EXPECT_THAT( 1145 EXPECT_THAT(
1144 r.replacement(), 1146 r.replacement(),
1145 IsSelect(kMachInt32, IsInt32LessThan(p0, IsInt32Constant(0)), 1147 IsSelect(MachineRepresentation::kWord32,
1148 IsInt32LessThan(p0, IsInt32Constant(0)),
1146 IsInt32Sub(IsInt32Constant(0), 1149 IsInt32Sub(IsInt32Constant(0),
1147 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), 1150 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0),
1148 IsInt32Constant(mask))), 1151 IsInt32Constant(mask))),
1149 IsWord32And(p0, IsInt32Constant(mask)))); 1152 IsWord32And(p0, IsInt32Constant(mask))));
1150 } 1153 }
1151 TRACED_FORRANGE(int32_t, shift, 1, 31) { 1154 TRACED_FORRANGE(int32_t, shift, 1, 31) {
1152 Reduction const r = Reduce(graph()->NewNode( 1155 Reduction const r = Reduce(graph()->NewNode(
1153 machine()->Int32Mod(), p0, 1156 machine()->Int32Mod(), p0,
1154 Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift), 1157 Uint32Constant(bit_cast<uint32_t, int32_t>(-1) << shift),
1155 graph()->start())); 1158 graph()->start()));
1156 int32_t const mask = bit_cast<int32_t, uint32_t>((1U << shift) - 1); 1159 int32_t const mask = bit_cast<int32_t, uint32_t>((1U << shift) - 1);
1157 ASSERT_TRUE(r.Changed()); 1160 ASSERT_TRUE(r.Changed());
1158 EXPECT_THAT( 1161 EXPECT_THAT(
1159 r.replacement(), 1162 r.replacement(),
1160 IsSelect(kMachInt32, IsInt32LessThan(p0, IsInt32Constant(0)), 1163 IsSelect(MachineRepresentation::kWord32,
1164 IsInt32LessThan(p0, IsInt32Constant(0)),
1161 IsInt32Sub(IsInt32Constant(0), 1165 IsInt32Sub(IsInt32Constant(0),
1162 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), 1166 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0),
1163 IsInt32Constant(mask))), 1167 IsInt32Constant(mask))),
1164 IsWord32And(p0, IsInt32Constant(mask)))); 1168 IsWord32And(p0, IsInt32Constant(mask))));
1165 } 1169 }
1166 TRACED_FOREACH(int32_t, divisor, kInt32Values) { 1170 TRACED_FOREACH(int32_t, divisor, kInt32Values) {
1167 if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue; 1171 if (divisor == 0 || base::bits::IsPowerOfTwo32(Abs(divisor))) continue;
1168 Reduction const r = Reduce(graph()->NewNode( 1172 Reduction const r = Reduce(graph()->NewNode(
1169 machine()->Int32Mod(), p0, Int32Constant(divisor), graph()->start())); 1173 machine()->Int32Mod(), p0, Int32Constant(divisor), graph()->start()));
1170 ASSERT_TRUE(r.Changed()); 1174 ASSERT_TRUE(r.Changed());
(...skipping 378 matching lines...) Expand 10 before | Expand all | Expand 10 after
1549 } 1553 }
1550 } 1554 }
1551 } 1555 }
1552 1556
1553 1557
1554 // ----------------------------------------------------------------------------- 1558 // -----------------------------------------------------------------------------
1555 // Store 1559 // Store
1556 1560
1557 1561
1558 TEST_F(MachineOperatorReducerTest, StoreRepWord8WithWord32And) { 1562 TEST_F(MachineOperatorReducerTest, StoreRepWord8WithWord32And) {
1559 const StoreRepresentation rep(kMachUint8, kNoWriteBarrier); 1563 const StoreRepresentation rep(MachineType::Uint8(), kNoWriteBarrier);
1560 Node* const base = Parameter(0); 1564 Node* const base = Parameter(0);
1561 Node* const index = Parameter(1); 1565 Node* const index = Parameter(1);
1562 Node* const value = Parameter(2); 1566 Node* const value = Parameter(2);
1563 Node* const effect = graph()->start(); 1567 Node* const effect = graph()->start();
1564 Node* const control = graph()->start(); 1568 Node* const control = graph()->start();
1565 TRACED_FOREACH(uint32_t, x, kUint32Values) { 1569 TRACED_FOREACH(uint32_t, x, kUint32Values) {
1566 Node* const node = 1570 Node* const node =
1567 graph()->NewNode(machine()->Store(rep), base, index, 1571 graph()->NewNode(machine()->Store(rep), base, index,
1568 graph()->NewNode(machine()->Word32And(), value, 1572 graph()->NewNode(machine()->Word32And(), value,
1569 Uint32Constant(x | 0xffu)), 1573 Uint32Constant(x | 0xffu)),
1570 effect, control); 1574 effect, control);
1571 1575
1572 Reduction r = Reduce(node); 1576 Reduction r = Reduce(node);
1573 ASSERT_TRUE(r.Changed()); 1577 ASSERT_TRUE(r.Changed());
1574 EXPECT_THAT(r.replacement(), 1578 EXPECT_THAT(r.replacement(),
1575 IsStore(rep, base, index, value, effect, control)); 1579 IsStore(rep, base, index, value, effect, control));
1576 } 1580 }
1577 } 1581 }
1578 1582
1579 1583
1580 TEST_F(MachineOperatorReducerTest, StoreRepWord8WithWord32SarAndWord32Shl) { 1584 TEST_F(MachineOperatorReducerTest, StoreRepWord8WithWord32SarAndWord32Shl) {
1581 const StoreRepresentation rep(kMachUint8, kNoWriteBarrier); 1585 const StoreRepresentation rep(MachineType::Uint8(), kNoWriteBarrier);
1582 Node* const base = Parameter(0); 1586 Node* const base = Parameter(0);
1583 Node* const index = Parameter(1); 1587 Node* const index = Parameter(1);
1584 Node* const value = Parameter(2); 1588 Node* const value = Parameter(2);
1585 Node* const effect = graph()->start(); 1589 Node* const effect = graph()->start();
1586 Node* const control = graph()->start(); 1590 Node* const control = graph()->start();
1587 TRACED_FORRANGE(int32_t, x, 1, 24) { 1591 TRACED_FORRANGE(int32_t, x, 1, 24) {
1588 Node* const node = graph()->NewNode( 1592 Node* const node = graph()->NewNode(
1589 machine()->Store(rep), base, index, 1593 machine()->Store(rep), base, index,
1590 graph()->NewNode( 1594 graph()->NewNode(
1591 machine()->Word32Sar(), 1595 machine()->Word32Sar(),
1592 graph()->NewNode(machine()->Word32Shl(), value, Int32Constant(x)), 1596 graph()->NewNode(machine()->Word32Shl(), value, Int32Constant(x)),
1593 Int32Constant(x)), 1597 Int32Constant(x)),
1594 effect, control); 1598 effect, control);
1595 1599
1596 Reduction r = Reduce(node); 1600 Reduction r = Reduce(node);
1597 ASSERT_TRUE(r.Changed()); 1601 ASSERT_TRUE(r.Changed());
1598 EXPECT_THAT(r.replacement(), 1602 EXPECT_THAT(r.replacement(),
1599 IsStore(rep, base, index, value, effect, control)); 1603 IsStore(rep, base, index, value, effect, control));
1600 } 1604 }
1601 } 1605 }
1602 1606
1603 1607
1604 TEST_F(MachineOperatorReducerTest, StoreRepWord16WithWord32And) { 1608 TEST_F(MachineOperatorReducerTest, StoreRepWord16WithWord32And) {
1605 const StoreRepresentation rep(kMachUint16, kNoWriteBarrier); 1609 const StoreRepresentation rep(MachineType::Uint16(), kNoWriteBarrier);
1606 Node* const base = Parameter(0); 1610 Node* const base = Parameter(0);
1607 Node* const index = Parameter(1); 1611 Node* const index = Parameter(1);
1608 Node* const value = Parameter(2); 1612 Node* const value = Parameter(2);
1609 Node* const effect = graph()->start(); 1613 Node* const effect = graph()->start();
1610 Node* const control = graph()->start(); 1614 Node* const control = graph()->start();
1611 TRACED_FOREACH(uint32_t, x, kUint32Values) { 1615 TRACED_FOREACH(uint32_t, x, kUint32Values) {
1612 Node* const node = 1616 Node* const node =
1613 graph()->NewNode(machine()->Store(rep), base, index, 1617 graph()->NewNode(machine()->Store(rep), base, index,
1614 graph()->NewNode(machine()->Word32And(), value, 1618 graph()->NewNode(machine()->Word32And(), value,
1615 Uint32Constant(x | 0xffffu)), 1619 Uint32Constant(x | 0xffffu)),
1616 effect, control); 1620 effect, control);
1617 1621
1618 Reduction r = Reduce(node); 1622 Reduction r = Reduce(node);
1619 ASSERT_TRUE(r.Changed()); 1623 ASSERT_TRUE(r.Changed());
1620 EXPECT_THAT(r.replacement(), 1624 EXPECT_THAT(r.replacement(),
1621 IsStore(rep, base, index, value, effect, control)); 1625 IsStore(rep, base, index, value, effect, control));
1622 } 1626 }
1623 } 1627 }
1624 1628
1625 1629
1626 TEST_F(MachineOperatorReducerTest, StoreRepWord16WithWord32SarAndWord32Shl) { 1630 TEST_F(MachineOperatorReducerTest, StoreRepWord16WithWord32SarAndWord32Shl) {
1627 const StoreRepresentation rep(kMachUint16, kNoWriteBarrier); 1631 const StoreRepresentation rep(MachineType::Uint16(), kNoWriteBarrier);
1628 Node* const base = Parameter(0); 1632 Node* const base = Parameter(0);
1629 Node* const index = Parameter(1); 1633 Node* const index = Parameter(1);
1630 Node* const value = Parameter(2); 1634 Node* const value = Parameter(2);
1631 Node* const effect = graph()->start(); 1635 Node* const effect = graph()->start();
1632 Node* const control = graph()->start(); 1636 Node* const control = graph()->start();
1633 TRACED_FORRANGE(int32_t, x, 1, 16) { 1637 TRACED_FORRANGE(int32_t, x, 1, 16) {
1634 Node* const node = graph()->NewNode( 1638 Node* const node = graph()->NewNode(
1635 machine()->Store(rep), base, index, 1639 machine()->Store(rep), base, index,
1636 graph()->NewNode( 1640 graph()->NewNode(
1637 machine()->Word32Sar(), 1641 machine()->Word32Sar(),
1638 graph()->NewNode(machine()->Word32Shl(), value, Int32Constant(x)), 1642 graph()->NewNode(machine()->Word32Shl(), value, Int32Constant(x)),
1639 Int32Constant(x)), 1643 Int32Constant(x)),
1640 effect, control); 1644 effect, control);
1641 1645
1642 Reduction r = Reduce(node); 1646 Reduction r = Reduce(node);
1643 ASSERT_TRUE(r.Changed()); 1647 ASSERT_TRUE(r.Changed());
1644 EXPECT_THAT(r.replacement(), 1648 EXPECT_THAT(r.replacement(),
1645 IsStore(rep, base, index, value, effect, control)); 1649 IsStore(rep, base, index, value, effect, control));
1646 } 1650 }
1647 } 1651 }
1648 1652
1649 } // namespace compiler 1653 } // namespace compiler
1650 } // namespace internal 1654 } // namespace internal
1651 } // namespace v8 1655 } // namespace v8
OLDNEW
« no previous file with comments | « test/unittests/compiler/loop-peeling-unittest.cc ('k') | test/unittests/compiler/machine-operator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698