Chromium Code Reviews| Index: src/compiler/x64/instruction-selector-x64.cc |
| diff --git a/src/compiler/x64/instruction-selector-x64.cc b/src/compiler/x64/instruction-selector-x64.cc |
| index cdd2b052eadf68cca0bb0fad1527945cdb384a37..81b44637116c82d8e71fc5c885c6b178ead3ffeb 100644 |
| --- a/src/compiler/x64/instruction-selector-x64.cc |
| +++ b/src/compiler/x64/instruction-selector-x64.cc |
| @@ -43,11 +43,22 @@ class X64OperandGenerator final : public OperandGenerator { |
| } |
| MachineRepresentation rep = |
| LoadRepresentationOf(input->op()).representation(); |
| - if (rep == MachineRepresentation::kWord64 || |
| - rep == MachineRepresentation::kTagged) { |
| - return opcode == kX64Cmp || opcode == kX64Test; |
| - } else if (rep == MachineRepresentation::kWord32) { |
| - return opcode == kX64Cmp32 || opcode == kX64Test32; |
| + switch (opcode) { |
| + case kX64Cmp: |
| + case kX64Test: |
| + return rep == MachineRepresentation::kWord64 || |
| + rep == MachineRepresentation::kTagged; |
| + case kX64Cmp32: |
| + case kX64Test32: |
| + return rep == MachineRepresentation::kWord32; |
| + case kX64Cmp16: |
| + case kX64Test16: |
| + return rep == MachineRepresentation::kWord16; |
| + case kX64Cmp8: |
| + case kX64Test8: |
| + return rep == MachineRepresentation::kWord8; |
| + default: |
| + break; |
| } |
| return false; |
| } |
| @@ -1416,6 +1427,33 @@ void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
| VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); |
| } |
| +// Tries to match the size of the given opcode to that of the operands, if |
| +// possible. |
| +InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, |
| + Node* right) { |
| + if (opcode != kX64Cmp32 && opcode != kX64Test32) { |
| + return opcode; |
| + } |
| + if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) { |
|
Jarin
2016/03/14 14:54:08
Could you add a comment explaining why you only co
epertoso
2016/03/15 14:38:46
Done.
|
| + return opcode; |
| + } |
| + // If the load representations don't match, both operands will be |
| + // zero/sign-extended to 32bit. |
| + LoadRepresentation left_representation = LoadRepresentationOf(left->op()); |
| + if (left_representation != LoadRepresentationOf(right->op())) { |
| + return opcode; |
| + } |
| + switch (left_representation.representation()) { |
| + case MachineRepresentation::kBit: |
| + case MachineRepresentation::kWord8: |
| + return opcode == kX64Cmp32 ? kX64Cmp8 : kX64Test8; |
| + case MachineRepresentation::kWord16: |
| + return opcode == kX64Cmp32 ? kX64Cmp16 : kX64Test16; |
| + default: |
| + return opcode; |
| + } |
| +} |
| + |
| // Shared routine for multiple word compare operations. |
| void VisitWordCompare(InstructionSelector* selector, Node* node, |
| InstructionCode opcode, FlagsContinuation* cont) { |
| @@ -1423,6 +1461,8 @@ void VisitWordCompare(InstructionSelector* selector, Node* node, |
| Node* left = node->InputAt(0); |
| Node* right = node->InputAt(1); |
| + opcode = TryNarrowOpcodeSize(opcode, left, right); |
| + |
| // If one of the two inputs is an immediate, make sure it's on the right, or |
| // if one of the two inputs is a memory operand, make sure it's on the left. |
| if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || |