Index: src/compiler/machine-operator-reducer.cc |
diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc |
index 55c93c2c13d826876be71fa9c60b36e14a9f8156..c1c58fe90404b75bc235607fa5ccf625b5e0ba0f 100644 |
--- a/src/compiler/machine-operator-reducer.cc |
+++ b/src/compiler/machine-operator-reducer.cc |
@@ -314,6 +314,39 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
if (m.LeftEqualsRight()) return ReplaceBool(true); // x <= x => true |
break; |
} |
+ case IrOpcode::kFloat32Sub: { |
+ Float32BinopMatcher m(node); |
+ if (m.right().Is(0) && (copysign(1.0, m.right().Value()) > 0)) { |
+ return Replace(m.left().node()); // x - 0 => x |
+ } |
+ if (m.right().IsNaN()) { // x - NaN => NaN |
+ return Replace(m.right().node()); |
+ } |
+ if (m.left().IsNaN()) { // NaN - x => NaN |
+ return Replace(m.left().node()); |
+ } |
+ if (m.IsFoldable()) { // L - R => (L - R) |
+ return ReplaceFloat32(m.left().Value() - m.right().Value()); |
+ } |
+ if (m.left().IsMinusZero()) { |
+ // -0.0 - round_down(-0.0 - R) => round_up(R) |
+ if (machine()->Float32RoundUp().IsSupported() && |
+ m.right().IsFloat32RoundDown()) { |
+ if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat32Sub) { |
+ Float32BinopMatcher mright0(m.right().InputAt(0)); |
+ if (mright0.left().IsMinusZero()) { |
+ return Replace(graph()->NewNode(machine()->Float32RoundUp().op(), |
+ mright0.right().node())); |
+ } |
+ } |
+ } |
+ // -0.0 - R => -R |
+ node->RemoveInput(0); |
+ NodeProperties::ChangeOp(node, machine()->Float32Neg()); |
+ return Changed(node); |
+ } |
+ break; |
+ } |
case IrOpcode::kFloat64Add: { |
Float64BinopMatcher m(node); |
if (m.right().IsNaN()) { // x + NaN => NaN |
@@ -335,9 +368,26 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
if (m.left().IsNaN()) { // NaN - x => NaN |
return Replace(m.left().node()); |
} |
- if (m.IsFoldable()) { // K - K => K |
+ if (m.IsFoldable()) { // L - R => (L - R) |
return ReplaceFloat64(m.left().Value() - m.right().Value()); |
} |
+ if (m.left().IsMinusZero()) { |
+ // -0.0 - round_down(-0.0 - R) => round_up(R) |
+ if (machine()->Float64RoundUp().IsSupported() && |
+ m.right().IsFloat64RoundDown()) { |
+ if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub) { |
+ Float64BinopMatcher mright0(m.right().InputAt(0)); |
+ if (mright0.left().IsMinusZero()) { |
+ return Replace(graph()->NewNode(machine()->Float64RoundUp().op(), |
+ mright0.right().node())); |
+ } |
+ } |
+ } |
+ // -0.0 - R => -R |
+ node->RemoveInput(0); |
+ NodeProperties::ChangeOp(node, machine()->Float64Neg()); |
+ return Changed(node); |
+ } |
break; |
} |
case IrOpcode::kFloat64Mul: { |