diff --git a/BUILD.gn b/BUILD.gn index 8d608fad12..d86b9d19a4 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -723,8 +723,6 @@ source_set("v8_base") { "src/compiler/ast-loop-assignment-analyzer.h", "src/compiler/basic-block-instrumentor.cc", "src/compiler/basic-block-instrumentor.h", - "src/compiler/binary-operator-reducer.cc", - "src/compiler/binary-operator-reducer.h", "src/compiler/branch-elimination.cc", "src/compiler/branch-elimination.h", "src/compiler/bytecode-graph-builder.cc", diff --git a/src/compiler/binary-operator-reducer.cc b/src/compiler/binary-operator-reducer.cc deleted file mode 100644 index 43d26d8884..0000000000 --- a/src/compiler/binary-operator-reducer.cc +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2015 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/binary-operator-reducer.h" - -#include - -#include "src/compiler/common-operator.h" -#include "src/compiler/graph.h" -#include "src/compiler/machine-operator.h" -#include "src/compiler/node.h" -#include "src/compiler/node-matchers.h" -#include "src/compiler/node-properties.h" -#include "src/types-inl.h" - -namespace v8 { -namespace internal { -namespace compiler { - -BinaryOperatorReducer::BinaryOperatorReducer(Editor* editor, Graph* graph, - CommonOperatorBuilder* common, - MachineOperatorBuilder* machine) - : AdvancedReducer(editor), - graph_(graph), - common_(common), - machine_(machine), - dead_(graph->NewNode(common->Dead())) {} - - -Reduction BinaryOperatorReducer::Reduce(Node* node) { - switch (node->opcode()) { - case IrOpcode::kFloat64Mul: - return ReduceFloat52Mul(node); - case IrOpcode::kFloat64Div: - return ReduceFloat52Div(node); - default: - break; - } - return NoChange(); -} - - -Reduction BinaryOperatorReducer::ReduceFloat52Mul(Node* node) { - if (!machine()->Is64()) return NoChange(); - - Float64BinopMatcher m(node); - if (!m.left().IsChangeInt32ToFloat64() || - !m.right().IsChangeInt32ToFloat64()) { - return NoChange(); - } - - Type* type = NodeProperties::GetType(node); - Type::RangeType* range = type->GetRange(); - - // JavaScript has 52 bit precision in multiplication - if (range == nullptr || range->Min() < 0.0 || - range->Max() > 0xFFFFFFFFFFFFFULL) { - return NoChange(); - } - - Node* mul = graph()->NewNode(machine()->Int64Mul(), m.left().InputAt(0), - m.right().InputAt(0)); - Revisit(mul); - - Type* range_type = Type::Range(range->Min(), range->Max(), graph()->zone()); - - // TODO(indutny): Is Type::Number() a proper thing here? It looks like - // every other place is using Type:Internal() for int64 values. - // Should we off-load range propagation to Typer? - NodeProperties::SetType( - mul, Type::Intersect(range_type, Type::Number(), graph()->zone())); - - Node* out = graph()->NewNode(machine()->RoundInt64ToFloat64(), mul); - return Replace(out); -} - - -Reduction BinaryOperatorReducer::ReduceFloat52Div(Node* node) { - if (!machine()->Is64()) return NoChange(); - - Float64BinopMatcher m(node); - if (!m.left().IsRoundInt64ToFloat64()) return NoChange(); - - // Right value should be positive... - if (!m.right().HasValue() || m.right().Value() <= 0) return NoChange(); - - // ...integer... - int64_t value = static_cast(m.right().Value()); - if (value != static_cast(m.right().Value())) return NoChange(); - - // ...and should be a power of two. - if (!base::bits::IsPowerOfTwo64(value)) return NoChange(); - - Node* left = m.left().InputAt(0); - Type::RangeType* range = NodeProperties::GetType(left)->GetRange(); - - // The result should fit into 32bit word - int64_t min = static_cast(range->Min()) / value; - int64_t max = static_cast(range->Max()) / value; - if (min < 0 || max > 0xFFFFFFFLL) { - return NoChange(); - } - - int64_t shift = WhichPowerOf2_64(static_cast(m.right().Value())); - - // Replace division with 64bit right shift - Node* shr = - graph()->NewNode(machine()->Word64Shr(), left, - graph()->NewNode(common()->Int64Constant(shift))); - Revisit(shr); - - Node* out = graph()->NewNode(machine()->RoundInt64ToFloat64(), shr); - return Replace(out); -} - - -Reduction BinaryOperatorReducer::Change(Node* node, Operator const* op, - Node* a) { - node->ReplaceInput(0, a); - node->TrimInputCount(1); - NodeProperties::ChangeOp(node, op); - return Changed(node); -} - -} // namespace compiler -} // namespace internal -} // namespace v8 diff --git a/src/compiler/binary-operator-reducer.h b/src/compiler/binary-operator-reducer.h deleted file mode 100644 index fd0d381c30..0000000000 --- a/src/compiler/binary-operator-reducer.h +++ /dev/null @@ -1,52 +0,0 @@ -// 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. - -#ifndef V8_COMPILER_BINARY_OPERATOR_REDUCER_H_ -#define V8_COMPILER_BINARY_OPERATOR_REDUCER_H_ - -#include "src/compiler/graph-reducer.h" - -namespace v8 { -namespace internal { -namespace compiler { - -// Forward declarations. -class CommonOperatorBuilder; -class Graph; -class MachineOperatorBuilder; -class Operator; - - -// Performs strength reduction on nodes that have common operators. -class BinaryOperatorReducer final : public AdvancedReducer { - public: - BinaryOperatorReducer(Editor* editor, Graph* graph, - CommonOperatorBuilder* common, - MachineOperatorBuilder* machine); - ~BinaryOperatorReducer() final {} - - Reduction Reduce(Node* node) final; - - private: - Reduction ReduceFloat52Mul(Node* node); - Reduction ReduceFloat52Div(Node* node); - - Reduction Change(Node* node, Operator const* op, Node* a); - - Graph* graph() const { return graph_; } - CommonOperatorBuilder* common() const { return common_; } - MachineOperatorBuilder* machine() const { return machine_; } - Node* dead() const { return dead_; } - - Graph* const graph_; - CommonOperatorBuilder* const common_; - MachineOperatorBuilder* const machine_; - Node* const dead_; -}; - -} // namespace compiler -} // namespace internal -} // namespace v8 - -#endif // V8_COMPILER_BINARY_OPERATOR_REDUCER_H_ diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc index 5951fb612a..c174da2f7f 100644 --- a/src/compiler/machine-operator-reducer.cc +++ b/src/compiler/machine-operator-reducer.cc @@ -648,7 +648,6 @@ Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) { Float64Matcher m(node->InputAt(0)); if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value())); if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0)); - if (m.IsRoundInt64ToFloat64()) return Replace(m.node()->InputAt(0)); if (m.IsPhi()) { Node* const phi = m.node(); DCHECK_EQ(kRepFloat64, RepresentationOf(OpParameter(phi))); diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index 06213c7af0..3325d9b064 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -12,7 +12,6 @@ #include "src/compiler/ast-graph-builder.h" #include "src/compiler/ast-loop-assignment-analyzer.h" #include "src/compiler/basic-block-instrumentor.h" -#include "src/compiler/binary-operator-reducer.h" #include "src/compiler/branch-elimination.h" #include "src/compiler/bytecode-graph-builder.h" #include "src/compiler/change-lowering.h" @@ -639,14 +638,11 @@ struct SimplifiedLoweringPhase { MachineOperatorReducer machine_reducer(data->jsgraph()); CommonOperatorReducer common_reducer(&graph_reducer, data->graph(), data->common(), data->machine()); - BinaryOperatorReducer binary_reducer(&graph_reducer, data->graph(), - data->common(), data->machine()); AddReducer(data, &graph_reducer, &dead_code_elimination); AddReducer(data, &graph_reducer, &simple_reducer); AddReducer(data, &graph_reducer, &value_numbering); AddReducer(data, &graph_reducer, &machine_reducer); AddReducer(data, &graph_reducer, &common_reducer); - AddReducer(data, &graph_reducer, &binary_reducer); graph_reducer.ReduceGraph(); } }; diff --git a/test/unittests/compiler/binary-operator-reducer-unittest.cc b/test/unittests/compiler/binary-operator-reducer-unittest.cc deleted file mode 100644 index 5d223446e2..0000000000 --- a/test/unittests/compiler/binary-operator-reducer-unittest.cc +++ /dev/null @@ -1,94 +0,0 @@ -// 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/binary-operator-reducer.h" -#include "src/compiler/common-operator.h" -#include "src/compiler/machine-operator.h" -#include "src/compiler/machine-type.h" -#include "src/compiler/node-properties.h" -#include "src/compiler/operator.h" -#include "src/compiler/simplified-operator.h" -#include "src/types-inl.h" -#include "test/unittests/compiler/graph-reducer-unittest.h" -#include "test/unittests/compiler/graph-unittest.h" -#include "test/unittests/compiler/node-test-utils.h" - -using testing::StrictMock; - -namespace v8 { -namespace internal { -namespace compiler { - -class BinaryOperatorReducerTest : public TypedGraphTest { - public: - explicit BinaryOperatorReducerTest(int num_parameters = 1) - : TypedGraphTest(num_parameters), machine_(zone()), simplified_(zone()) {} - ~BinaryOperatorReducerTest() override {} - - protected: - Reduction Reduce(AdvancedReducer::Editor* editor, Node* node) { - BinaryOperatorReducer reducer(editor, graph(), common(), machine()); - return reducer.Reduce(node); - } - - Reduction Reduce(Node* node) { - StrictMock editor; - return Reduce(&editor, node); - } - - MachineOperatorBuilder* machine() { return &machine_; } - SimplifiedOperatorBuilder* simplified() { return &simplified_; } - - private: - MachineOperatorBuilder machine_; - SimplifiedOperatorBuilder simplified_; -}; - - -TEST_F(BinaryOperatorReducerTest, Div52OfMul52) { - // This reduction applies only to 64bit arch - if (!machine()->Is64()) return; - - Node* p0 = Parameter(0); - Node* p1 = Parameter(1); - Node* t0 = graph()->NewNode(machine()->ChangeInt32ToFloat64(), p0); - Node* t1 = graph()->NewNode(machine()->ChangeInt32ToFloat64(), p1); - - Type* mul_range = Type::Range(0x0, 0xFFFFFFFFFFFFFULL, graph()->zone()); - Node* mul = graph()->NewNode(machine()->Float64Mul(), t0, t1); - NodeProperties::SetType( - mul, Type::Intersect(mul_range, Type::Number(), graph()->zone())); - - Node* mul_replacement; - auto mul_matcher = IsInt64Mul(p0, p1); - { - StrictMock editor; - - EXPECT_CALL(editor, Revisit(mul_matcher)); - - Reduction r = Reduce(&editor, mul); - ASSERT_TRUE(r.Changed()); - mul_replacement = r.replacement(); - EXPECT_THAT(mul_replacement, IsRoundInt64ToFloat64(mul_matcher)); - } - - { - StrictMock editor; - - Node* power = Float64Constant(0x4000000); - Node* div = - graph()->NewNode(machine()->Float64Div(), mul_replacement, power); - - auto shr_matcher = IsWord64Shr(mul_matcher, IsInt64Constant(26)); - EXPECT_CALL(editor, Revisit(shr_matcher)); - - Reduction r = Reduce(&editor, div); - ASSERT_TRUE(r.Changed()); - EXPECT_THAT(r.replacement(), IsRoundInt64ToFloat64(shr_matcher)); - } -} - -} // namespace compiler -} // namespace internal -} // namespace v8 diff --git a/test/unittests/compiler/machine-operator-reducer-unittest.cc b/test/unittests/compiler/machine-operator-reducer-unittest.cc index 6f7ed3aca4..7ffdfe5bf0 100644 --- a/test/unittests/compiler/machine-operator-reducer-unittest.cc +++ b/test/unittests/compiler/machine-operator-reducer-unittest.cc @@ -1646,18 +1646,6 @@ TEST_F(MachineOperatorReducerTest, StoreRepWord16WithWord32SarAndWord32Shl) { } } - -TEST_F(MachineOperatorReducerTest, RoundPlusTruncate) { - Node* p0 = Parameter(0); - Node* t0 = graph()->NewNode(machine()->RoundInt64ToFloat64(), p0); - Node* t1 = graph()->NewNode( - machine()->TruncateFloat64ToInt32(TruncationMode::kJavaScript), t0); - - Reduction r = Reduce(t1); - ASSERT_TRUE(r.Changed()); - EXPECT_THAT(r.replacement(), p0); -} - } // namespace compiler } // namespace internal } // namespace v8 diff --git a/test/unittests/compiler/node-test-utils.cc b/test/unittests/compiler/node-test-utils.cc index 713a4bc440..7103413b88 100644 --- a/test/unittests/compiler/node-test-utils.cc +++ b/test/unittests/compiler/node-test-utils.cc @@ -2559,7 +2559,6 @@ IS_BINOP_MATCHER(Word64And) IS_BINOP_MATCHER(Word64Or) IS_BINOP_MATCHER(Word64Sar) IS_BINOP_MATCHER(Word64Shl) -IS_BINOP_MATCHER(Word64Shr) IS_BINOP_MATCHER(Word64Equal) IS_BINOP_MATCHER(Int32AddWithOverflow) IS_BINOP_MATCHER(Int32Add) @@ -2571,7 +2570,6 @@ IS_BINOP_MATCHER(Uint32LessThan) IS_BINOP_MATCHER(Uint32LessThanOrEqual) IS_BINOP_MATCHER(Int64Add) IS_BINOP_MATCHER(Int64Sub) -IS_BINOP_MATCHER(Int64Mul) IS_BINOP_MATCHER(JSAdd) IS_BINOP_MATCHER(Float32Max) IS_BINOP_MATCHER(Float32Min) @@ -2600,7 +2598,6 @@ IS_UNOP_MATCHER(ChangeUint32ToUint64) IS_UNOP_MATCHER(TruncateFloat64ToFloat32) IS_UNOP_MATCHER(TruncateFloat64ToInt32) IS_UNOP_MATCHER(TruncateInt64ToInt32) -IS_UNOP_MATCHER(RoundInt64ToFloat64) IS_UNOP_MATCHER(Float32Abs) IS_UNOP_MATCHER(Float64Abs) IS_UNOP_MATCHER(Float64Sqrt) diff --git a/test/unittests/compiler/node-test-utils.h b/test/unittests/compiler/node-test-utils.h index 1a28fe3e49..02ee82e202 100644 --- a/test/unittests/compiler/node-test-utils.h +++ b/test/unittests/compiler/node-test-utils.h @@ -280,8 +280,6 @@ Matcher IsWord64Or(const Matcher& lhs_matcher, const Matcher& rhs_matcher); Matcher IsWord64Shl(const Matcher& lhs_matcher, const Matcher& rhs_matcher); -Matcher IsWord64Shr(const Matcher& lhs_matcher, - const Matcher& rhs_matcher); Matcher IsWord64Sar(const Matcher& lhs_matcher, const Matcher& rhs_matcher); Matcher IsWord64Equal(const Matcher& lhs_matcher, @@ -306,8 +304,6 @@ Matcher IsInt64Add(const Matcher& lhs_matcher, const Matcher& rhs_matcher); Matcher IsInt64Sub(const Matcher& lhs_matcher, const Matcher& rhs_matcher); -Matcher IsInt64Mul(const Matcher& lhs_matcher, - const Matcher& rhs_matcher); Matcher IsJSAdd(const Matcher& lhs_matcher, const Matcher& rhs_matcher); Matcher IsChangeFloat64ToInt32(const Matcher& input_matcher); @@ -319,7 +315,6 @@ Matcher IsChangeUint32ToUint64(const Matcher& input_matcher); Matcher IsTruncateFloat64ToFloat32(const Matcher& input_matcher); Matcher IsTruncateFloat64ToInt32(const Matcher& input_matcher); Matcher IsTruncateInt64ToInt32(const Matcher& input_matcher); -Matcher IsRoundInt64ToFloat64(const Matcher& input_matcher); Matcher IsFloat32Max(const Matcher& lhs_matcher, const Matcher& rhs_matcher); Matcher IsFloat32Min(const Matcher& lhs_matcher, diff --git a/test/unittests/unittests.gyp b/test/unittests/unittests.gyp index ca625f0fb2..362aebc8a9 100644 --- a/test/unittests/unittests.gyp +++ b/test/unittests/unittests.gyp @@ -44,7 +44,6 @@ 'base/utils/random-number-generator-unittest.cc', 'cancelable-tasks-unittest.cc', 'char-predicates-unittest.cc', - 'compiler/binary-operator-reducer-unittest.cc', 'compiler/branch-elimination-unittest.cc', 'compiler/bytecode-graph-builder-unittest.cc', 'compiler/change-lowering-unittest.cc', diff --git a/tools/gyp/v8.gyp b/tools/gyp/v8.gyp index 26e844d32a..2b729d8e38 100644 --- a/tools/gyp/v8.gyp +++ b/tools/gyp/v8.gyp @@ -461,8 +461,6 @@ '../../src/compiler/ast-loop-assignment-analyzer.h', '../../src/compiler/basic-block-instrumentor.cc', '../../src/compiler/basic-block-instrumentor.h', - '../../src/compiler/binary-operator-reducer.cc', - '../../src/compiler/binary-operator-reducer.h', '../../src/compiler/branch-elimination.cc', '../../src/compiler/branch-elimination.h', '../../src/compiler/bytecode-graph-builder.cc',