Commit 89ee8ec1 authored by Jacob.Bramley@arm.com's avatar Jacob.Bramley@arm.com

[turbofan] add some simplifications in the machine operator reducer

Simplify the '+', '-' and '%' operators with some basic constants (0, 1 or NaN).

R=titzer@chromium.org, bmeurer@chromium.org, titzer@google.com

BUG=

Review URL: https://codereview.chromium.org/599383002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24270 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 40a9b436
...@@ -352,6 +352,9 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -352,6 +352,9 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
} }
case IrOpcode::kFloat64Add: { case IrOpcode::kFloat64Add: {
Float64BinopMatcher m(node); Float64BinopMatcher m(node);
if (m.right().IsNaN()) { // x + NaN => NaN
return Replace(m.right().node());
}
if (m.IsFoldable()) { // K + K => K if (m.IsFoldable()) { // K + K => K
return ReplaceFloat64(m.left().Value() + m.right().Value()); return ReplaceFloat64(m.left().Value() + m.right().Value());
} }
...@@ -359,6 +362,15 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -359,6 +362,15 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
} }
case IrOpcode::kFloat64Sub: { case IrOpcode::kFloat64Sub: {
Float64BinopMatcher m(node); 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 if (m.IsFoldable()) { // K - K => K
return ReplaceFloat64(m.left().Value() - m.right().Value()); return ReplaceFloat64(m.left().Value() - m.right().Value());
} }
...@@ -391,6 +403,9 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { ...@@ -391,6 +403,9 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
} }
case IrOpcode::kFloat64Mod: { case IrOpcode::kFloat64Mod: {
Float64BinopMatcher m(node); Float64BinopMatcher m(node);
if (m.right().Is(0)) { // x % 0 => NaN
return ReplaceFloat64(base::OS::nan_value());
}
if (m.right().IsNaN()) { // x % NaN => NaN if (m.right().IsNaN()) { // x % NaN => NaN
return Replace(m.right().node()); return Replace(m.right().node());
} }
......
...@@ -687,9 +687,9 @@ static void CheckNans(ReducerTester* R) { ...@@ -687,9 +687,9 @@ static void CheckNans(ReducerTester* R) {
pr != nans.end(); ++pr) { pr != nans.end(); ++pr) {
Node* nan1 = R->Constant<double>(*pl); Node* nan1 = R->Constant<double>(*pl);
Node* nan2 = R->Constant<double>(*pr); Node* nan2 = R->Constant<double>(*pr);
R->CheckBinop(nan1, x, nan1); // x % NaN => NaN R->CheckBinop(nan1, x, nan1); // x op NaN => NaN
R->CheckBinop(nan1, nan1, x); // NaN % x => NaN R->CheckBinop(nan1, nan1, x); // NaN op x => NaN
R->CheckBinop(nan1, nan2, nan1); // NaN % NaN => NaN R->CheckBinop(nan1, nan2, nan1); // NaN op NaN => NaN
} }
} }
} }
...@@ -706,8 +706,15 @@ TEST(ReduceFloat64Add) { ...@@ -706,8 +706,15 @@ TEST(ReduceFloat64Add) {
} }
} }
FOR_FLOAT64_INPUTS(i) { R.CheckPutConstantOnRight(*i); } FOR_FLOAT64_INPUTS(i) {
// TODO(titzer): CheckNans(&R); Double tmp(*i);
if (!tmp.IsSpecial() || tmp.IsInfinite()) {
// Don't check NaNs as they are reduced more.
R.CheckPutConstantOnRight(*i);
}
}
CheckNans(&R);
} }
...@@ -721,7 +728,13 @@ TEST(ReduceFloat64Sub) { ...@@ -721,7 +728,13 @@ TEST(ReduceFloat64Sub) {
R.CheckFoldBinop<double>(x - y, x, y); R.CheckFoldBinop<double>(x - y, x, y);
} }
} }
// TODO(titzer): CheckNans(&R);
Node* zero = R.Constant<double>(0.0);
Node* x = R.Parameter();
R.CheckBinop(x, x, zero); // x - 0.0 => x
CheckNans(&R);
} }
...@@ -783,6 +796,11 @@ TEST(ReduceFloat64Mod) { ...@@ -783,6 +796,11 @@ TEST(ReduceFloat64Mod) {
} }
} }
Node* x = R.Parameter();
Node* zero = R.Constant<double>(0.0);
R.CheckFoldBinop<double>(v8::base::OS::nan_value(), x, zero);
CheckNans(&R); CheckNans(&R);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment