| Index: test/unittests/compiler/machine-operator-reducer-unittest.cc
|
| diff --git a/test/unittests/compiler/machine-operator-reducer-unittest.cc b/test/unittests/compiler/machine-operator-reducer-unittest.cc
|
| index fff6f96709d072ecf055c927800d2532a73280c3..33c5489a6f5f9a62bfe32981b9100f0ff4aa71c2 100644
|
| --- a/test/unittests/compiler/machine-operator-reducer-unittest.cc
|
| +++ b/test/unittests/compiler/machine-operator-reducer-unittest.cc
|
| @@ -232,6 +232,12 @@ const uint32_t kUint32Values[] = {
|
| 0x000fffff, 0x0007ffff, 0x0003ffff, 0x0001ffff, 0x0000ffff, 0x00007fff,
|
| 0x00003fff, 0x00001fff, 0x00000fff, 0x000007ff, 0x000003ff, 0x000001ff};
|
|
|
| +
|
| +int32_t RandomInt32(base::RandomNumberGenerator* rng) {
|
| + int index = rng->NextInt(static_cast<int>(arraysize(kInt32Values)));
|
| + return kInt32Values[index];
|
| +}
|
| +
|
| } // namespace
|
|
|
|
|
| @@ -1144,6 +1150,43 @@ TEST_F(MachineOperatorReducerTest, StoreRepWord16WithWord32And) {
|
| }
|
| }
|
|
|
| +
|
| +TEST_F(MachineOperatorReducerTest, ConstantFoldCompare32) {
|
| + base::RandomNumberGenerator rng;
|
| + TRACED_FOREACH(int32_t, c_0, kInt32Values) {
|
| + const int32_t c_1 = RandomInt32(&rng);
|
| + const int32_t c_2 = RandomInt32(&rng);
|
| + {
|
| + Node* const k_0 = Int32Constant(c_0);
|
| + Node* const k_1 = Int32Constant(c_1);
|
| + Node* const k_2 = Int32Constant(c_2);
|
| + Node* const p0 = Parameter(0);
|
| + Node* const add_0 = graph()->NewNode(machine()->Int32Add(), p0, k_0);
|
| + Node* const add_1 = graph()->NewNode(machine()->Int32Add(), add_0, k_1);
|
| + Node* const node =
|
| + graph()->NewNode(machine()->Int32LessThan(), add_1, k_2);
|
| + Reduction r = Reduce(node);
|
| + ASSERT_TRUE(r.Changed());
|
| + EXPECT_THAT(r.replacement(),
|
| + IsInt32LessThan(p0, IsInt32Constant(c_2 - c_1 - c_0)));
|
| + }
|
| + {
|
| + Node* const k_0 = Int32Constant(c_0);
|
| + Node* const k_1 = Int32Constant(c_1);
|
| + Node* const k_2 = Int32Constant(c_2);
|
| + Node* const p0 = Parameter(0);
|
| + Node* const add_0 = graph()->NewNode(machine()->Int32Add(), p0, k_0);
|
| + Node* const add_1 = graph()->NewNode(machine()->Int32Add(), add_0, k_1);
|
| + Node* const node =
|
| + graph()->NewNode(machine()->Int32LessThan(), k_2, add_1);
|
| + Reduction r = Reduce(node);
|
| + ASSERT_TRUE(r.Changed());
|
| + EXPECT_THAT(r.replacement(),
|
| + IsInt32LessThan(IsInt32Constant(c_2 - c_1 - c_0), p0));
|
| + }
|
| + }
|
| +}
|
| +
|
| } // namespace compiler
|
| } // namespace internal
|
| } // namespace v8
|
|
|