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 <algorithm> | 5 #include <algorithm> |
6 | 6 |
7 #include "src/base/adapters.h" | 7 #include "src/base/adapters.h" |
8 #include "src/compiler/instruction-selector-impl.h" | 8 #include "src/compiler/instruction-selector-impl.h" |
9 #include "src/compiler/node-matchers.h" | 9 #include "src/compiler/node-matchers.h" |
10 #include "src/compiler/node-properties.h" | 10 #include "src/compiler/node-properties.h" |
(...skipping 1413 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1424 | 1424 |
1425 | 1425 |
1426 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, | 1426 void InstructionSelector::VisitBranch(Node* branch, BasicBlock* tbranch, |
1427 BasicBlock* fbranch) { | 1427 BasicBlock* fbranch) { |
1428 X64OperandGenerator g(this); | 1428 X64OperandGenerator g(this); |
1429 Node* user = branch; | 1429 Node* user = branch; |
1430 Node* value = branch->InputAt(0); | 1430 Node* value = branch->InputAt(0); |
1431 | 1431 |
1432 FlagsContinuation cont(kNotEqual, tbranch, fbranch); | 1432 FlagsContinuation cont(kNotEqual, tbranch, fbranch); |
1433 | 1433 |
| 1434 // Try to combine with comparisons against 0 by simply inverting the branch. |
| 1435 while (CanCover(user, value) && value->opcode() == IrOpcode::kWord32Equal) { |
| 1436 Int32BinopMatcher m(value); |
| 1437 if (m.right().Is(0)) { |
| 1438 user = value; |
| 1439 value = m.left().node(); |
| 1440 cont.Negate(); |
| 1441 } else { |
| 1442 break; |
| 1443 } |
| 1444 } |
| 1445 |
1434 // Try to combine the branch with a comparison. | 1446 // Try to combine the branch with a comparison. |
1435 while (CanCover(user, value)) { | 1447 if (CanCover(user, value)) { |
1436 switch (value->opcode()) { | 1448 switch (value->opcode()) { |
1437 case IrOpcode::kWord32Equal: | 1449 case IrOpcode::kWord32Equal: |
1438 case IrOpcode::kWord64Equal: { | |
1439 Int64BinopMatcher m(value); | |
1440 if (m.right().Is(0)) { | |
1441 user = value; | |
1442 value = m.left().node(); | |
1443 cont.Negate(); | |
1444 continue; | |
1445 } | |
1446 cont.OverwriteAndNegateIfEqual(kEqual); | 1450 cont.OverwriteAndNegateIfEqual(kEqual); |
1447 return VisitWordCompare( | 1451 return VisitWordCompare(this, value, kX64Cmp32, &cont); |
1448 this, value, | |
1449 value->opcode() == IrOpcode::kWord64Equal ? kX64Cmp : kX64Cmp32, | |
1450 &cont); | |
1451 } | |
1452 case IrOpcode::kInt32LessThan: | 1452 case IrOpcode::kInt32LessThan: |
1453 cont.OverwriteAndNegateIfEqual(kSignedLessThan); | 1453 cont.OverwriteAndNegateIfEqual(kSignedLessThan); |
1454 return VisitWordCompare(this, value, kX64Cmp32, &cont); | 1454 return VisitWordCompare(this, value, kX64Cmp32, &cont); |
1455 case IrOpcode::kInt32LessThanOrEqual: | 1455 case IrOpcode::kInt32LessThanOrEqual: |
1456 cont.OverwriteAndNegateIfEqual(kSignedLessThanOrEqual); | 1456 cont.OverwriteAndNegateIfEqual(kSignedLessThanOrEqual); |
1457 return VisitWordCompare(this, value, kX64Cmp32, &cont); | 1457 return VisitWordCompare(this, value, kX64Cmp32, &cont); |
1458 case IrOpcode::kUint32LessThan: | 1458 case IrOpcode::kUint32LessThan: |
1459 cont.OverwriteAndNegateIfEqual(kUnsignedLessThan); | 1459 cont.OverwriteAndNegateIfEqual(kUnsignedLessThan); |
1460 return VisitWordCompare(this, value, kX64Cmp32, &cont); | 1460 return VisitWordCompare(this, value, kX64Cmp32, &cont); |
1461 case IrOpcode::kUint32LessThanOrEqual: | 1461 case IrOpcode::kUint32LessThanOrEqual: |
1462 cont.OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual); | 1462 cont.OverwriteAndNegateIfEqual(kUnsignedLessThanOrEqual); |
1463 return VisitWordCompare(this, value, kX64Cmp32, &cont); | 1463 return VisitWordCompare(this, value, kX64Cmp32, &cont); |
| 1464 case IrOpcode::kWord64Equal: { |
| 1465 cont.OverwriteAndNegateIfEqual(kEqual); |
| 1466 Int64BinopMatcher m(value); |
| 1467 if (m.right().Is(0)) { |
| 1468 // Try to combine the branch with a comparison. |
| 1469 Node* const user = m.node(); |
| 1470 Node* const value = m.left().node(); |
| 1471 if (CanCover(user, value)) { |
| 1472 switch (value->opcode()) { |
| 1473 case IrOpcode::kInt64Sub: |
| 1474 return VisitWord64Compare(this, value, &cont); |
| 1475 case IrOpcode::kWord64And: |
| 1476 return VisitWordCompare(this, value, kX64Test, &cont); |
| 1477 default: |
| 1478 break; |
| 1479 } |
| 1480 } |
| 1481 return VisitCompareZero(this, value, kX64Cmp, &cont); |
| 1482 } |
| 1483 return VisitWord64Compare(this, value, &cont); |
| 1484 } |
1464 case IrOpcode::kInt64LessThan: | 1485 case IrOpcode::kInt64LessThan: |
1465 cont.OverwriteAndNegateIfEqual(kSignedLessThan); | 1486 cont.OverwriteAndNegateIfEqual(kSignedLessThan); |
1466 return VisitWord64Compare(this, value, &cont); | 1487 return VisitWord64Compare(this, value, &cont); |
1467 case IrOpcode::kInt64LessThanOrEqual: | 1488 case IrOpcode::kInt64LessThanOrEqual: |
1468 cont.OverwriteAndNegateIfEqual(kSignedLessThanOrEqual); | 1489 cont.OverwriteAndNegateIfEqual(kSignedLessThanOrEqual); |
1469 return VisitWord64Compare(this, value, &cont); | 1490 return VisitWord64Compare(this, value, &cont); |
1470 case IrOpcode::kUint64LessThan: | 1491 case IrOpcode::kUint64LessThan: |
1471 cont.OverwriteAndNegateIfEqual(kUnsignedLessThan); | 1492 cont.OverwriteAndNegateIfEqual(kUnsignedLessThan); |
1472 return VisitWord64Compare(this, value, &cont); | 1493 return VisitWord64Compare(this, value, &cont); |
1473 case IrOpcode::kUint64LessThanOrEqual: | 1494 case IrOpcode::kUint64LessThanOrEqual: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1523 } | 1544 } |
1524 break; | 1545 break; |
1525 case IrOpcode::kInt32Sub: | 1546 case IrOpcode::kInt32Sub: |
1526 return VisitWordCompare(this, value, kX64Cmp32, &cont); | 1547 return VisitWordCompare(this, value, kX64Cmp32, &cont); |
1527 case IrOpcode::kInt64Sub: | 1548 case IrOpcode::kInt64Sub: |
1528 return VisitWord64Compare(this, value, &cont); | 1549 return VisitWord64Compare(this, value, &cont); |
1529 case IrOpcode::kWord32And: | 1550 case IrOpcode::kWord32And: |
1530 return VisitWordCompare(this, value, kX64Test32, &cont); | 1551 return VisitWordCompare(this, value, kX64Test32, &cont); |
1531 case IrOpcode::kWord64And: | 1552 case IrOpcode::kWord64And: |
1532 return VisitWordCompare(this, value, kX64Test, &cont); | 1553 return VisitWordCompare(this, value, kX64Test, &cont); |
1533 case IrOpcode::kLoad: | |
1534 if (LoadRepresentationOf(value->op()).representation() == | |
1535 MachineRepresentation::kWord64) { | |
1536 return VisitCompareZero(this, value, kX64Cmp, &cont); | |
1537 } | |
1538 break; | |
1539 default: | 1554 default: |
1540 break; | 1555 break; |
1541 } | 1556 } |
1542 break; | |
1543 } | 1557 } |
1544 | 1558 |
1545 // Branch could not be combined with a compare, emit compare against 0. | 1559 // Branch could not be combined with a compare, emit compare against 0. |
1546 VisitCompareZero(this, value, kX64Cmp32, &cont); | 1560 VisitCompareZero(this, value, kX64Cmp32, &cont); |
1547 } | 1561 } |
1548 | 1562 |
1549 | 1563 |
1550 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) { | 1564 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) { |
1551 X64OperandGenerator g(this); | 1565 X64OperandGenerator g(this); |
1552 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); | 1566 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1800 MachineOperatorBuilder::kFloat64RoundTruncate | | 1814 MachineOperatorBuilder::kFloat64RoundTruncate | |
1801 MachineOperatorBuilder::kFloat32RoundTiesEven | | 1815 MachineOperatorBuilder::kFloat32RoundTiesEven | |
1802 MachineOperatorBuilder::kFloat64RoundTiesEven; | 1816 MachineOperatorBuilder::kFloat64RoundTiesEven; |
1803 } | 1817 } |
1804 return flags; | 1818 return flags; |
1805 } | 1819 } |
1806 | 1820 |
1807 } // namespace compiler | 1821 } // namespace compiler |
1808 } // namespace internal | 1822 } // namespace internal |
1809 } // namespace v8 | 1823 } // namespace v8 |
OLD | NEW |