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 19 matching lines...) Expand all Loading... |
30 } | 30 } |
31 case IrOpcode::kNumberConstant: { | 31 case IrOpcode::kNumberConstant: { |
32 const double value = OpParameter<double>(node); | 32 const double value = OpParameter<double>(node); |
33 return bit_cast<int64_t>(value) == 0; | 33 return bit_cast<int64_t>(value) == 0; |
34 } | 34 } |
35 default: | 35 default: |
36 return false; | 36 return false; |
37 } | 37 } |
38 } | 38 } |
39 | 39 |
40 bool CanBeMemoryOperand(InstructionCode opcode, Node* node, Node* input) { | 40 bool CanBeMemoryOperand(InstructionCode opcode, Node* node, Node* input, |
| 41 int effect_level) { |
41 if (input->opcode() != IrOpcode::kLoad || | 42 if (input->opcode() != IrOpcode::kLoad || |
42 !selector()->CanCover(node, input)) { | 43 !selector()->CanCover(node, input)) { |
43 return false; | 44 return false; |
44 } | 45 } |
| 46 if (effect_level != selector()->GetEffectLevel(input)) { |
| 47 return false; |
| 48 } |
45 MachineRepresentation rep = | 49 MachineRepresentation rep = |
46 LoadRepresentationOf(input->op()).representation(); | 50 LoadRepresentationOf(input->op()).representation(); |
47 switch (opcode) { | 51 switch (opcode) { |
48 case kX64Cmp: | 52 case kX64Cmp: |
49 case kX64Test: | 53 case kX64Test: |
50 return rep == MachineRepresentation::kWord64 || | 54 return rep == MachineRepresentation::kWord64 || |
51 rep == MachineRepresentation::kTagged; | 55 rep == MachineRepresentation::kTagged; |
52 case kX64Cmp32: | 56 case kX64Cmp32: |
53 case kX64Test32: | 57 case kX64Test32: |
54 return rep == MachineRepresentation::kWord32; | 58 return rep == MachineRepresentation::kWord32; |
(...skipping 1486 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 void VisitWordCompare(InstructionSelector* selector, Node* node, | 1545 void VisitWordCompare(InstructionSelector* selector, Node* node, |
1542 InstructionCode opcode, FlagsContinuation* cont) { | 1546 InstructionCode opcode, FlagsContinuation* cont) { |
1543 X64OperandGenerator g(selector); | 1547 X64OperandGenerator g(selector); |
1544 Node* left = node->InputAt(0); | 1548 Node* left = node->InputAt(0); |
1545 Node* right = node->InputAt(1); | 1549 Node* right = node->InputAt(1); |
1546 | 1550 |
1547 opcode = TryNarrowOpcodeSize(opcode, left, right); | 1551 opcode = TryNarrowOpcodeSize(opcode, left, right); |
1548 | 1552 |
1549 // If one of the two inputs is an immediate, make sure it's on the right, or | 1553 // If one of the two inputs is an immediate, make sure it's on the right, or |
1550 // if one of the two inputs is a memory operand, make sure it's on the left. | 1554 // if one of the two inputs is a memory operand, make sure it's on the left. |
| 1555 int effect_level = selector->GetEffectLevel(node); |
| 1556 if (cont->IsBranch()) { |
| 1557 effect_level = selector->GetEffectLevel( |
| 1558 cont->true_block()->PredecessorAt(0)->control_input()); |
| 1559 } |
| 1560 |
1551 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || | 1561 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || |
1552 (g.CanBeMemoryOperand(opcode, node, right) && | 1562 (g.CanBeMemoryOperand(opcode, node, right, effect_level) && |
1553 !g.CanBeMemoryOperand(opcode, node, left))) { | 1563 !g.CanBeMemoryOperand(opcode, node, left, effect_level))) { |
1554 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1564 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1555 std::swap(left, right); | 1565 std::swap(left, right); |
1556 } | 1566 } |
1557 | 1567 |
1558 // Match immediates on right side of comparison. | 1568 // Match immediates on right side of comparison. |
1559 if (g.CanBeImmediate(right)) { | 1569 if (g.CanBeImmediate(right)) { |
1560 if (g.CanBeMemoryOperand(opcode, node, left)) { | 1570 if (g.CanBeMemoryOperand(opcode, node, left, effect_level)) { |
1561 return VisitCompareWithMemoryOperand(selector, opcode, left, | 1571 return VisitCompareWithMemoryOperand(selector, opcode, left, |
1562 g.UseImmediate(right), cont); | 1572 g.UseImmediate(right), cont); |
1563 } | 1573 } |
1564 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), | 1574 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), |
1565 cont); | 1575 cont); |
1566 } | 1576 } |
1567 | 1577 |
1568 // Match memory operands on left side of comparison. | 1578 // Match memory operands on left side of comparison. |
1569 if (g.CanBeMemoryOperand(opcode, node, left)) { | 1579 if (g.CanBeMemoryOperand(opcode, node, left, effect_level)) { |
1570 return VisitCompareWithMemoryOperand(selector, opcode, left, | 1580 return VisitCompareWithMemoryOperand(selector, opcode, left, |
1571 g.UseRegister(right), cont); | 1581 g.UseRegister(right), cont); |
1572 } | 1582 } |
1573 | 1583 |
1574 if (g.CanBeBetterLeftOperand(right)) { | 1584 if (g.CanBeBetterLeftOperand(right)) { |
1575 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); | 1585 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
1576 std::swap(left, right); | 1586 std::swap(left, right); |
1577 } | 1587 } |
1578 | 1588 |
1579 return VisitCompare(selector, opcode, left, right, cont, | 1589 return VisitCompare(selector, opcode, left, right, cont, |
(...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2103 // static | 2113 // static |
2104 MachineOperatorBuilder::AlignmentRequirements | 2114 MachineOperatorBuilder::AlignmentRequirements |
2105 InstructionSelector::AlignmentRequirements() { | 2115 InstructionSelector::AlignmentRequirements() { |
2106 return MachineOperatorBuilder::AlignmentRequirements:: | 2116 return MachineOperatorBuilder::AlignmentRequirements:: |
2107 FullUnalignedAccessSupport(); | 2117 FullUnalignedAccessSupport(); |
2108 } | 2118 } |
2109 | 2119 |
2110 } // namespace compiler | 2120 } // namespace compiler |
2111 } // namespace internal | 2121 } // namespace internal |
2112 } // namespace v8 | 2122 } // namespace v8 |
OLD | NEW |