Chromium Code Reviews| Index: src/compiler/machine-operator-reducer.cc |
| diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc |
| index 04af8d4a431a9ca9c9e875a05380359084192d03..81a0b784fc9949b46805055f7de4746b43211dc4 100644 |
| --- a/src/compiler/machine-operator-reducer.cc |
| +++ b/src/compiler/machine-operator-reducer.cc |
| @@ -350,7 +350,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
| if (m.IsFoldable()) { // K * K => K |
| return ReplaceFloat64(m.left().Value() * m.right().Value()); |
| } |
| - break; |
| + return ReduceFloat52Mul(node); |
| } |
| case IrOpcode::kFloat64Div: { |
| Float64BinopMatcher m(node); |
| @@ -364,7 +364,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
| if (m.IsFoldable()) { // K / K => K |
| return ReplaceFloat64(m.left().Value() / m.right().Value()); |
| } |
| - break; |
| + return ReduceFloat52Div(node); |
| } |
| case IrOpcode::kFloat64Mod: { |
| Float64BinopMatcher m(node); |
| @@ -1080,6 +1080,88 @@ Reduction MachineOperatorReducer::ReduceFloat64Compare(Node* node) { |
| } |
| +Reduction MachineOperatorReducer::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); |
|
Benedikt Meurer
2015/11/25 20:09:10
The MachineOperatorReducer must not look at the ty
|
| + 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)); |
| + |
| + 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 MachineOperatorReducer::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<int64_t>(m.right().Value()); |
| + if (value != static_cast<int64_t>(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 RoundInt64ToFloat64 input should fit into 52bit integer |
| + if (range == nullptr || range->Min() < 0 || |
| + range->Max() > 0xFFFFFFFFFFFFFULL) { |
| + return NoChange(); |
| + } |
| + |
| + // The result should fit into 32bit word |
| + int64_t min = static_cast<int64_t>(range->Min()) / value; |
| + int64_t max = static_cast<int64_t>(range->Max()) / value; |
| + if (min < 0 || max > 0xFFFFFFFLL) { |
| + return NoChange(); |
| + } |
| + |
| + int64_t shift = WhichPowerOf2_64(static_cast<int64_t>(m.right().Value())); |
| + |
| + // Replace division with 64bit right shift |
| + Node* shr = |
| + graph()->NewNode(machine()->Word64Shr(), left, |
| + graph()->NewNode(common()->Int64Constant(shift))); |
| + |
| + Type* range_type = Type::Range(min, max, graph()->zone()); |
| + NodeProperties::SetType( |
| + shr, Type::Intersect(range_type, Type::Number(), graph()->zone())); |
| + |
| + Node* out = graph()->NewNode(machine()->RoundInt64ToFloat64(), shr); |
| + return Replace(out); |
| +} |
| + |
| + |
| CommonOperatorBuilder* MachineOperatorReducer::common() const { |
| return jsgraph()->common(); |
| } |