Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Unified Diff: src/compiler/machine-operator-reducer.cc

Issue 2647353007: [wasm] Fix constant folding with signalling NaN. (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/wasm/float-constant-folding.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/machine-operator-reducer.cc
diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc
index cc952ecc49bc5fc4476666ba72c8a6e83d945f79..7b28dfbc2746041f31465e187aa80dbab4464a0d 100644
--- a/src/compiler/machine-operator-reducer.cc
+++ b/src/compiler/machine-operator-reducer.cc
@@ -316,14 +316,13 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
}
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());
+ // - 0.0 to make a signalling NaN quiet.
+ return ReplaceFloat32(m.right().Value() - 0.0);
}
if (m.left().IsNaN()) { // NaN - x => NaN
- return Replace(m.left().node());
+ // - 0.0 to make a signalling NaN quiet.
+ return ReplaceFloat32(m.left().Value() - 0.0);
}
if (m.IsFoldable()) { // L - R => (L - R)
return ReplaceFloat32(m.left().Value() - m.right().Value());
@@ -350,7 +349,8 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
case IrOpcode::kFloat64Add: {
Float64BinopMatcher m(node);
if (m.right().IsNaN()) { // x + NaN => NaN
- return Replace(m.right().node());
+ // - 0.0 to make a signalling NaN quiet.
+ return ReplaceFloat64(m.right().Value() - 0.0);
}
if (m.IsFoldable()) { // K + K => K
return ReplaceFloat64(m.left().Value() + m.right().Value());
@@ -359,14 +359,13 @@ 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
titzer 2017/01/25 13:28:57 Can you leave a TODO here that we could still do t
- return Replace(m.right().node());
+ // - 0.0 to make a signalling NaN quiet.
+ return ReplaceFloat64(m.right().Value() - 0.0);
}
if (m.left().IsNaN()) { // NaN - x => NaN
- return Replace(m.left().node());
+ // - 0.0 to make a signalling NaN quiet.
+ return ReplaceFloat64(m.left().Value() - 0.0);
}
if (m.IsFoldable()) { // L - R => (L - R)
return ReplaceFloat64(m.left().Value() - m.right().Value());
@@ -398,9 +397,9 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
NodeProperties::ChangeOp(node, machine()->Float64Sub());
return Changed(node);
}
- if (m.right().Is(1)) return Replace(m.left().node()); // x * 1.0 => x
if (m.right().IsNaN()) { // x * NaN => NaN
- return Replace(m.right().node());
+ // - 0.0 to make a signalling NaN quiet.
+ return ReplaceFloat64(m.right().Value() - 0.0);
}
if (m.IsFoldable()) { // K * K => K
return ReplaceFloat64(m.left().Value() * m.right().Value());
@@ -414,12 +413,13 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
}
case IrOpcode::kFloat64Div: {
Float64BinopMatcher m(node);
- if (m.right().Is(1)) return Replace(m.left().node()); // x / 1.0 => x
if (m.right().IsNaN()) { // x / NaN => NaN
- return Replace(m.right().node());
+ // - 0.0 to make a signalling NaN quiet.
+ return ReplaceFloat64(m.right().Value() - 0.0);
}
if (m.left().IsNaN()) { // NaN / x => NaN
- return Replace(m.left().node());
+ // - 0.0 to make a signalling NaN quiet.
+ return ReplaceFloat64(m.left().Value() - 0.0);
}
if (m.IsFoldable()) { // K / K => K
return ReplaceFloat64(m.left().Value() / m.right().Value());
« no previous file with comments | « no previous file | test/mjsunit/wasm/float-constant-folding.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698