| Index: src/compiler/common-operator-reducer.cc
|
| diff --git a/src/compiler/common-operator-reducer.cc b/src/compiler/common-operator-reducer.cc
|
| index c66cce0538794f8019fba27966bc3181b088113d..8001961d37215c8b57ddaac7ea0ebbc5e6a38d7a 100644
|
| --- a/src/compiler/common-operator-reducer.cc
|
| +++ b/src/compiler/common-operator-reducer.cc
|
| @@ -55,21 +55,39 @@ Reduction CommonOperatorReducer::ReducePhi(Node* node) {
|
| if (matcher.Matched()) {
|
| if (matcher.IfTrue() == merge->InputAt(1)) std::swap(vtrue, vfalse);
|
| Node* cond = matcher.Branch()->InputAt(0);
|
| - if (cond->opcode() == IrOpcode::kFloat64LessThan) {
|
| - if (cond->InputAt(0) == vtrue && cond->InputAt(1) == vfalse &&
|
| + if (cond->opcode() == IrOpcode::kFloat32LessThan) {
|
| + Float32BinopMatcher mcond(cond);
|
| + if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) &&
|
| + vfalse->opcode() == IrOpcode::kFloat32Sub &&
|
| + machine()->HasFloat32Abs()) {
|
| + Float32BinopMatcher mvfalse(vfalse);
|
| + if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) {
|
| + return Change(node, machine()->Float32Abs(), vtrue);
|
| + }
|
| + }
|
| + if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) &&
|
| + machine()->HasFloat32Min()) {
|
| + return Change(node, machine()->Float32Min(), vtrue, vfalse);
|
| + } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) &&
|
| + machine()->HasFloat32Max()) {
|
| + return Change(node, machine()->Float32Max(), vtrue, vfalse);
|
| + }
|
| + } else if (cond->opcode() == IrOpcode::kFloat64LessThan) {
|
| + Float64BinopMatcher mcond(cond);
|
| + if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) &&
|
| + vfalse->opcode() == IrOpcode::kFloat64Sub &&
|
| + machine()->HasFloat64Abs()) {
|
| + Float64BinopMatcher mvfalse(vfalse);
|
| + if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) {
|
| + return Change(node, machine()->Float64Abs(), vtrue);
|
| + }
|
| + }
|
| + if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) &&
|
| machine()->HasFloat64Min()) {
|
| - node->set_op(machine()->Float64Min());
|
| - node->ReplaceInput(0, vtrue);
|
| - node->ReplaceInput(1, vfalse);
|
| - node->TrimInputCount(2);
|
| - return Changed(node);
|
| - } else if (cond->InputAt(0) == vfalse && cond->InputAt(1) == vtrue &&
|
| + return Change(node, machine()->Float64Min(), vtrue, vfalse);
|
| + } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) &&
|
| machine()->HasFloat64Max()) {
|
| - node->set_op(machine()->Float64Max());
|
| - node->ReplaceInput(0, vtrue);
|
| - node->ReplaceInput(1, vfalse);
|
| - node->TrimInputCount(2);
|
| - return Changed(node);
|
| + return Change(node, machine()->Float64Max(), vtrue, vfalse);
|
| }
|
| }
|
| }
|
| @@ -91,27 +109,64 @@ Reduction CommonOperatorReducer::ReduceSelect(Node* node) {
|
| Node* vtrue = NodeProperties::GetValueInput(node, 1);
|
| Node* vfalse = NodeProperties::GetValueInput(node, 2);
|
| if (vtrue == vfalse) return Replace(vtrue);
|
| - if (cond->opcode() == IrOpcode::kFloat64LessThan) {
|
| - if (cond->InputAt(0) == vtrue && cond->InputAt(1) == vfalse &&
|
| + if (cond->opcode() == IrOpcode::kFloat32LessThan) {
|
| + Float32BinopMatcher mcond(cond);
|
| + if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) &&
|
| + vfalse->opcode() == IrOpcode::kFloat32Sub &&
|
| + machine()->HasFloat32Abs()) {
|
| + Float32BinopMatcher mvfalse(vfalse);
|
| + if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) {
|
| + return Change(node, machine()->Float32Abs(), vtrue);
|
| + }
|
| + }
|
| + if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) &&
|
| + machine()->HasFloat32Min()) {
|
| + return Change(node, machine()->Float32Min(), vtrue, vfalse);
|
| + } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) &&
|
| + machine()->HasFloat32Max()) {
|
| + return Change(node, machine()->Float32Max(), vtrue, vfalse);
|
| + }
|
| + } else if (cond->opcode() == IrOpcode::kFloat64LessThan) {
|
| + Float64BinopMatcher mcond(cond);
|
| + if (mcond.left().Is(0.0) && mcond.right().Equals(vtrue) &&
|
| + vfalse->opcode() == IrOpcode::kFloat64Sub &&
|
| + machine()->HasFloat64Abs()) {
|
| + Float64BinopMatcher mvfalse(vfalse);
|
| + if (mvfalse.left().IsZero() && mvfalse.right().Equals(vtrue)) {
|
| + return Change(node, machine()->Float64Abs(), vtrue);
|
| + }
|
| + }
|
| + if (mcond.left().Equals(vtrue) && mcond.right().Equals(vfalse) &&
|
| machine()->HasFloat64Min()) {
|
| - node->set_op(machine()->Float64Min());
|
| - node->ReplaceInput(0, vtrue);
|
| - node->ReplaceInput(1, vfalse);
|
| - node->TrimInputCount(2);
|
| - return Changed(node);
|
| - } else if (cond->InputAt(0) == vfalse && cond->InputAt(1) == vtrue &&
|
| + return Change(node, machine()->Float64Min(), vtrue, vfalse);
|
| + } else if (mcond.left().Equals(vfalse) && mcond.right().Equals(vtrue) &&
|
| machine()->HasFloat64Max()) {
|
| - node->set_op(machine()->Float64Max());
|
| - node->ReplaceInput(0, vtrue);
|
| - node->ReplaceInput(1, vfalse);
|
| - node->TrimInputCount(2);
|
| - return Changed(node);
|
| + return Change(node, machine()->Float64Max(), vtrue, vfalse);
|
| }
|
| }
|
| return NoChange();
|
| }
|
|
|
|
|
| +Reduction CommonOperatorReducer::Change(Node* node, Operator const* op,
|
| + Node* a) {
|
| + node->set_op(op);
|
| + node->ReplaceInput(0, a);
|
| + node->TrimInputCount(1);
|
| + return Changed(node);
|
| +}
|
| +
|
| +
|
| +Reduction CommonOperatorReducer::Change(Node* node, Operator const* op, Node* a,
|
| + Node* b) {
|
| + node->set_op(op);
|
| + node->ReplaceInput(0, a);
|
| + node->ReplaceInput(1, b);
|
| + node->TrimInputCount(2);
|
| + return Changed(node);
|
| +}
|
| +
|
| +
|
| CommonOperatorBuilder* CommonOperatorReducer::common() const {
|
| return jsgraph()->common();
|
| }
|
|
|