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

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

Issue 2226663002: [turbofan] Lower "-0.0 - x" in the MachineOperatorReducer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 4 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/cctest/compiler/test-machine-operator-reducer.cc » ('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 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: {
« no previous file with comments | « no previous file | test/cctest/compiler/test-machine-operator-reducer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698