2016-07-05 12:19:48 +00:00
|
|
|
// Copyright 2016 the V8 project authors. All rights reserved.
|
2014-12-05 07:59:04 +00:00
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "src/compiler/load-elimination.h"
|
2022-07-18 13:30:02 +00:00
|
|
|
|
2016-07-05 12:19:48 +00:00
|
|
|
#include "src/compiler/access-builder.h"
|
2016-08-05 15:28:52 +00:00
|
|
|
#include "src/compiler/js-graph.h"
|
2016-07-05 12:19:48 +00:00
|
|
|
#include "src/compiler/node.h"
|
2014-12-05 07:59:04 +00:00
|
|
|
#include "src/compiler/simplified-operator.h"
|
2016-07-25 12:02:20 +00:00
|
|
|
#include "test/unittests/compiler/graph-reducer-unittest.h"
|
2014-12-05 07:59:04 +00:00
|
|
|
#include "test/unittests/compiler/graph-unittest.h"
|
|
|
|
#include "test/unittests/compiler/node-test-utils.h"
|
2016-07-25 12:02:20 +00:00
|
|
|
|
|
|
|
using testing::_;
|
|
|
|
using testing::StrictMock;
|
2014-12-05 07:59:04 +00:00
|
|
|
|
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
|
|
|
|
2016-04-05 12:29:43 +00:00
|
|
|
class LoadEliminationTest : public TypedGraphTest {
|
2014-12-05 07:59:04 +00:00
|
|
|
public:
|
2016-08-05 15:28:52 +00:00
|
|
|
LoadEliminationTest()
|
|
|
|
: TypedGraphTest(3),
|
|
|
|
simplified_(zone()),
|
|
|
|
jsgraph_(isolate(), graph(), common(), nullptr, simplified(), nullptr) {
|
|
|
|
}
|
2018-09-17 11:30:48 +00:00
|
|
|
~LoadEliminationTest() override = default;
|
2014-12-05 07:59:04 +00:00
|
|
|
|
|
|
|
protected:
|
2016-08-05 15:28:52 +00:00
|
|
|
JSGraph* jsgraph() { return &jsgraph_; }
|
2014-12-05 07:59:04 +00:00
|
|
|
SimplifiedOperatorBuilder* simplified() { return &simplified_; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
SimplifiedOperatorBuilder simplified_;
|
2016-08-05 15:28:52 +00:00
|
|
|
JSGraph jsgraph_;
|
2014-12-05 07:59:04 +00:00
|
|
|
};
|
|
|
|
|
2016-07-25 12:02:20 +00:00
|
|
|
TEST_F(LoadEliminationTest, LoadElementAndLoadElement) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* index = Parameter(Type::UnsignedSmall(), 1);
|
2019-02-14 13:01:52 +00:00
|
|
|
ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(),
|
2016-07-25 12:02:20 +00:00
|
|
|
MachineType::AnyTagged(), kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
2016-08-05 15:28:52 +00:00
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
2016-07-25 12:02:20 +00:00
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
|
|
|
Node* load1 = effect = graph()->NewNode(simplified()->LoadElement(access),
|
|
|
|
object, index, effect, control);
|
|
|
|
load_elimination.Reduce(load1);
|
|
|
|
|
|
|
|
Node* load2 = effect = graph()->NewNode(simplified()->LoadElement(access),
|
|
|
|
object, index, effect, control);
|
|
|
|
EXPECT_CALL(editor, ReplaceWithValue(load2, load1, load1, _));
|
|
|
|
Reduction r = load_elimination.Reduce(load2);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(load1, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LoadEliminationTest, StoreElementAndLoadElement) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* index = Parameter(Type::UnsignedSmall(), 1);
|
|
|
|
Node* value = Parameter(Type::Any(), 2);
|
2019-02-14 13:01:52 +00:00
|
|
|
ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(),
|
2016-07-25 12:02:20 +00:00
|
|
|
MachineType::AnyTagged(), kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
2016-08-05 15:28:52 +00:00
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
2016-07-25 12:02:20 +00:00
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
|
|
|
Node* store = effect =
|
|
|
|
graph()->NewNode(simplified()->StoreElement(access), object, index, value,
|
|
|
|
effect, control);
|
|
|
|
load_elimination.Reduce(store);
|
|
|
|
|
|
|
|
Node* load = effect = graph()->NewNode(simplified()->LoadElement(access),
|
|
|
|
object, index, effect, control);
|
|
|
|
EXPECT_CALL(editor, ReplaceWithValue(load, value, store, _));
|
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(value, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LoadEliminationTest, StoreElementAndStoreFieldAndLoadElement) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
Node* index = Parameter(Type::UnsignedSmall(), 1);
|
|
|
|
Node* value = Parameter(Type::Any(), 2);
|
2019-02-14 13:01:52 +00:00
|
|
|
ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(),
|
2016-07-25 12:02:20 +00:00
|
|
|
MachineType::AnyTagged(), kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
2016-08-05 15:28:52 +00:00
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
2016-07-25 12:02:20 +00:00
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
|
|
|
Node* store1 = effect =
|
|
|
|
graph()->NewNode(simplified()->StoreElement(access), object, index, value,
|
|
|
|
effect, control);
|
|
|
|
load_elimination.Reduce(store1);
|
|
|
|
|
|
|
|
Node* store2 = effect =
|
|
|
|
graph()->NewNode(simplified()->StoreField(AccessBuilder::ForMap()),
|
|
|
|
object, value, effect, control);
|
|
|
|
load_elimination.Reduce(store2);
|
|
|
|
|
|
|
|
Node* load = effect = graph()->NewNode(simplified()->LoadElement(access),
|
|
|
|
object, index, effect, control);
|
|
|
|
EXPECT_CALL(editor, ReplaceWithValue(load, value, store2, _));
|
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(value, r.replacement());
|
|
|
|
}
|
|
|
|
|
2016-07-05 12:19:48 +00:00
|
|
|
TEST_F(LoadEliminationTest, LoadFieldAndLoadField) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
2014-12-05 07:59:04 +00:00
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2019-02-14 13:01:52 +00:00
|
|
|
FieldAccess const access = {kTaggedBase, kTaggedSize,
|
2017-01-02 19:07:28 +00:00
|
|
|
MaybeHandle<Name>(), MaybeHandle<Map>(),
|
|
|
|
Type::Any(), MachineType::AnyTagged(),
|
2016-07-25 12:02:20 +00:00
|
|
|
kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
2016-08-05 15:28:52 +00:00
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
2016-07-25 12:02:20 +00:00
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
2016-07-05 12:19:48 +00:00
|
|
|
Node* load1 = effect = graph()->NewNode(simplified()->LoadField(access),
|
|
|
|
object, effect, control);
|
2016-07-25 12:02:20 +00:00
|
|
|
load_elimination.Reduce(load1);
|
|
|
|
|
2016-07-05 12:19:48 +00:00
|
|
|
Node* load2 = effect = graph()->NewNode(simplified()->LoadField(access),
|
|
|
|
object, effect, control);
|
2016-07-25 12:02:20 +00:00
|
|
|
EXPECT_CALL(editor, ReplaceWithValue(load2, load1, load1, _));
|
|
|
|
Reduction r = load_elimination.Reduce(load2);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(load1, r.replacement());
|
2016-07-05 12:19:48 +00:00
|
|
|
}
|
2014-12-05 07:59:04 +00:00
|
|
|
|
2016-07-05 12:19:48 +00:00
|
|
|
TEST_F(LoadEliminationTest, StoreFieldAndLoadField) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* value = Parameter(Type::Any(), 1);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2019-02-14 13:01:52 +00:00
|
|
|
FieldAccess access = {kTaggedBase, kTaggedSize,
|
2017-01-02 19:07:28 +00:00
|
|
|
MaybeHandle<Name>(), MaybeHandle<Map>(),
|
|
|
|
Type::Any(), MachineType::AnyTagged(),
|
2016-07-05 12:19:48 +00:00
|
|
|
kNoWriteBarrier};
|
2016-07-25 12:02:20 +00:00
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
2016-08-05 15:28:52 +00:00
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
2016-07-25 12:02:20 +00:00
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
2016-07-05 12:19:48 +00:00
|
|
|
Node* store = effect = graph()->NewNode(simplified()->StoreField(access),
|
|
|
|
object, value, effect, control);
|
2016-07-25 12:02:20 +00:00
|
|
|
load_elimination.Reduce(store);
|
|
|
|
|
2016-07-05 12:19:48 +00:00
|
|
|
Node* load = effect = graph()->NewNode(simplified()->LoadField(access),
|
|
|
|
object, effect, control);
|
2016-07-25 12:02:20 +00:00
|
|
|
EXPECT_CALL(editor, ReplaceWithValue(load, value, store, _));
|
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(value, r.replacement());
|
|
|
|
}
|
2014-12-05 07:59:04 +00:00
|
|
|
|
2017-01-17 03:12:08 +00:00
|
|
|
TEST_F(LoadEliminationTest, StoreFieldAndKillFields) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* value = Parameter(Type::Any(), 1);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
|
|
|
|
2019-02-14 13:01:52 +00:00
|
|
|
FieldAccess access1 = {kTaggedBase, kTaggedSize,
|
|
|
|
MaybeHandle<Name>(), MaybeHandle<Map>(),
|
|
|
|
Type::Any(), MachineType::AnyTagged(),
|
|
|
|
kNoWriteBarrier};
|
2017-01-17 03:12:08 +00:00
|
|
|
|
|
|
|
// Offset that out of field cache size.
|
2019-02-14 13:01:52 +00:00
|
|
|
FieldAccess access2 = {kTaggedBase, 2048 * kTaggedSize,
|
|
|
|
MaybeHandle<Name>(), MaybeHandle<Map>(),
|
|
|
|
Type::Any(), MachineType::AnyTagged(),
|
|
|
|
kNoWriteBarrier};
|
2017-01-17 03:12:08 +00:00
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
|
|
|
Node* store1 = effect = graph()->NewNode(simplified()->StoreField(access1),
|
|
|
|
object, value, effect, control);
|
|
|
|
load_elimination.Reduce(store1);
|
|
|
|
|
|
|
|
// Invalidate caches of object.
|
|
|
|
Node* store2 = effect = graph()->NewNode(simplified()->StoreField(access2),
|
|
|
|
object, value, effect, control);
|
|
|
|
load_elimination.Reduce(store2);
|
|
|
|
|
|
|
|
Node* store3 = graph()->NewNode(simplified()->StoreField(access1),
|
|
|
|
object, value, effect, control);
|
|
|
|
|
|
|
|
Reduction r = load_elimination.Reduce(store3);
|
|
|
|
|
|
|
|
// store3 shall not be replaced, since caches were invalidated.
|
|
|
|
EXPECT_EQ(store3, r.replacement());
|
|
|
|
}
|
|
|
|
|
2016-07-25 12:02:20 +00:00
|
|
|
TEST_F(LoadEliminationTest, StoreFieldAndStoreElementAndLoadField) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* value = Parameter(Type::Any(), 1);
|
|
|
|
Node* index = Parameter(Type::UnsignedSmall(), 2);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2019-02-14 13:01:52 +00:00
|
|
|
FieldAccess access = {kTaggedBase, kTaggedSize,
|
2017-01-02 19:07:28 +00:00
|
|
|
MaybeHandle<Name>(), MaybeHandle<Map>(),
|
|
|
|
Type::Any(), MachineType::AnyTagged(),
|
2016-07-25 12:02:20 +00:00
|
|
|
kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
2016-08-05 15:28:52 +00:00
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
2016-07-25 12:02:20 +00:00
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
|
|
|
Node* store1 = effect = graph()->NewNode(simplified()->StoreField(access),
|
|
|
|
object, value, effect, control);
|
|
|
|
load_elimination.Reduce(store1);
|
2014-12-05 07:59:04 +00:00
|
|
|
|
2016-07-25 12:02:20 +00:00
|
|
|
Node* store2 = effect = graph()->NewNode(
|
|
|
|
simplified()->StoreElement(AccessBuilder::ForFixedArrayElement()), object,
|
|
|
|
index, object, effect, control);
|
|
|
|
load_elimination.Reduce(store2);
|
|
|
|
|
|
|
|
Node* load = effect = graph()->NewNode(simplified()->LoadField(access),
|
|
|
|
object, effect, control);
|
|
|
|
EXPECT_CALL(editor, ReplaceWithValue(load, value, store2, _));
|
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(value, r.replacement());
|
2014-12-05 07:59:04 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 05:08:52 +00:00
|
|
|
TEST_F(LoadEliminationTest, LoadElementOnTrueBranchOfDiamond) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* index = Parameter(Type::UnsignedSmall(), 1);
|
|
|
|
Node* check = Parameter(Type::Boolean(), 2);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2019-02-14 13:01:52 +00:00
|
|
|
ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(),
|
2016-08-25 05:08:52 +00:00
|
|
|
MachineType::AnyTagged(), kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), check, control);
|
|
|
|
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* etrue = graph()->NewNode(simplified()->LoadElement(access), object,
|
|
|
|
index, effect, if_true);
|
|
|
|
load_elimination.Reduce(etrue);
|
|
|
|
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
Node* efalse = effect;
|
|
|
|
|
|
|
|
control = graph()->NewNode(common()->Merge(2), if_true, if_false);
|
|
|
|
effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control);
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
Node* load = graph()->NewNode(simplified()->LoadElement(access), object,
|
|
|
|
index, effect, control);
|
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(load, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LoadEliminationTest, LoadElementOnFalseBranchOfDiamond) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* index = Parameter(Type::UnsignedSmall(), 1);
|
|
|
|
Node* check = Parameter(Type::Boolean(), 2);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2019-02-14 13:01:52 +00:00
|
|
|
ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Any(),
|
2016-08-25 05:08:52 +00:00
|
|
|
MachineType::AnyTagged(), kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), check, control);
|
|
|
|
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* etrue = effect;
|
|
|
|
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
Node* efalse = graph()->NewNode(simplified()->LoadElement(access), object,
|
|
|
|
index, effect, if_false);
|
|
|
|
load_elimination.Reduce(efalse);
|
|
|
|
|
|
|
|
control = graph()->NewNode(common()->Merge(2), if_true, if_false);
|
|
|
|
effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control);
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
Node* load = graph()->NewNode(simplified()->LoadElement(access), object,
|
|
|
|
index, effect, control);
|
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(load, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LoadEliminationTest, LoadFieldOnFalseBranchOfDiamond) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* check = Parameter(Type::Boolean(), 1);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2019-02-14 13:01:52 +00:00
|
|
|
FieldAccess const access = {kTaggedBase, kTaggedSize,
|
2017-01-02 19:07:28 +00:00
|
|
|
MaybeHandle<Name>(), MaybeHandle<Map>(),
|
|
|
|
Type::Any(), MachineType::AnyTagged(),
|
2016-08-25 05:08:52 +00:00
|
|
|
kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), check, control);
|
|
|
|
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* etrue = effect;
|
|
|
|
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
Node* efalse = graph()->NewNode(simplified()->LoadField(access), object,
|
|
|
|
effect, if_false);
|
|
|
|
load_elimination.Reduce(efalse);
|
|
|
|
|
|
|
|
control = graph()->NewNode(common()->Merge(2), if_true, if_false);
|
|
|
|
effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control);
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
Node* load = graph()->NewNode(simplified()->LoadField(access), object, effect,
|
|
|
|
control);
|
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(load, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LoadEliminationTest, LoadFieldOnTrueBranchOfDiamond) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* check = Parameter(Type::Boolean(), 1);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2019-02-14 13:01:52 +00:00
|
|
|
FieldAccess const access = {kTaggedBase, kTaggedSize,
|
2017-01-02 19:07:28 +00:00
|
|
|
MaybeHandle<Name>(), MaybeHandle<Map>(),
|
|
|
|
Type::Any(), MachineType::AnyTagged(),
|
2016-08-25 05:08:52 +00:00
|
|
|
kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), check, control);
|
|
|
|
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* etrue = graph()->NewNode(simplified()->LoadField(access), object,
|
|
|
|
effect, if_true);
|
|
|
|
load_elimination.Reduce(etrue);
|
|
|
|
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
Node* efalse = effect;
|
|
|
|
|
|
|
|
control = graph()->NewNode(common()->Merge(2), if_true, if_false);
|
|
|
|
effect = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, control);
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
Node* load = graph()->NewNode(simplified()->LoadField(access), object, effect,
|
|
|
|
control);
|
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(load, r.replacement());
|
|
|
|
}
|
|
|
|
|
2016-08-31 05:48:05 +00:00
|
|
|
TEST_F(LoadEliminationTest, LoadFieldWithTypeMismatch) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* value = Parameter(Type::Signed32(), 1);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2019-02-14 13:01:52 +00:00
|
|
|
FieldAccess const access = {kTaggedBase, kTaggedSize,
|
2017-01-02 19:07:28 +00:00
|
|
|
MaybeHandle<Name>(), MaybeHandle<Map>(),
|
|
|
|
Type::Unsigned31(), MachineType::AnyTagged(),
|
2016-08-31 05:48:05 +00:00
|
|
|
kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
2017-08-08 10:53:44 +00:00
|
|
|
effect = graph()->NewNode(simplified()->StoreField(access), object, value,
|
|
|
|
effect, control);
|
2016-08-31 05:48:05 +00:00
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
Node* load = graph()->NewNode(simplified()->LoadField(access), object, effect,
|
|
|
|
control);
|
2018-08-24 10:49:27 +00:00
|
|
|
EXPECT_CALL(editor, ReplaceWithValue(load, IsTypeGuard(value, _), _, _));
|
2016-08-31 05:48:05 +00:00
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2018-08-24 10:49:27 +00:00
|
|
|
EXPECT_THAT(r.replacement(), IsTypeGuard(value, _));
|
2016-08-31 05:48:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(LoadEliminationTest, LoadElementWithTypeMismatch) {
|
|
|
|
Node* object = Parameter(Type::Any(), 0);
|
|
|
|
Node* index = Parameter(Type::UnsignedSmall(), 1);
|
|
|
|
Node* value = Parameter(Type::Signed32(), 2);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2019-02-14 13:01:52 +00:00
|
|
|
ElementAccess const access = {kTaggedBase, kTaggedSize, Type::Unsigned31(),
|
2016-08-31 05:48:05 +00:00
|
|
|
MachineType::AnyTagged(), kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
|
|
|
|
|
|
|
load_elimination.Reduce(graph()->start());
|
|
|
|
|
2017-08-08 10:53:44 +00:00
|
|
|
effect = graph()->NewNode(simplified()->StoreElement(access), object, index,
|
|
|
|
value, effect, control);
|
2016-08-31 05:48:05 +00:00
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
Node* load = graph()->NewNode(simplified()->LoadElement(access), object,
|
|
|
|
index, effect, control);
|
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
2017-08-08 10:53:44 +00:00
|
|
|
EXPECT_EQ(load, r.replacement());
|
2016-08-31 05:48:05 +00:00
|
|
|
}
|
|
|
|
|
2016-09-01 10:50:08 +00:00
|
|
|
TEST_F(LoadEliminationTest, AliasAnalysisForFinishRegion) {
|
|
|
|
Node* value0 = Parameter(Type::Signed32(), 0);
|
|
|
|
Node* value1 = Parameter(Type::Signed32(), 1);
|
|
|
|
Node* effect = graph()->start();
|
|
|
|
Node* control = graph()->start();
|
2019-02-14 13:01:52 +00:00
|
|
|
FieldAccess const access = {kTaggedBase, kTaggedSize,
|
2017-01-02 19:07:28 +00:00
|
|
|
MaybeHandle<Name>(), MaybeHandle<Map>(),
|
|
|
|
Type::Signed32(), MachineType::AnyTagged(),
|
2016-09-01 10:50:08 +00:00
|
|
|
kNoWriteBarrier};
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
LoadElimination load_elimination(&editor, jsgraph(), zone());
|
|
|
|
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
effect = graph()->NewNode(
|
|
|
|
common()->BeginRegion(RegionObservability::kNotObservable), effect);
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
2019-03-11 19:04:02 +00:00
|
|
|
Node* object0 = effect = graph()->NewNode(
|
|
|
|
simplified()->Allocate(Type::Any(), AllocationType::kYoung),
|
|
|
|
jsgraph()->Constant(16), effect, control);
|
2016-09-01 10:50:08 +00:00
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
Node* region0 = effect =
|
|
|
|
graph()->NewNode(common()->FinishRegion(), object0, effect);
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
effect = graph()->NewNode(
|
|
|
|
common()->BeginRegion(RegionObservability::kNotObservable), effect);
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
2019-03-11 19:04:02 +00:00
|
|
|
Node* object1 = effect = graph()->NewNode(
|
|
|
|
simplified()->Allocate(Type::Any(), AllocationType::kYoung),
|
|
|
|
jsgraph()->Constant(16), effect, control);
|
2016-09-01 10:50:08 +00:00
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
Node* region1 = effect =
|
|
|
|
graph()->NewNode(common()->FinishRegion(), object1, effect);
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
effect = graph()->NewNode(simplified()->StoreField(access), region0, value0,
|
|
|
|
effect, control);
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
effect = graph()->NewNode(simplified()->StoreField(access), region1, value1,
|
|
|
|
effect, control);
|
|
|
|
load_elimination.Reduce(effect);
|
|
|
|
|
|
|
|
Node* load = graph()->NewNode(simplified()->LoadField(access), region0,
|
|
|
|
effect, control);
|
|
|
|
EXPECT_CALL(editor, ReplaceWithValue(load, value0, effect, _));
|
|
|
|
Reduction r = load_elimination.Reduce(load);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(value0, r.replacement());
|
|
|
|
}
|
|
|
|
|
2014-12-05 07:59:04 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|