Index: src/compiler/machine-operator-reducer.cc |
diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc |
index 932854778eaeacf8c73b5f0bd439a83cedde7862..098e4d03e11493ba2bf79fd32f95d86d3347de1c 100644 |
--- a/src/compiler/machine-operator-reducer.cc |
+++ b/src/compiler/machine-operator-reducer.cc |
@@ -338,6 +338,9 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
} |
case IrOpcode::kFloat64Add: { |
Float64BinopMatcher m(node); |
+ if (m.right().IsNaN()) { // x + NaN => NaN |
+ return Replace(m.right().node()); |
+ } |
if (m.IsFoldable()) { // K + K => K |
return ReplaceFloat64(m.left().Value() + m.right().Value()); |
} |
@@ -345,6 +348,15 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
} |
case IrOpcode::kFloat64Sub: { |
Float64BinopMatcher m(node); |
+ if (m.right().Is(0) && (Double(m.right().Value()).Sign() > 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()) { // K - K => K |
return ReplaceFloat64(m.left().Value() - m.right().Value()); |
} |
@@ -377,6 +389,9 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
} |
case IrOpcode::kFloat64Mod: { |
Float64BinopMatcher m(node); |
+ if (m.right().Is(0)) { // x % 0 => NaN |
+ return ReplaceFloat64(base::OS::nan_value()); |
+ } |
if (m.right().IsNaN()) { // x % NaN => NaN |
return Replace(m.right().node()); |
} |