2014-12-22 13:06:34 +00:00
|
|
|
// Copyright 2014 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/common-operator-reducer.h"
|
2019-05-21 09:30:15 +00:00
|
|
|
#include "src/codegen/machine-type.h"
|
|
|
|
#include "src/compiler/common-operator.h"
|
2015-03-12 14:07:28 +00:00
|
|
|
#include "src/compiler/machine-operator.h"
|
2015-01-07 14:42:38 +00:00
|
|
|
#include "src/compiler/operator.h"
|
2015-06-25 11:06:58 +00:00
|
|
|
#include "src/compiler/simplified-operator.h"
|
2015-06-18 09:15:32 +00:00
|
|
|
#include "test/unittests/compiler/graph-reducer-unittest.h"
|
2014-12-22 13:06:34 +00:00
|
|
|
#include "test/unittests/compiler/graph-unittest.h"
|
2015-03-12 14:07:28 +00:00
|
|
|
#include "test/unittests/compiler/node-test-utils.h"
|
2014-12-22 13:06:34 +00:00
|
|
|
|
2015-06-18 09:15:32 +00:00
|
|
|
using testing::StrictMock;
|
|
|
|
|
2014-12-22 13:06:34 +00:00
|
|
|
namespace v8 {
|
|
|
|
namespace internal {
|
|
|
|
namespace compiler {
|
2017-09-28 17:55:52 +00:00
|
|
|
namespace common_operator_reducer_unittest {
|
2014-12-22 13:06:34 +00:00
|
|
|
|
|
|
|
class CommonOperatorReducerTest : public GraphTest {
|
|
|
|
public:
|
|
|
|
explicit CommonOperatorReducerTest(int num_parameters = 1)
|
2015-06-25 11:06:58 +00:00
|
|
|
: GraphTest(num_parameters), machine_(zone()), simplified_(zone()) {}
|
2018-09-17 11:30:48 +00:00
|
|
|
~CommonOperatorReducerTest() override = default;
|
2014-12-22 13:06:34 +00:00
|
|
|
|
|
|
|
protected:
|
2015-06-18 09:15:32 +00:00
|
|
|
Reduction Reduce(
|
|
|
|
AdvancedReducer::Editor* editor, Node* node,
|
2022-03-21 16:55:30 +00:00
|
|
|
BranchSemantics branch_semantics,
|
2015-06-18 09:15:32 +00:00
|
|
|
MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) {
|
2020-08-12 14:39:53 +00:00
|
|
|
JSHeapBroker broker(isolate(), zone());
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineOperatorBuilder machine(zone(), MachineType::PointerRepresentation(),
|
|
|
|
flags);
|
2018-07-09 13:49:51 +00:00
|
|
|
CommonOperatorReducer reducer(editor, graph(), &broker, common(), &machine,
|
2022-03-21 16:55:30 +00:00
|
|
|
zone(), branch_semantics);
|
2014-12-22 13:06:34 +00:00
|
|
|
return reducer.Reduce(node);
|
|
|
|
}
|
2015-03-12 14:07:28 +00:00
|
|
|
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction Reduce(
|
|
|
|
Node* node, BranchSemantics branch_semantics,
|
|
|
|
MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) {
|
2015-06-18 09:15:32 +00:00
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
2022-03-21 16:55:30 +00:00
|
|
|
return Reduce(&editor, node, branch_semantics, flags);
|
2015-06-18 09:15:32 +00:00
|
|
|
}
|
|
|
|
|
2015-03-12 14:07:28 +00:00
|
|
|
MachineOperatorBuilder* machine() { return &machine_; }
|
2015-06-25 11:06:58 +00:00
|
|
|
SimplifiedOperatorBuilder* simplified() { return &simplified_; }
|
2015-03-12 14:07:28 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
MachineOperatorBuilder machine_;
|
2015-06-25 11:06:58 +00:00
|
|
|
SimplifiedOperatorBuilder simplified_;
|
2014-12-22 13:06:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
const BranchHint kBranchHints[] = {BranchHint::kNone, BranchHint::kFalse,
|
|
|
|
BranchHint::kTrue};
|
|
|
|
|
|
|
|
|
2015-12-10 09:03:30 +00:00
|
|
|
const MachineRepresentation kMachineRepresentations[] = {
|
|
|
|
MachineRepresentation::kBit, MachineRepresentation::kWord8,
|
|
|
|
MachineRepresentation::kWord16, MachineRepresentation::kWord32,
|
|
|
|
MachineRepresentation::kWord64, MachineRepresentation::kFloat32,
|
|
|
|
MachineRepresentation::kFloat64, MachineRepresentation::kTagged};
|
2014-12-22 13:06:34 +00:00
|
|
|
|
|
|
|
|
|
|
|
const Operator kOp0(0, Operator::kNoProperties, "Op0", 0, 0, 0, 1, 1, 0);
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Branch
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, BranchWithInt32ZeroConstant) {
|
|
|
|
TRACED_FOREACH(BranchHint, hint, kBranchHints) {
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Node* const branch =
|
|
|
|
graph()->NewNode(common()->Branch(hint), Int32Constant(0), control);
|
|
|
|
Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Replace(if_true, IsDead()));
|
|
|
|
EXPECT_CALL(editor, Replace(if_false, control));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction const r = Reduce(&editor, branch, BranchSemantics::kMachine);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsDead());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, BranchWithInt32OneConstant) {
|
|
|
|
TRACED_FOREACH(BranchHint, hint, kBranchHints) {
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Node* const branch =
|
|
|
|
graph()->NewNode(common()->Branch(hint), Int32Constant(1), control);
|
|
|
|
Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Replace(if_true, control));
|
|
|
|
EXPECT_CALL(editor, Replace(if_false, IsDead()));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction const r = Reduce(&editor, branch, BranchSemantics::kMachine);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsDead());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, BranchWithFalseConstant) {
|
|
|
|
TRACED_FOREACH(BranchHint, hint, kBranchHints) {
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Node* const branch =
|
|
|
|
graph()->NewNode(common()->Branch(hint), FalseConstant(), control);
|
|
|
|
Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Replace(if_true, IsDead()));
|
|
|
|
EXPECT_CALL(editor, Replace(if_false, control));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction const r = Reduce(&editor, branch, BranchSemantics::kJS);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsDead());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, BranchWithTrueConstant) {
|
|
|
|
TRACED_FOREACH(BranchHint, hint, kBranchHints) {
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Node* const branch =
|
|
|
|
graph()->NewNode(common()->Branch(hint), TrueConstant(), control);
|
|
|
|
Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Replace(if_true, control));
|
|
|
|
EXPECT_CALL(editor, Replace(if_false, IsDead()));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction const r = Reduce(&editor, branch, BranchSemantics::kJS);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsDead());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-25 11:06:58 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, BranchWithBooleanNot) {
|
|
|
|
Node* const value = Parameter(0);
|
|
|
|
TRACED_FOREACH(BranchHint, hint, kBranchHints) {
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Node* const branch = graph()->NewNode(
|
|
|
|
common()->Branch(hint),
|
|
|
|
graph()->NewNode(simplified()->BooleanNot(), value), control);
|
|
|
|
Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction const r = Reduce(branch, BranchSemantics::kJS);
|
2015-06-25 11:06:58 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(branch, r.replacement());
|
|
|
|
EXPECT_THAT(branch, IsBranch(value, control));
|
|
|
|
EXPECT_THAT(if_false, IsIfTrue(branch));
|
|
|
|
EXPECT_THAT(if_true, IsIfFalse(branch));
|
2015-06-26 12:08:11 +00:00
|
|
|
EXPECT_EQ(NegateBranchHint(hint), BranchHintOf(branch->op()));
|
2015-06-25 11:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-05 07:02:00 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, BranchWithSelect) {
|
|
|
|
Node* const value = Parameter(0);
|
|
|
|
TRACED_FOREACH(BranchHint, hint, kBranchHints) {
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Node* const branch = graph()->NewNode(
|
|
|
|
common()->Branch(hint),
|
|
|
|
graph()->NewNode(common()->Select(MachineRepresentation::kTagged),
|
|
|
|
value, FalseConstant(), TrueConstant()),
|
|
|
|
control);
|
|
|
|
Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction const r = Reduce(branch, BranchSemantics::kJS);
|
2016-09-05 07:02:00 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(branch, r.replacement());
|
|
|
|
EXPECT_THAT(branch, IsBranch(value, control));
|
|
|
|
EXPECT_THAT(if_false, IsIfTrue(branch));
|
|
|
|
EXPECT_THAT(if_true, IsIfFalse(branch));
|
|
|
|
EXPECT_EQ(NegateBranchHint(hint), BranchHintOf(branch->op()));
|
|
|
|
}
|
|
|
|
}
|
2015-06-25 11:06:58 +00:00
|
|
|
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Merge
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, MergeOfUnusedDiamond0) {
|
|
|
|
Node* const value = Parameter(0);
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Node* const branch = graph()->NewNode(common()->Branch(), value, control);
|
|
|
|
Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
Reduction const r =
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduce(graph()->NewNode(common()->Merge(2), if_true, if_false),
|
|
|
|
BranchSemantics::kJS);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(control, r.replacement());
|
|
|
|
EXPECT_THAT(branch, IsDead());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, MergeOfUnusedDiamond1) {
|
|
|
|
Node* const value = Parameter(0);
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
Node* const branch = graph()->NewNode(common()->Branch(), value, control);
|
|
|
|
Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
Reduction const r =
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduce(graph()->NewNode(common()->Merge(2), if_false, if_true),
|
|
|
|
BranchSemantics::kJS);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(control, r.replacement());
|
|
|
|
EXPECT_THAT(branch, IsDead());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-22 13:06:34 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// EffectPhi
|
|
|
|
|
|
|
|
|
2015-06-18 09:15:32 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, EffectPhiWithMerge) {
|
2014-12-22 13:06:34 +00:00
|
|
|
const int kMaxInputs = 64;
|
|
|
|
Node* inputs[kMaxInputs];
|
|
|
|
Node* const input = graph()->NewNode(&kOp0);
|
|
|
|
TRACED_FORRANGE(int, input_count, 2, kMaxInputs - 1) {
|
|
|
|
int const value_input_count = input_count - 1;
|
2015-06-18 09:15:32 +00:00
|
|
|
for (int i = 0; i < value_input_count; ++i) {
|
|
|
|
inputs[i] = graph()->start();
|
|
|
|
}
|
|
|
|
Node* const merge = graph()->NewNode(common()->Merge(value_input_count),
|
|
|
|
value_input_count, inputs);
|
2014-12-22 13:06:34 +00:00
|
|
|
for (int i = 0; i < value_input_count; ++i) {
|
|
|
|
inputs[i] = input;
|
|
|
|
}
|
2015-06-18 09:15:32 +00:00
|
|
|
inputs[value_input_count] = merge;
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Revisit(merge));
|
|
|
|
Reduction r =
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduce(&editor,
|
|
|
|
graph()->NewNode(common()->EffectPhi(value_input_count),
|
|
|
|
input_count, inputs),
|
|
|
|
BranchSemantics::kJS);
|
2014-12-22 13:06:34 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(input, r.replacement());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-18 09:15:32 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, EffectPhiWithLoop) {
|
|
|
|
Node* const e0 = graph()->NewNode(&kOp0);
|
|
|
|
Node* const loop =
|
|
|
|
graph()->NewNode(common()->Loop(2), graph()->start(), graph()->start());
|
|
|
|
loop->ReplaceInput(1, loop);
|
|
|
|
Node* const ephi = graph()->NewNode(common()->EffectPhi(2), e0, e0, loop);
|
|
|
|
ephi->ReplaceInput(1, ephi);
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Revisit(loop));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction const r = Reduce(&editor, ephi, BranchSemantics::kJS);
|
2015-06-18 09:15:32 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(e0, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-12-22 13:06:34 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Phi
|
|
|
|
|
|
|
|
|
2015-06-18 09:15:32 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, PhiWithMerge) {
|
2014-12-22 13:06:34 +00:00
|
|
|
const int kMaxInputs = 64;
|
|
|
|
Node* inputs[kMaxInputs];
|
|
|
|
Node* const input = graph()->NewNode(&kOp0);
|
|
|
|
TRACED_FORRANGE(int, input_count, 2, kMaxInputs - 1) {
|
|
|
|
int const value_input_count = input_count - 1;
|
2015-12-10 09:03:30 +00:00
|
|
|
TRACED_FOREACH(MachineRepresentation, rep, kMachineRepresentations) {
|
2015-03-12 14:07:28 +00:00
|
|
|
for (int i = 0; i < value_input_count; ++i) {
|
|
|
|
inputs[i] = graph()->start();
|
|
|
|
}
|
2015-06-18 09:15:32 +00:00
|
|
|
Node* const merge = graph()->NewNode(common()->Merge(value_input_count),
|
|
|
|
value_input_count, inputs);
|
2014-12-22 13:06:34 +00:00
|
|
|
for (int i = 0; i < value_input_count; ++i) {
|
|
|
|
inputs[i] = input;
|
|
|
|
}
|
2015-03-12 14:07:28 +00:00
|
|
|
inputs[value_input_count] = merge;
|
2015-06-18 09:15:32 +00:00
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Revisit(merge));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r =
|
|
|
|
Reduce(&editor,
|
|
|
|
graph()->NewNode(common()->Phi(rep, value_input_count),
|
|
|
|
input_count, inputs),
|
|
|
|
BranchSemantics::kJS);
|
2014-12-22 13:06:34 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(input, r.replacement());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-18 09:15:32 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, PhiWithLoop) {
|
|
|
|
Node* const p0 = Parameter(0);
|
|
|
|
Node* const loop =
|
|
|
|
graph()->NewNode(common()->Loop(2), graph()->start(), graph()->start());
|
|
|
|
loop->ReplaceInput(1, loop);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* const phi = graph()->NewNode(
|
|
|
|
common()->Phi(MachineRepresentation::kTagged, 2), p0, p0, loop);
|
2015-06-18 09:15:32 +00:00
|
|
|
phi->ReplaceInput(1, phi);
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Revisit(loop));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction const r = Reduce(&editor, phi, BranchSemantics::kMachine);
|
2015-06-18 09:15:32 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(p0, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-08 11:54:53 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, PhiToFloat32Abs) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* c0 = Float32Constant(0.0);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0);
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* vtrue = p0;
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
Node* vfalse = graph()->NewNode(machine()->Float32Sub(), c0, p0);
|
|
|
|
Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* phi = graph()->NewNode(
|
|
|
|
common()->Phi(MachineRepresentation::kFloat32, 2), vtrue, vfalse, merge);
|
2015-06-18 09:15:32 +00:00
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Revisit(merge));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(&editor, phi, BranchSemantics::kMachine);
|
2015-04-08 11:54:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat32Abs(p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, PhiToFloat64Abs) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* c0 = Float64Constant(0.0);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0);
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* vtrue = p0;
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
Node* vfalse = graph()->NewNode(machine()->Float64Sub(), c0, p0);
|
|
|
|
Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* phi = graph()->NewNode(
|
|
|
|
common()->Phi(MachineRepresentation::kFloat64, 2), vtrue, vfalse, merge);
|
2015-06-18 09:15:32 +00:00
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Revisit(merge));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(&editor, phi, BranchSemantics::kMachine);
|
2015-04-08 11:54:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat64Abs(p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-06-26 08:20:53 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Return
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, ReturnWithPhiAndEffectPhiAndMerge) {
|
|
|
|
Node* cond = Parameter(2);
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), cond, graph()->start());
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* etrue = graph()->start();
|
|
|
|
Node* vtrue = Parameter(0);
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
Node* efalse = graph()->start();
|
|
|
|
Node* vfalse = Parameter(1);
|
|
|
|
Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
|
|
|
|
Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* phi = graph()->NewNode(common()->Phi(MachineRepresentation::kTagged, 2),
|
|
|
|
vtrue, vfalse, merge);
|
2016-11-02 13:15:39 +00:00
|
|
|
|
|
|
|
Node* zero = graph()->NewNode(common()->Int32Constant(0));
|
|
|
|
Node* ret = graph()->NewNode(common()->Return(), zero, phi, ephi, merge);
|
2015-06-26 08:20:53 +00:00
|
|
|
graph()->SetEnd(graph()->NewNode(common()->End(1), ret));
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Replace(merge, IsDead()));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction const r = Reduce(&editor, ret, BranchSemantics::kJS);
|
2015-06-26 08:20:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsDead());
|
|
|
|
EXPECT_THAT(graph()->end(), IsEnd(ret, IsReturn(vtrue, etrue, if_true),
|
|
|
|
IsReturn(vfalse, efalse, if_false)));
|
|
|
|
}
|
|
|
|
|
2017-01-17 19:01:32 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, MultiReturnWithPhiAndEffectPhiAndMerge) {
|
|
|
|
Node* cond = Parameter(2);
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), cond, graph()->start());
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* etrue = graph()->start();
|
|
|
|
Node* vtrue1 = Parameter(0);
|
|
|
|
Node* vtrue2 = Parameter(1);
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
Node* efalse = graph()->start();
|
|
|
|
Node* vfalse1 = Parameter(1);
|
|
|
|
Node* vfalse2 = Parameter(0);
|
|
|
|
Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
|
|
|
|
Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge);
|
|
|
|
Node* phi1 = graph()->NewNode(
|
|
|
|
common()->Phi(MachineRepresentation::kTagged, 2), vtrue1, vfalse1, merge);
|
|
|
|
Node* phi2 = graph()->NewNode(
|
|
|
|
common()->Phi(MachineRepresentation::kTagged, 2), vtrue2, vfalse2, merge);
|
|
|
|
|
|
|
|
Node* zero = graph()->NewNode(common()->Int32Constant(0));
|
|
|
|
Node* ret =
|
|
|
|
graph()->NewNode(common()->Return(2), zero, phi1, phi2, ephi, merge);
|
|
|
|
graph()->SetEnd(graph()->NewNode(common()->End(1), ret));
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction const r = Reduce(&editor, ret, BranchSemantics::kJS);
|
2017-01-17 19:01:32 +00:00
|
|
|
// For now a return with multiple return values should not be reduced.
|
|
|
|
ASSERT_TRUE(!r.Changed());
|
|
|
|
}
|
2015-06-26 08:20:53 +00:00
|
|
|
|
2014-12-22 13:06:34 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Select
|
|
|
|
|
|
|
|
|
2015-06-18 09:15:32 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, SelectWithSameThenAndElse) {
|
2014-12-22 13:06:34 +00:00
|
|
|
Node* const input = graph()->NewNode(&kOp0);
|
|
|
|
TRACED_FOREACH(BranchHint, hint, kBranchHints) {
|
2015-12-10 09:03:30 +00:00
|
|
|
TRACED_FOREACH(MachineRepresentation, rep, kMachineRepresentations) {
|
2014-12-22 13:06:34 +00:00
|
|
|
Reduction r = Reduce(
|
2022-03-21 16:55:30 +00:00
|
|
|
graph()->NewNode(common()->Select(rep, hint), input, input, input),
|
|
|
|
BranchSemantics::kJS);
|
2014-12-22 13:06:34 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(input, r.replacement());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-12 14:07:28 +00:00
|
|
|
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, SelectWithInt32ZeroConstant) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* select =
|
|
|
|
graph()->NewNode(common()->Select(MachineRepresentation::kTagged),
|
|
|
|
Int32Constant(0), p0, p1);
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(select, BranchSemantics::kMachine);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(p1, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, SelectWithInt32OneConstant) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* select =
|
|
|
|
graph()->NewNode(common()->Select(MachineRepresentation::kTagged),
|
|
|
|
Int32Constant(1), p0, p1);
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(select, BranchSemantics::kMachine);
|
[turbofan] Proper dead code elimination as regular reducer.
The three different concerns that the ControlReducer used to deal with
are now properly separated into
a.) DeadCodeElimination, which is a regular AdvancedReducer, that
propagates Dead via control edges,
b.) CommonOperatorReducer, which does strength reduction on common
operators (i.e. Branch, Phi, and friends), and
c.) GraphTrimming, which removes dead->live edges from the graph.
This will make it possible to run the DeadCodeElimination together with
other passes that actually introduce Dead nodes, i.e. typed lowering;
and it opens the door for general inlining without two stage fix point
iteration.
To make the DeadCodeElimination easier and more uniform, we basically
reverted the introduction of DeadValue and DeadEffect, and changed the
Dead operator to produce control, value and effect. Note however that
this is not a requirement, but merely a way to make dead propagation
easier and more uniform. We could always go back and decide to have
different Dead operators if some other change requires that.
Note that there are several additional opportunities for cleanup now,
i.e. OSR deconstruction could be a regular reducer now, and we don't
need to use TheHole as dead value marker in the GraphReducer. And we can
actually run the dead code elimination together with the other passes
instead of using separate passes over the graph. We will do this in
follow up CLs.
R=jarin@chromium.org, mstarzinger@chromium.org
Review URL: https://codereview.chromium.org/1193833002
Cr-Commit-Position: refs/heads/master@{#29146}
2015-06-19 12:07:17 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(p0, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-10 10:28:06 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, SelectWithFalseConstant) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* select =
|
|
|
|
graph()->NewNode(common()->Select(MachineRepresentation::kTagged),
|
|
|
|
FalseConstant(), p0, p1);
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(select, BranchSemantics::kJS);
|
2015-04-10 10:28:06 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(p1, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, SelectWithTrueConstant) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* select = graph()->NewNode(
|
|
|
|
common()->Select(MachineRepresentation::kTagged), TrueConstant(), p0, p1);
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(select, BranchSemantics::kJS);
|
2015-04-10 10:28:06 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_EQ(p0, r.replacement());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-04-08 11:54:53 +00:00
|
|
|
TEST_F(CommonOperatorReducerTest, SelectToFloat32Abs) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* c0 = Float32Constant(0.0);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0);
|
|
|
|
Node* select =
|
2015-12-10 09:03:30 +00:00
|
|
|
graph()->NewNode(common()->Select(MachineRepresentation::kFloat32), check,
|
|
|
|
p0, graph()->NewNode(machine()->Float32Sub(), c0, p0));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(select, BranchSemantics::kMachine);
|
2015-04-08 11:54:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat32Abs(p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, SelectToFloat64Abs) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* c0 = Float64Constant(0.0);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0);
|
|
|
|
Node* select =
|
2015-12-10 09:03:30 +00:00
|
|
|
graph()->NewNode(common()->Select(MachineRepresentation::kFloat64), check,
|
|
|
|
p0, graph()->NewNode(machine()->Float64Sub(), c0, p0));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(select, BranchSemantics::kMachine);
|
2015-04-08 11:54:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat64Abs(p0));
|
|
|
|
}
|
|
|
|
|
2018-01-31 12:32:55 +00:00
|
|
|
// -----------------------------------------------------------------------------
|
|
|
|
// Switch
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, SwitchInputMatchesCaseWithDefault) {
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
|
|
|
|
Node* sw = graph()->NewNode(common()->Switch(2), Int32Constant(1), control);
|
|
|
|
Node* const if_1 = graph()->NewNode(common()->IfValue(1), sw);
|
|
|
|
graph()->NewNode(common()->IfDefault(), sw);
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Replace(if_1, control));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(&editor, sw, BranchSemantics::kMachine);
|
2018-01-31 12:32:55 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsDead());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, SwitchInputMatchesDefaultWithCase) {
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
|
|
|
|
Node* sw = graph()->NewNode(common()->Switch(2), Int32Constant(0), control);
|
|
|
|
graph()->NewNode(common()->IfValue(1), sw);
|
|
|
|
Node* const if_default = graph()->NewNode(common()->IfDefault(), sw);
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Replace(if_default, control));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(&editor, sw, BranchSemantics::kMachine);
|
2018-01-31 12:32:55 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsDead());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, SwitchInputMatchesCaseExtraCaseWithDefault) {
|
|
|
|
Node* const control = graph()->start();
|
|
|
|
|
|
|
|
Node* sw = graph()->NewNode(common()->Switch(3), Int32Constant(0), control);
|
|
|
|
Node* const if_0 = graph()->NewNode(common()->IfValue(0), sw);
|
|
|
|
graph()->NewNode(common()->IfValue(1), sw);
|
|
|
|
graph()->NewNode(common()->IfDefault(), sw);
|
|
|
|
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Replace(if_0, control));
|
2022-03-21 16:55:30 +00:00
|
|
|
Reduction r = Reduce(&editor, sw, BranchSemantics::kMachine);
|
2018-01-31 12:32:55 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsDead());
|
|
|
|
}
|
|
|
|
|
2017-09-28 17:55:52 +00:00
|
|
|
} // namespace common_operator_reducer_unittest
|
2014-12-22 13:06:34 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|