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)) { | |
320 return Replace(m.left().node()); // x - 0 => x | |
321 } | |
322 if (m.right().IsNaN()) { // x - NaN => NaN | 319 if (m.right().IsNaN()) { // x - NaN => NaN |
323 return Replace(m.right().node()); | 320 // - 0.0 to make a signalling NaN quiet. |
321 return ReplaceFloat32(m.right().Value() - 0.0); | |
324 } | 322 } |
325 if (m.left().IsNaN()) { // NaN - x => NaN | 323 if (m.left().IsNaN()) { // NaN - x => NaN |
326 return Replace(m.left().node()); | 324 // - 0.0 to make a signalling NaN quiet. |
325 return ReplaceFloat32(m.left().Value() - 0.0); | |
327 } | 326 } |
328 if (m.IsFoldable()) { // L - R => (L - R) | 327 if (m.IsFoldable()) { // L - R => (L - R) |
329 return ReplaceFloat32(m.left().Value() - m.right().Value()); | 328 return ReplaceFloat32(m.left().Value() - m.right().Value()); |
330 } | 329 } |
331 if (m.left().IsMinusZero()) { | 330 if (m.left().IsMinusZero()) { |
332 // -0.0 - round_down(-0.0 - R) => round_up(R) | 331 // -0.0 - round_down(-0.0 - R) => round_up(R) |
333 if (machine()->Float32RoundUp().IsSupported() && | 332 if (machine()->Float32RoundUp().IsSupported() && |
334 m.right().IsFloat32RoundDown()) { | 333 m.right().IsFloat32RoundDown()) { |
335 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat32Sub) { | 334 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat32Sub) { |
336 Float32BinopMatcher mright0(m.right().InputAt(0)); | 335 Float32BinopMatcher mright0(m.right().InputAt(0)); |
337 if (mright0.left().IsMinusZero()) { | 336 if (mright0.left().IsMinusZero()) { |
338 return Replace(graph()->NewNode(machine()->Float32RoundUp().op(), | 337 return Replace(graph()->NewNode(machine()->Float32RoundUp().op(), |
339 mright0.right().node())); | 338 mright0.right().node())); |
340 } | 339 } |
341 } | 340 } |
342 } | 341 } |
343 // -0.0 - R => -R | 342 // -0.0 - R => -R |
344 node->RemoveInput(0); | 343 node->RemoveInput(0); |
345 NodeProperties::ChangeOp(node, machine()->Float32Neg()); | 344 NodeProperties::ChangeOp(node, machine()->Float32Neg()); |
346 return Changed(node); | 345 return Changed(node); |
347 } | 346 } |
348 break; | 347 break; |
349 } | 348 } |
350 case IrOpcode::kFloat64Add: { | 349 case IrOpcode::kFloat64Add: { |
351 Float64BinopMatcher m(node); | 350 Float64BinopMatcher m(node); |
352 if (m.right().IsNaN()) { // x + NaN => NaN | 351 if (m.right().IsNaN()) { // x + NaN => NaN |
353 return Replace(m.right().node()); | 352 // - 0.0 to make a signalling NaN quiet. |
353 return ReplaceFloat64(m.right().Value() - 0.0); | |
354 } | 354 } |
355 if (m.IsFoldable()) { // K + K => K | 355 if (m.IsFoldable()) { // K + K => K |
356 return ReplaceFloat64(m.left().Value() + m.right().Value()); | 356 return ReplaceFloat64(m.left().Value() + m.right().Value()); |
357 } | 357 } |
358 break; | 358 break; |
359 } | 359 } |
360 case IrOpcode::kFloat64Sub: { | 360 case IrOpcode::kFloat64Sub: { |
361 Float64BinopMatcher m(node); | 361 Float64BinopMatcher m(node); |
362 if (m.right().Is(0) && (Double(m.right().Value()).Sign() > 0)) { | |
363 return Replace(m.left().node()); // x - 0 => x | |
364 } | |
365 if (m.right().IsNaN()) { // x - NaN => NaN | 362 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
| |
366 return Replace(m.right().node()); | 363 // - 0.0 to make a signalling NaN quiet. |
364 return ReplaceFloat64(m.right().Value() - 0.0); | |
367 } | 365 } |
368 if (m.left().IsNaN()) { // NaN - x => NaN | 366 if (m.left().IsNaN()) { // NaN - x => NaN |
369 return Replace(m.left().node()); | 367 // - 0.0 to make a signalling NaN quiet. |
368 return ReplaceFloat64(m.left().Value() - 0.0); | |
370 } | 369 } |
371 if (m.IsFoldable()) { // L - R => (L - R) | 370 if (m.IsFoldable()) { // L - R => (L - R) |
372 return ReplaceFloat64(m.left().Value() - m.right().Value()); | 371 return ReplaceFloat64(m.left().Value() - m.right().Value()); |
373 } | 372 } |
374 if (m.left().IsMinusZero()) { | 373 if (m.left().IsMinusZero()) { |
375 // -0.0 - round_down(-0.0 - R) => round_up(R) | 374 // -0.0 - round_down(-0.0 - R) => round_up(R) |
376 if (machine()->Float64RoundUp().IsSupported() && | 375 if (machine()->Float64RoundUp().IsSupported() && |
377 m.right().IsFloat64RoundDown()) { | 376 m.right().IsFloat64RoundDown()) { |
378 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub) { | 377 if (m.right().InputAt(0)->opcode() == IrOpcode::kFloat64Sub) { |
379 Float64BinopMatcher mright0(m.right().InputAt(0)); | 378 Float64BinopMatcher mright0(m.right().InputAt(0)); |
(...skipping 11 matching lines...) Expand all Loading... | |
391 break; | 390 break; |
392 } | 391 } |
393 case IrOpcode::kFloat64Mul: { | 392 case IrOpcode::kFloat64Mul: { |
394 Float64BinopMatcher m(node); | 393 Float64BinopMatcher m(node); |
395 if (m.right().Is(-1)) { // x * -1.0 => -0.0 - x | 394 if (m.right().Is(-1)) { // x * -1.0 => -0.0 - x |
396 node->ReplaceInput(0, Float64Constant(-0.0)); | 395 node->ReplaceInput(0, Float64Constant(-0.0)); |
397 node->ReplaceInput(1, m.left().node()); | 396 node->ReplaceInput(1, m.left().node()); |
398 NodeProperties::ChangeOp(node, machine()->Float64Sub()); | 397 NodeProperties::ChangeOp(node, machine()->Float64Sub()); |
399 return Changed(node); | 398 return Changed(node); |
400 } | 399 } |
401 if (m.right().Is(1)) return Replace(m.left().node()); // x * 1.0 => x | |
402 if (m.right().IsNaN()) { // x * NaN => NaN | 400 if (m.right().IsNaN()) { // x * NaN => NaN |
403 return Replace(m.right().node()); | 401 // - 0.0 to make a signalling NaN quiet. |
402 return ReplaceFloat64(m.right().Value() - 0.0); | |
404 } | 403 } |
405 if (m.IsFoldable()) { // K * K => K | 404 if (m.IsFoldable()) { // K * K => K |
406 return ReplaceFloat64(m.left().Value() * m.right().Value()); | 405 return ReplaceFloat64(m.left().Value() * m.right().Value()); |
407 } | 406 } |
408 if (m.right().Is(2)) { // x * 2.0 => x + x | 407 if (m.right().Is(2)) { // x * 2.0 => x + x |
409 node->ReplaceInput(1, m.left().node()); | 408 node->ReplaceInput(1, m.left().node()); |
410 NodeProperties::ChangeOp(node, machine()->Float64Add()); | 409 NodeProperties::ChangeOp(node, machine()->Float64Add()); |
411 return Changed(node); | 410 return Changed(node); |
412 } | 411 } |
413 break; | 412 break; |
414 } | 413 } |
415 case IrOpcode::kFloat64Div: { | 414 case IrOpcode::kFloat64Div: { |
416 Float64BinopMatcher m(node); | 415 Float64BinopMatcher m(node); |
417 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1.0 => x | |
418 if (m.right().IsNaN()) { // x / NaN => NaN | 416 if (m.right().IsNaN()) { // x / NaN => NaN |
419 return Replace(m.right().node()); | 417 // - 0.0 to make a signalling NaN quiet. |
418 return ReplaceFloat64(m.right().Value() - 0.0); | |
420 } | 419 } |
421 if (m.left().IsNaN()) { // NaN / x => NaN | 420 if (m.left().IsNaN()) { // NaN / x => NaN |
422 return Replace(m.left().node()); | 421 // - 0.0 to make a signalling NaN quiet. |
422 return ReplaceFloat64(m.left().Value() - 0.0); | |
423 } | 423 } |
424 if (m.IsFoldable()) { // K / K => K | 424 if (m.IsFoldable()) { // K / K => K |
425 return ReplaceFloat64(m.left().Value() / m.right().Value()); | 425 return ReplaceFloat64(m.left().Value() / m.right().Value()); |
426 } | 426 } |
427 if (m.right().Is(-1)) { // x / -1.0 => -x | 427 if (m.right().Is(-1)) { // x / -1.0 => -x |
428 node->RemoveInput(1); | 428 node->RemoveInput(1); |
429 NodeProperties::ChangeOp(node, machine()->Float64Neg()); | 429 NodeProperties::ChangeOp(node, machine()->Float64Neg()); |
430 return Changed(node); | 430 return Changed(node); |
431 } | 431 } |
432 if (m.right().IsNormal() && m.right().IsPositiveOrNegativePowerOf2()) { | 432 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 { | 1410 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
1411 return jsgraph()->machine(); | 1411 return jsgraph()->machine(); |
1412 } | 1412 } |
1413 | 1413 |
1414 | 1414 |
1415 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 1415 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
1416 | 1416 |
1417 } // namespace compiler | 1417 } // namespace compiler |
1418 } // namespace internal | 1418 } // namespace internal |
1419 } // namespace v8 | 1419 } // namespace v8 |
OLD | NEW |