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.h"
|
|
|
|
#include "src/compiler/common-operator-reducer.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-12-03 13:33:14 +00:00
|
|
|
#include "src/machine-type.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 {
|
|
|
|
|
|
|
|
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()) {}
|
2015-04-20 13:08:11 +00:00
|
|
|
~CommonOperatorReducerTest() override {}
|
2014-12-22 13:06:34 +00:00
|
|
|
|
|
|
|
protected:
|
2015-06-18 09:15:32 +00:00
|
|
|
Reduction Reduce(
|
|
|
|
AdvancedReducer::Editor* editor, Node* node,
|
|
|
|
MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) {
|
2015-12-10 09:03:30 +00:00
|
|
|
MachineOperatorBuilder machine(zone(), MachineType::PointerRepresentation(),
|
|
|
|
flags);
|
2015-06-18 09:15:32 +00:00
|
|
|
CommonOperatorReducer reducer(editor, graph(), common(), &machine);
|
2014-12-22 13:06:34 +00:00
|
|
|
return reducer.Reduce(node);
|
|
|
|
}
|
2015-03-12 14:07:28 +00:00
|
|
|
|
2015-06-18 09:15:32 +00:00
|
|
|
Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags =
|
|
|
|
MachineOperatorBuilder::kNoFlags) {
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
return Reduce(&editor, node, flags);
|
|
|
|
}
|
|
|
|
|
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));
|
|
|
|
Reduction const r = Reduce(&editor, branch);
|
|
|
|
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()));
|
|
|
|
Reduction const r = Reduce(&editor, branch);
|
|
|
|
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));
|
|
|
|
Reduction const r = Reduce(&editor, branch);
|
|
|
|
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()));
|
|
|
|
Reduction const r = Reduce(&editor, branch);
|
|
|
|
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);
|
|
|
|
Reduction const r = Reduce(branch);
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
[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 =
|
|
|
|
Reduce(graph()->NewNode(common()->Merge(2), if_true, if_false));
|
|
|
|
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 =
|
|
|
|
Reduce(graph()->NewNode(common()->Merge(2), if_false, if_true));
|
|
|
|
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 =
|
|
|
|
Reduce(&editor, graph()->NewNode(common()->EffectPhi(value_input_count),
|
|
|
|
input_count, inputs));
|
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));
|
|
|
|
Reduction const r = Reduce(&editor, ephi);
|
|
|
|
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));
|
|
|
|
Reduction r = Reduce(
|
2015-12-10 09:03:30 +00:00
|
|
|
&editor, graph()->NewNode(common()->Phi(rep, value_input_count),
|
2015-06-18 09:15:32 +00:00
|
|
|
input_count, inputs));
|
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));
|
|
|
|
Reduction const r = Reduce(&editor, phi);
|
|
|
|
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));
|
|
|
|
Reduction r = Reduce(&editor, phi);
|
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));
|
|
|
|
Reduction r = Reduce(&editor, phi);
|
2015-04-08 11:54:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat64Abs(p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, PhiToFloat32Max) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1);
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
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), p1, p0, merge);
|
2015-06-18 09:15:32 +00:00
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Revisit(merge));
|
|
|
|
Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat32Max);
|
2015-04-08 11:54:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat32Max(p1, p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, PhiToFloat64Max) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1);
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
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), p1, p0, merge);
|
2015-06-18 09:15:32 +00:00
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Revisit(merge));
|
|
|
|
Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat64Max);
|
2015-04-08 11:54:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat64Max(p1, p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, PhiToFloat32Min) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1);
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
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), p0, p1, merge);
|
2015-06-18 09:15:32 +00:00
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Revisit(merge));
|
|
|
|
Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat32Min);
|
2015-04-08 11:54:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat32Min(p0, p1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, PhiToFloat64Min) {
|
2015-03-12 14:07:28 +00:00
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1);
|
|
|
|
Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start());
|
|
|
|
Node* if_true = graph()->NewNode(common()->IfTrue(), branch);
|
|
|
|
Node* if_false = graph()->NewNode(common()->IfFalse(), branch);
|
|
|
|
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), p0, p1, merge);
|
2015-06-18 09:15:32 +00:00
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Revisit(merge));
|
|
|
|
Reduction r = Reduce(&editor, phi, MachineOperatorBuilder::kFloat64Min);
|
2015-04-08 11:54:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1));
|
2015-03-12 14:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
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);
|
2015-06-26 08:20:53 +00:00
|
|
|
Node* ret = graph()->NewNode(common()->Return(), phi, ephi, merge);
|
|
|
|
graph()->SetEnd(graph()->NewNode(common()->End(1), ret));
|
|
|
|
StrictMock<MockAdvancedReducerEditor> editor;
|
|
|
|
EXPECT_CALL(editor, Replace(merge, IsDead()));
|
|
|
|
Reduction const r = Reduce(&editor, ret);
|
|
|
|
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)));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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(
|
2015-12-10 09:03:30 +00:00
|
|
|
graph()->NewNode(common()->Select(rep, hint), input, input, input));
|
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);
|
[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
|
|
|
Reduction r = Reduce(select);
|
|
|
|
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);
|
[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
|
|
|
Reduction r = Reduce(select);
|
|
|
|
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);
|
2015-04-10 10:28:06 +00:00
|
|
|
Reduction r = Reduce(select);
|
|
|
|
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);
|
2015-04-10 10:28:06 +00:00
|
|
|
Reduction r = Reduce(select);
|
|
|
|
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));
|
2015-05-08 08:24:59 +00:00
|
|
|
Reduction r = Reduce(select);
|
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));
|
2015-05-08 08:24:59 +00:00
|
|
|
Reduction r = Reduce(select);
|
2015-04-08 11:54:53 +00:00
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat64Abs(p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, SelectToFloat32Max) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* select = graph()->NewNode(
|
|
|
|
common()->Select(MachineRepresentation::kFloat32), check, p1, p0);
|
2015-04-08 11:54:53 +00:00
|
|
|
Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Max);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat32Max(p1, p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, SelectToFloat64Max) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* select = graph()->NewNode(
|
|
|
|
common()->Select(MachineRepresentation::kFloat64), check, p1, p0);
|
2015-04-08 11:54:53 +00:00
|
|
|
Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Max);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat64Max(p1, p0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, SelectToFloat32Min) {
|
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* select = graph()->NewNode(
|
|
|
|
common()->Select(MachineRepresentation::kFloat32), check, p0, p1);
|
2015-04-08 11:54:53 +00:00
|
|
|
Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Min);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat32Min(p0, p1));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TEST_F(CommonOperatorReducerTest, SelectToFloat64Min) {
|
2015-03-12 14:07:28 +00:00
|
|
|
Node* p0 = Parameter(0);
|
|
|
|
Node* p1 = Parameter(1);
|
|
|
|
Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1);
|
2015-12-10 09:03:30 +00:00
|
|
|
Node* select = graph()->NewNode(
|
|
|
|
common()->Select(MachineRepresentation::kFloat64), check, p0, p1);
|
2015-04-08 11:54:53 +00:00
|
|
|
Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min);
|
|
|
|
ASSERT_TRUE(r.Changed());
|
|
|
|
EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1));
|
2015-03-12 14:07:28 +00:00
|
|
|
}
|
|
|
|
|
2014-12-22 13:06:34 +00:00
|
|
|
} // namespace compiler
|
|
|
|
} // namespace internal
|
|
|
|
} // namespace v8
|