| Index: test/unittests/compiler/load-elimination-unittest.cc
|
| diff --git a/test/unittests/compiler/load-elimination-unittest.cc b/test/unittests/compiler/load-elimination-unittest.cc
|
| index 721d6dfb1e551c5c6cf8af9b18ec9da46a4cbe4f..965390e42256ea281bd85a35d799e8aedfae2dff 100644
|
| --- a/test/unittests/compiler/load-elimination-unittest.cc
|
| +++ b/test/unittests/compiler/load-elimination-unittest.cc
|
| @@ -1,9 +1,10 @@
|
| -// Copyright 2014 the V8 project authors. All rights reserved.
|
| +// Copyright 2016 the V8 project authors. All rights reserved.
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "src/compiler/access-builder.h"
|
| #include "src/compiler/load-elimination.h"
|
| +#include "src/compiler/access-builder.h"
|
| +#include "src/compiler/node.h"
|
| #include "src/compiler/simplified-operator.h"
|
| #include "test/unittests/compiler/graph-unittest.h"
|
| #include "test/unittests/compiler/node-test-utils.h"
|
| @@ -18,11 +19,9 @@ class LoadEliminationTest : public TypedGraphTest {
|
| ~LoadEliminationTest() override {}
|
|
|
| protected:
|
| - Reduction Reduce(Node* node) {
|
| - // TODO(titzer): mock the GraphReducer here for better unit testing.
|
| - GraphReducer graph_reducer(zone(), graph());
|
| - LoadElimination reducer(&graph_reducer, graph(), simplified());
|
| - return reducer.Reduce(node);
|
| + void Run() {
|
| + LoadElimination load_elimination(graph(), zone());
|
| + load_elimination.Run();
|
| }
|
|
|
| SimplifiedOperatorBuilder* simplified() { return &simplified_; }
|
| @@ -31,42 +30,49 @@ class LoadEliminationTest : public TypedGraphTest {
|
| SimplifiedOperatorBuilder simplified_;
|
| };
|
|
|
| -
|
| -TEST_F(LoadEliminationTest, LoadFieldWithStoreField) {
|
| - Node* object1 = Parameter(Type::Any(), 0);
|
| - Node* object2 = Parameter(Type::Any(), 1);
|
| - Node* value = Parameter(Type::Any(), 2);
|
| +TEST_F(LoadEliminationTest, LoadFieldAndLoadField) {
|
| + Node* object = Parameter(Type::Any(), 0);
|
| Node* effect = graph()->start();
|
| Node* control = graph()->start();
|
| + FieldAccess access = {kTaggedBase,
|
| + kPointerSize,
|
| + MaybeHandle<Name>(),
|
| + Type::Any(),
|
| + MachineType::AnyTagged(),
|
| + kNoWriteBarrier};
|
| + Node* load1 = effect = graph()->NewNode(simplified()->LoadField(access),
|
| + object, effect, control);
|
| + Node* load2 = effect = graph()->NewNode(simplified()->LoadField(access),
|
| + object, effect, control);
|
| + control = graph()->NewNode(common()->Return(), load2, effect, control);
|
| + graph()->end()->ReplaceInput(0, control);
|
|
|
| - FieldAccess access1 = AccessBuilder::ForContextSlot(42);
|
| - Node* store1 = graph()->NewNode(simplified()->StoreField(access1), object1,
|
| - value, effect, control);
|
| - Reduction r1 = Reduce(graph()->NewNode(simplified()->LoadField(access1),
|
| - object1, store1, control));
|
| - ASSERT_TRUE(r1.Changed());
|
| - EXPECT_EQ(value, r1.replacement());
|
| + Run();
|
|
|
| - FieldAccess access2 = AccessBuilder::ForMap();
|
| - Node* store2 = graph()->NewNode(simplified()->StoreField(access2), object1,
|
| - object2, store1, control);
|
| - Reduction r2 = Reduce(graph()->NewNode(simplified()->LoadField(access2),
|
| - object1, store2, control));
|
| - ASSERT_TRUE(r2.Changed());
|
| - EXPECT_EQ(object2, r2.replacement());
|
| + EXPECT_THAT(graph()->end(), IsEnd(IsReturn(load1, load1, graph()->start())));
|
| +}
|
|
|
| - Node* store3 = graph()->NewNode(
|
| - simplified()->StoreBuffer(BufferAccess(kExternalInt8Array)), object2,
|
| - value, Int32Constant(10), object1, store2, control);
|
| +TEST_F(LoadEliminationTest, StoreFieldAndLoadField) {
|
| + Node* object = Parameter(Type::Any(), 0);
|
| + Node* value = Parameter(Type::Any(), 1);
|
| + Node* effect = graph()->start();
|
| + Node* control = graph()->start();
|
| + FieldAccess access = {kTaggedBase,
|
| + kPointerSize,
|
| + MaybeHandle<Name>(),
|
| + Type::Any(),
|
| + MachineType::AnyTagged(),
|
| + kNoWriteBarrier};
|
| + Node* store = effect = graph()->NewNode(simplified()->StoreField(access),
|
| + object, value, effect, control);
|
| + Node* load = effect = graph()->NewNode(simplified()->LoadField(access),
|
| + object, effect, control);
|
| + control = graph()->NewNode(common()->Return(), load, effect, control);
|
| + graph()->end()->ReplaceInput(0, control);
|
|
|
| - Reduction r3 = Reduce(graph()->NewNode(simplified()->LoadField(access1),
|
| - object2, store3, control));
|
| - ASSERT_FALSE(r3.Changed());
|
| + Run();
|
|
|
| - Reduction r4 = Reduce(graph()->NewNode(simplified()->LoadField(access1),
|
| - object1, store3, control));
|
| - ASSERT_TRUE(r4.Changed());
|
| - EXPECT_EQ(value, r4.replacement());
|
| + EXPECT_THAT(graph()->end(), IsEnd(IsReturn(value, store, graph()->start())));
|
| }
|
|
|
| } // namespace compiler
|
|
|