| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/machine-operator-reducer.h" | 5 #include "src/compiler/machine-operator-reducer.h" |
| 6 | 6 |
| 7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
| 8 #include "src/base/division-by-constant.h" | 8 #include "src/base/division-by-constant.h" |
| 9 #include "src/base/ieee754.h" | 9 #include "src/base/ieee754.h" |
| 10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
| (...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 324 // Do some calculation to make a signalling NaN quiet. | 324 // Do some calculation to make a signalling NaN quiet. |
| 325 return ReplaceFloat32(m.right().Value() - m.right().Value()); | 325 return ReplaceFloat32(m.right().Value() - m.right().Value()); |
| 326 } | 326 } |
| 327 if (m.left().IsNaN()) { // NaN - x => NaN | 327 if (m.left().IsNaN()) { // NaN - x => NaN |
| 328 // Do some calculation to make a signalling NaN quiet. | 328 // Do some calculation to make a signalling NaN quiet. |
| 329 return ReplaceFloat32(m.left().Value() - m.left().Value()); | 329 return ReplaceFloat32(m.left().Value() - m.left().Value()); |
| 330 } | 330 } |
| 331 if (m.IsFoldable()) { // L - R => (L - R) | 331 if (m.IsFoldable()) { // L - R => (L - R) |
| 332 return ReplaceFloat32(m.left().Value() - m.right().Value()); | 332 return ReplaceFloat32(m.left().Value() - m.right().Value()); |
| 333 } | 333 } |
| 334 if (m.left().IsMinusZero()) { | 334 if (allow_signalling_nan_ && m.left().IsMinusZero()) { |
| 335 // -0.0 - round_down(-0.0 - R) => round_up(R) | 335 // -0.0 - round_down(-0.0 - R) => round_up(R) |
| 336 if (machine()->Float32RoundUp().IsSupported() && | 336 if (machine()->Float32RoundUp().IsSupported() && |
| 337 m.right().IsFloat32RoundDown()) { | 337 m.right().IsFloat32RoundDown()) { |
| 338 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat32Sub) { | 338 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat32Sub) { |
| 339 Float32BinopMatcher mright0(m.right().InputAt(0)); | 339 Float32BinopMatcher mright0(m.right().InputAt(0)); |
| 340 if (mright0.left().IsMinusZero()) { | 340 if (mright0.left().IsMinusZero()) { |
| 341 return Replace(graph()->NewNode(machine()->Float32RoundUp().op(), | 341 return Replace(graph()->NewNode(machine()->Float32RoundUp().op(), |
| 342 mright0.right().node())); | 342 mright0.right().node())); |
| 343 } | 343 } |
| 344 } | 344 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 371 // Do some calculation to make a signalling NaN quiet. | 371 // Do some calculation to make a signalling NaN quiet. |
| 372 return ReplaceFloat64(m.right().Value() - m.right().Value()); | 372 return ReplaceFloat64(m.right().Value() - m.right().Value()); |
| 373 } | 373 } |
| 374 if (m.left().IsNaN()) { // NaN - x => NaN | 374 if (m.left().IsNaN()) { // NaN - x => NaN |
| 375 // Do some calculation to make a signalling NaN quiet. | 375 // Do some calculation to make a signalling NaN quiet. |
| 376 return ReplaceFloat64(m.left().Value() - m.left().Value()); | 376 return ReplaceFloat64(m.left().Value() - m.left().Value()); |
| 377 } | 377 } |
| 378 if (m.IsFoldable()) { // L - R => (L - R) | 378 if (m.IsFoldable()) { // L - R => (L - R) |
| 379 return ReplaceFloat64(m.left().Value() - m.right().Value()); | 379 return ReplaceFloat64(m.left().Value() - m.right().Value()); |
| 380 } | 380 } |
| 381 if (m.left().IsMinusZero()) { | 381 if (allow_signalling_nan_ && m.left().IsMinusZero()) { |
| 382 // -0.0 - round_down(-0.0 - R) => round_up(R) | 382 // -0.0 - round_down(-0.0 - R) => round_up(R) |
| 383 if (machine()->Float64RoundUp().IsSupported() && | 383 if (machine()->Float64RoundUp().IsSupported() && |
| 384 m.right().IsFloat64RoundDown()) { | 384 m.right().IsFloat64RoundDown()) { |
| 385 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub) { | 385 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub) { |
| 386 Float64BinopMatcher mright0(m.right().InputAt(0)); | 386 Float64BinopMatcher mright0(m.right().InputAt(0)); |
| 387 if (mright0.left().IsMinusZero()) { | 387 if (mright0.left().IsMinusZero()) { |
| 388 return Replace(graph()->NewNode(machine()->Float64RoundUp().op(), | 388 return Replace(graph()->NewNode(machine()->Float64RoundUp().op(), |
| 389 mright0.right().node())); | 389 mright0.right().node())); |
| 390 } | 390 } |
| 391 } | 391 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 // Do some calculation to make a signalling NaN quiet. | 430 // Do some calculation to make a signalling NaN quiet. |
| 431 return ReplaceFloat64(m.right().Value() - m.right().Value()); | 431 return ReplaceFloat64(m.right().Value() - m.right().Value()); |
| 432 } | 432 } |
| 433 if (m.left().IsNaN()) { // NaN / x => NaN | 433 if (m.left().IsNaN()) { // NaN / x => NaN |
| 434 // Do some calculation to make a signalling NaN quiet. | 434 // Do some calculation to make a signalling NaN quiet. |
| 435 return ReplaceFloat64(m.left().Value() - m.left().Value()); | 435 return ReplaceFloat64(m.left().Value() - m.left().Value()); |
| 436 } | 436 } |
| 437 if (m.IsFoldable()) { // K / K => K | 437 if (m.IsFoldable()) { // K / K => K |
| 438 return ReplaceFloat64(m.left().Value() / m.right().Value()); | 438 return ReplaceFloat64(m.left().Value() / m.right().Value()); |
| 439 } | 439 } |
| 440 if (m.right().Is(-1)) { // x / -1.0 => -x | 440 if (allow_signalling_nan_ && m.right().Is(-1)) { // x / -1.0 => -x |
| 441 node->RemoveInput(1); | 441 node->RemoveInput(1); |
| 442 NodeProperties::ChangeOp(node, machine()->Float64Neg()); | 442 NodeProperties::ChangeOp(node, machine()->Float64Neg()); |
| 443 return Changed(node); | 443 return Changed(node); |
| 444 } | 444 } |
| 445 if (m.right().IsNormal() && m.right().IsPositiveOrNegativePowerOf2()) { | 445 if (m.right().IsNormal() && m.right().IsPositiveOrNegativePowerOf2()) { |
| 446 // All reciprocals of non-denormal powers of two can be represented | 446 // All reciprocals of non-denormal powers of two can be represented |
| 447 // exactly, so division by power of two can be reduced to | 447 // exactly, so division by power of two can be reduced to |
| 448 // multiplication by reciprocal, with the same result. | 448 // multiplication by reciprocal, with the same result. |
| 449 node->ReplaceInput(1, Float64Constant(1.0 / m.right().Value())); | 449 node->ReplaceInput(1, Float64Constant(1.0 / m.right().Value())); |
| 450 NodeProperties::ChangeOp(node, machine()->Float64Mul()); | 450 NodeProperties::ChangeOp(node, machine()->Float64Mul()); |
| (...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1423 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 1423 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
| 1424 return jsgraph()->machine(); | 1424 return jsgraph()->machine(); |
| 1425 } | 1425 } |
| 1426 | 1426 |
| 1427 | 1427 |
| 1428 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 1428 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
| 1429 | 1429 |
| 1430 } // namespace compiler | 1430 } // namespace compiler |
| 1431 } // namespace internal | 1431 } // namespace internal |
| 1432 } // namespace v8 | 1432 } // namespace v8 |
| OLD | NEW |