Chromium Code Reviews| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 if (m.left().Is(0)) return ReplaceBool(true); // 0 <= x => true | 309 if (m.left().Is(0)) return ReplaceBool(true); // 0 <= x => true |
| 310 if (m.right().Is(kMaxUInt32)) return ReplaceBool(true); // x <= M => true | 310 if (m.right().Is(kMaxUInt32)) return ReplaceBool(true); // x <= M => true |
| 311 if (m.IsFoldable()) { // K <= K => K | 311 if (m.IsFoldable()) { // K <= K => K |
| 312 return ReplaceBool(m.left().Value() <= m.right().Value()); | 312 return ReplaceBool(m.left().Value() <= m.right().Value()); |
| 313 } | 313 } |
| 314 if (m.LeftEqualsRight()) return ReplaceBool(true); // x <= x => true | 314 if (m.LeftEqualsRight()) return ReplaceBool(true); // x <= x => true |
| 315 break; | 315 break; |
| 316 } | 316 } |
| 317 case IrOpcode::kFloat32Sub: { | 317 case IrOpcode::kFloat32Sub: { |
| 318 Float32BinopMatcher m(node); | 318 Float32BinopMatcher m(node); |
| 319 if (m.right().Is(0) && (copysign(1.0, m.right().Value()) > 0)) { | 319 // TODO(ahaas): We could do x - 0.0 = x if we knew that x is not an sNaN. |
| 320 return Replace(m.left().node()); // x - 0 => x | |
| 321 } | |
| 322 if (m.right().IsNaN()) { // x - NaN => NaN | 320 if (m.right().IsNaN()) { // x - NaN => NaN |
| 323 return Replace(m.right().node()); | 321 // Do some calculation to make a signalling NaN quiet. |
| 322 return ReplaceFloat32(m.right().Value() - m.right().Value()); | |
| 324 } | 323 } |
| 325 if (m.left().IsNaN()) { // NaN - x => NaN | 324 if (m.left().IsNaN()) { // NaN - x => NaN |
| 326 return Replace(m.left().node()); | 325 // Do some calculation to make a signalling NaN quiet. |
|
titzer
2017/01/25 15:30:54
Would it be correct to just return the canonical q
| |
| 326 return ReplaceFloat32(m.left().Value() - m.left().Value()); | |
| 327 } | 327 } |
| 328 if (m.IsFoldable()) { // L - R => (L - R) | 328 if (m.IsFoldable()) { // L - R => (L - R) |
| 329 return ReplaceFloat32(m.left().Value() - m.right().Value()); | 329 return ReplaceFloat32(m.left().Value() - m.right().Value()); |
| 330 } | 330 } |
| 331 if (m.left().IsMinusZero()) { | 331 if (m.left().IsMinusZero()) { |
| 332 // -0.0 - round_down(-0.0 - R) => round_up(R) | 332 // -0.0 - round_down(-0.0 - R) => round_up(R) |
| 333 if (machine()->Float32RoundUp().IsSupported() && | 333 if (machine()->Float32RoundUp().IsSupported() && |
| 334 m.right().IsFloat32RoundDown()) { | 334 m.right().IsFloat32RoundDown()) { |
| 335 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat32Sub) { | 335 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat32Sub) { |
| 336 Float32BinopMatcher mright0(m.right().InputAt(0)); | 336 Float32BinopMatcher mright0(m.right().InputAt(0)); |
| 337 if (mright0.left().IsMinusZero()) { | 337 if (mright0.left().IsMinusZero()) { |
| 338 return Replace(graph()->NewNode(machine()->Float32RoundUp().op(), | 338 return Replace(graph()->NewNode(machine()->Float32RoundUp().op(), |
| 339 mright0.right().node())); | 339 mright0.right().node())); |
| 340 } | 340 } |
| 341 } | 341 } |
| 342 } | 342 } |
| 343 // -0.0 - R => -R | 343 // -0.0 - R => -R |
| 344 node->RemoveInput(0); | 344 node->RemoveInput(0); |
| 345 NodeProperties::ChangeOp(node, machine()->Float32Neg()); | 345 NodeProperties::ChangeOp(node, machine()->Float32Neg()); |
| 346 return Changed(node); | 346 return Changed(node); |
| 347 } | 347 } |
| 348 break; | 348 break; |
| 349 } | 349 } |
| 350 case IrOpcode::kFloat64Add: { | 350 case IrOpcode::kFloat64Add: { |
| 351 Float64BinopMatcher m(node); | 351 Float64BinopMatcher m(node); |
| 352 if (m.right().IsNaN()) { // x + NaN => NaN | 352 if (m.right().IsNaN()) { // x + NaN => NaN |
| 353 return Replace(m.right().node()); | 353 // Do some calculation to make a signalling NaN quiet. |
| 354 return ReplaceFloat64(m.right().Value() - m.right().Value()); | |
| 354 } | 355 } |
| 355 if (m.IsFoldable()) { // K + K => K | 356 if (m.IsFoldable()) { // K + K => K |
| 356 return ReplaceFloat64(m.left().Value() + m.right().Value()); | 357 return ReplaceFloat64(m.left().Value() + m.right().Value()); |
| 357 } | 358 } |
| 358 break; | 359 break; |
| 359 } | 360 } |
| 360 case IrOpcode::kFloat64Sub: { | 361 case IrOpcode::kFloat64Sub: { |
| 361 Float64BinopMatcher m(node); | 362 Float64BinopMatcher m(node); |
| 362 if (m.right().Is(0) && (Double(m.right().Value()).Sign() > 0)) { | 363 // TODO(ahaas): We could do x - 0.0 = x if we knew that x is not an sNaN. |
| 363 return Replace(m.left().node()); // x - 0 => x | |
| 364 } | |
| 365 if (m.right().IsNaN()) { // x - NaN => NaN | 364 if (m.right().IsNaN()) { // x - NaN => NaN |
| 366 return Replace(m.right().node()); | 365 // Do some calculation to make a signalling NaN quiet. |
| 366 return ReplaceFloat64(m.right().Value() - m.right().Value()); | |
| 367 } | 367 } |
| 368 if (m.left().IsNaN()) { // NaN - x => NaN | 368 if (m.left().IsNaN()) { // NaN - x => NaN |
| 369 return Replace(m.left().node()); | 369 // Do some calculation to make a signalling NaN quiet. |
| 370 return ReplaceFloat64(m.left().Value() - m.left().Value()); | |
| 370 } | 371 } |
| 371 if (m.IsFoldable()) { // L - R => (L - R) | 372 if (m.IsFoldable()) { // L - R => (L - R) |
| 372 return ReplaceFloat64(m.left().Value() - m.right().Value()); | 373 return ReplaceFloat64(m.left().Value() - m.right().Value()); |
| 373 } | 374 } |
| 374 if (m.left().IsMinusZero()) { | 375 if (m.left().IsMinusZero()) { |
| 375 // -0.0 - round_down(-0.0 - R) => round_up(R) | 376 // -0.0 - round_down(-0.0 - R) => round_up(R) |
| 376 if (machine()->Float64RoundUp().IsSupported() && | 377 if (machine()->Float64RoundUp().IsSupported() && |
| 377 m.right().IsFloat64RoundDown()) { | 378 m.right().IsFloat64RoundDown()) { |
| 378 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub) { | 379 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub) { |
| 379 Float64BinopMatcher mright0(m.right().InputAt(0)); | 380 Float64BinopMatcher mright0(m.right().InputAt(0)); |
| 380 if (mright0.left().IsMinusZero()) { | 381 if (mright0.left().IsMinusZero()) { |
| 381 return Replace(graph()->NewNode(machine()->Float64RoundUp().op(), | 382 return Replace(graph()->NewNode(machine()->Float64RoundUp().op(), |
| 382 mright0.right().node())); | 383 mright0.right().node())); |
| 383 } | 384 } |
| 384 } | 385 } |
| 385 } | 386 } |
| 386 // -0.0 - R => -R | 387 // -0.0 - R => -R |
| 387 node->RemoveInput(0); | 388 node->RemoveInput(0); |
| 388 NodeProperties::ChangeOp(node, machine()->Float64Neg()); | 389 NodeProperties::ChangeOp(node, machine()->Float64Neg()); |
| 389 return Changed(node); | 390 return Changed(node); |
| 390 } | 391 } |
| 391 break; | 392 break; |
| 392 } | 393 } |
| 393 case IrOpcode::kFloat64Mul: { | 394 case IrOpcode::kFloat64Mul: { |
| 394 Float64BinopMatcher m(node); | 395 Float64BinopMatcher m(node); |
| 396 // TODO(ahaas): We could do x * 1.0 = x if we knew that x is not an sNaN. | |
| 395 if (m.right().Is(-1)) { // x * -1.0 => -0.0 - x | 397 if (m.right().Is(-1)) { // x * -1.0 => -0.0 - x |
| 396 node->ReplaceInput(0, Float64Constant(-0.0)); | 398 node->ReplaceInput(0, Float64Constant(-0.0)); |
| 397 node->ReplaceInput(1, m.left().node()); | 399 node->ReplaceInput(1, m.left().node()); |
| 398 NodeProperties::ChangeOp(node, machine()->Float64Sub()); | 400 NodeProperties::ChangeOp(node, machine()->Float64Sub()); |
| 399 return Changed(node); | 401 return Changed(node); |
| 400 } | 402 } |
| 401 if (m.right().Is(1)) return Replace(m.left().node()); // x * 1.0 => x | |
| 402 if (m.right().IsNaN()) { // x * NaN => NaN | 403 if (m.right().IsNaN()) { // x * NaN => NaN |
| 403 return Replace(m.right().node()); | 404 // Do some calculation to make a signalling NaN quiet. |
| 405 return ReplaceFloat64(m.right().Value() - m.right().Value()); | |
| 404 } | 406 } |
| 405 if (m.IsFoldable()) { // K * K => K | 407 if (m.IsFoldable()) { // K * K => K |
| 406 return ReplaceFloat64(m.left().Value() * m.right().Value()); | 408 return ReplaceFloat64(m.left().Value() * m.right().Value()); |
| 407 } | 409 } |
| 408 if (m.right().Is(2)) { // x * 2.0 => x + x | 410 if (m.right().Is(2)) { // x * 2.0 => x + x |
| 409 node->ReplaceInput(1, m.left().node()); | 411 node->ReplaceInput(1, m.left().node()); |
| 410 NodeProperties::ChangeOp(node, machine()->Float64Add()); | 412 NodeProperties::ChangeOp(node, machine()->Float64Add()); |
| 411 return Changed(node); | 413 return Changed(node); |
| 412 } | 414 } |
| 413 break; | 415 break; |
| 414 } | 416 } |
| 415 case IrOpcode::kFloat64Div: { | 417 case IrOpcode::kFloat64Div: { |
| 416 Float64BinopMatcher m(node); | 418 Float64BinopMatcher m(node); |
| 417 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1.0 => x | 419 // TODO(ahaas): We could do x / 1.0 = x if we knew that x is not an sNaN. |
| 418 if (m.right().IsNaN()) { // x / NaN => NaN | 420 if (m.right().IsNaN()) { // x / NaN => NaN |
| 419 return Replace(m.right().node()); | 421 // Do some calculation to make a signalling NaN quiet. |
| 422 return ReplaceFloat64(m.right().Value() - m.right().Value()); | |
| 420 } | 423 } |
| 421 if (m.left().IsNaN()) { // NaN / x => NaN | 424 if (m.left().IsNaN()) { // NaN / x => NaN |
| 422 return Replace(m.left().node()); | 425 // Do some calculation to make a signalling NaN quiet. |
| 426 return ReplaceFloat64(m.left().Value() - m.left().Value()); | |
| 423 } | 427 } |
| 424 if (m.IsFoldable()) { // K / K => K | 428 if (m.IsFoldable()) { // K / K => K |
| 425 return ReplaceFloat64(m.left().Value() / m.right().Value()); | 429 return ReplaceFloat64(m.left().Value() / m.right().Value()); |
| 426 } | 430 } |
| 427 if (m.right().Is(-1)) { // x / -1.0 => -x | 431 if (m.right().Is(-1)) { // x / -1.0 => -x |
| 428 node->RemoveInput(1); | 432 node->RemoveInput(1); |
| 429 NodeProperties::ChangeOp(node, machine()->Float64Neg()); | 433 NodeProperties::ChangeOp(node, machine()->Float64Neg()); |
| 430 return Changed(node); | 434 return Changed(node); |
| 431 } | 435 } |
| 432 if (m.right().IsNormal() && m.right().IsPositiveOrNegativePowerOf2()) { | 436 if (m.right().IsNormal() && m.right().IsPositiveOrNegativePowerOf2()) { |
| (...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1410 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 1414 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
| 1411 return jsgraph()->machine(); | 1415 return jsgraph()->machine(); |
| 1412 } | 1416 } |
| 1413 | 1417 |
| 1414 | 1418 |
| 1415 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 1419 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
| 1416 | 1420 |
| 1417 } // namespace compiler | 1421 } // namespace compiler |
| 1418 } // namespace internal | 1422 } // namespace internal |
| 1419 } // namespace v8 | 1423 } // namespace v8 |
| OLD | NEW |