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

Side by Side Diff: src/compiler/x64/instruction-selector-x64.cc

Issue 1677503002: [turbofan] Fixes the code generation for branches on x64 when the condition is Word64Equal. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
1446 // Try to combine the branch with a comparison. 1434 // Try to combine the branch with a comparison.
1447 if (CanCover(user, value)) { 1435 while (CanCover(user, value)) {
1448 switch (value->opcode()) { 1436 switch (value->opcode()) {
1449 case IrOpcode::kWord32Equal: 1437 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 }
1450 cont.OverwriteAndNegateIfEqual(kEqual); 1446 cont.OverwriteAndNegateIfEqual(kEqual);
1451 return VisitWordCompare(this, value, kX64Cmp32, &cont); 1447 return VisitWordCompare(
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 }
1485 case IrOpcode::kInt64LessThan: 1464 case IrOpcode::kInt64LessThan:
1486 cont.OverwriteAndNegateIfEqual(kSignedLessThan); 1465 cont.OverwriteAndNegateIfEqual(kSignedLessThan);
1487 return VisitWord64Compare(this, value, &cont); 1466 return VisitWord64Compare(this, value, &cont);
1488 case IrOpcode::kInt64LessThanOrEqual: 1467 case IrOpcode::kInt64LessThanOrEqual:
1489 cont.OverwriteAndNegateIfEqual(kSignedLessThanOrEqual); 1468 cont.OverwriteAndNegateIfEqual(kSignedLessThanOrEqual);
1490 return VisitWord64Compare(this, value, &cont); 1469 return VisitWord64Compare(this, value, &cont);
1491 case IrOpcode::kUint64LessThan: 1470 case IrOpcode::kUint64LessThan:
1492 cont.OverwriteAndNegateIfEqual(kUnsignedLessThan); 1471 cont.OverwriteAndNegateIfEqual(kUnsignedLessThan);
1493 return VisitWord64Compare(this, value, &cont); 1472 return VisitWord64Compare(this, value, &cont);
1494 case IrOpcode::kUint64LessThanOrEqual: 1473 case IrOpcode::kUint64LessThanOrEqual:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1544 } 1523 }
1545 break; 1524 break;
1546 case IrOpcode::kInt32Sub: 1525 case IrOpcode::kInt32Sub:
1547 return VisitWordCompare(this, value, kX64Cmp32, &cont); 1526 return VisitWordCompare(this, value, kX64Cmp32, &cont);
1548 case IrOpcode::kInt64Sub: 1527 case IrOpcode::kInt64Sub:
1549 return VisitWord64Compare(this, value, &cont); 1528 return VisitWord64Compare(this, value, &cont);
1550 case IrOpcode::kWord32And: 1529 case IrOpcode::kWord32And:
1551 return VisitWordCompare(this, value, kX64Test32, &cont); 1530 return VisitWordCompare(this, value, kX64Test32, &cont);
1552 case IrOpcode::kWord64And: 1531 case IrOpcode::kWord64And:
1553 return VisitWordCompare(this, value, kX64Test, &cont); 1532 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;
1554 default: 1539 default:
1555 break; 1540 break;
1556 } 1541 }
1542 break;
1557 } 1543 }
1558 1544
1559 // Branch could not be combined with a compare, emit compare against 0. 1545 // Branch could not be combined with a compare, emit compare against 0.
1560 VisitCompareZero(this, value, kX64Cmp32, &cont); 1546 VisitCompareZero(this, value, kX64Cmp32, &cont);
1561 } 1547 }
1562 1548
1563 1549
1564 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) { 1550 void InstructionSelector::VisitSwitch(Node* node, const SwitchInfo& sw) {
1565 X64OperandGenerator g(this); 1551 X64OperandGenerator g(this);
1566 InstructionOperand value_operand = g.UseRegister(node->InputAt(0)); 1552 InstructionOperand value_operand = g.UseRegister(node->InputAt(0));
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
1814 MachineOperatorBuilder::kFloat64RoundTruncate | 1800 MachineOperatorBuilder::kFloat64RoundTruncate |
1815 MachineOperatorBuilder::kFloat32RoundTiesEven | 1801 MachineOperatorBuilder::kFloat32RoundTiesEven |
1816 MachineOperatorBuilder::kFloat64RoundTiesEven; 1802 MachineOperatorBuilder::kFloat64RoundTiesEven;
1817 } 1803 }
1818 return flags; 1804 return flags;
1819 } 1805 }
1820 1806
1821 } // namespace compiler 1807 } // namespace compiler
1822 } // namespace internal 1808 } // namespace internal
1823 } // namespace v8 1809 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698