Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/compiler/access-builder.h" |
| 6 | #include "src/compiler/load-elimination.h" |
| 7 | #include "src/compiler/simplified-operator.h" |
| 8 | #include "test/unittests/compiler/graph-unittest.h" |
| 9 | #include "test/unittests/compiler/node-test-utils.h" |
| 10 | |
| 11 | namespace v8 { |
| 12 | namespace internal { |
| 13 | namespace compiler { |
| 14 | |
| 15 | class LoadEliminationTest : public GraphTest { |
| 16 | public: |
| 17 | LoadEliminationTest() : GraphTest(3), simplified_(zone()) {} |
| 18 | ~LoadEliminationTest() OVERRIDE {} |
| 19 | |
| 20 | protected: |
| 21 | Reduction Reduce(Node* node) { |
| 22 | LoadElimination reducer; |
| 23 | return reducer.Reduce(node); |
| 24 | } |
| 25 | |
| 26 | SimplifiedOperatorBuilder* simplified() { return &simplified_; } |
| 27 | |
| 28 | private: |
| 29 | SimplifiedOperatorBuilder simplified_; |
| 30 | }; |
| 31 | |
| 32 | |
| 33 | TEST_F(LoadEliminationTest, LoadFieldWithStoreField) { |
| 34 | Node* object1 = Parameter(0); |
| 35 | Node* object2 = Parameter(1); |
| 36 | Node* value = Parameter(2); |
| 37 | Node* effect = graph()->start(); |
| 38 | Node* control = graph()->start(); |
| 39 | |
| 40 | FieldAccess access1 = AccessBuilder::ForContextSlot(42); |
| 41 | Node* store1 = graph()->NewNode(simplified()->StoreField(access1), object1, |
| 42 | value, effect, control); |
| 43 | Reduction r1 = Reduce(graph()->NewNode(simplified()->LoadField(access1), |
| 44 | object1, store1, control)); |
| 45 | ASSERT_TRUE(r1.Changed()); |
| 46 | EXPECT_EQ(value, r1.replacement()); |
| 47 | |
| 48 | FieldAccess access2 = AccessBuilder::ForMap(); |
| 49 | Node* store2 = graph()->NewNode(simplified()->StoreField(access2), object1, |
| 50 | object2, store1, control); |
| 51 | Reduction r2 = Reduce(graph()->NewNode(simplified()->LoadField(access2), |
| 52 | object1, store2, control)); |
| 53 | ASSERT_TRUE(r2.Changed()); |
| 54 | EXPECT_EQ(object2, r2.replacement()); |
| 55 | |
| 56 | Node* store3 = graph()->NewNode( |
| 57 | simplified()->StoreBuffer(BufferAccess(kExternalInt8Array)), object2, |
| 58 | value, Int32Constant(10), object1, store2, control); |
| 59 | |
| 60 | Reduction r3 = Reduce(graph()->NewNode(simplified()->LoadField(access1), |
| 61 | object2, store3, control)); |
| 62 | ASSERT_FALSE(r3.Changed()); |
| 63 | |
| 64 | Reduction r4 = Reduce(graph()->NewNode(simplified()->LoadField(access1), |
| 65 | object1, store3, control)); |
| 66 | ASSERT_TRUE(r4.Changed()); |
| 67 | EXPECT_EQ(value, r4.replacement()); |
| 68 | } |
| 69 | |
| 70 | } // namespace compiler |
| 71 | } // namespace internal |
| 72 | } // namespace v8 |