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 b1af3e56d89e106ac159e6cc623643e771b99770..88f8f3f43466e3065e299d007f4d31d6f13894c9 100644 |
| --- a/src/compiler/x64/instruction-selector-x64.cc |
| +++ b/src/compiler/x64/instruction-selector-x64.cc |
| @@ -1500,6 +1500,35 @@ void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
| VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); |
| } |
| +bool GetMachineRepresentation(Node* node, |
|
Benedikt Meurer
2016/05/04 04:05:47
See ia32 comment.
epertoso
2016/05/04 08:58:03
Done.
|
| + MachineRepresentation* representation) { |
| + if (node->opcode() == IrOpcode::kLoad) { |
| + *representation = LoadRepresentationOf(node->op()).representation(); |
| + return true; |
| + } |
| + uint64_t value = 0; |
| + switch (node->opcode()) { |
| + case IrOpcode::kInt32Constant: |
| + value = OpParameter<uint32_t>(node->op()); |
|
Benedikt Meurer
2016/05/04 04:05:47
See ia32 comment.
epertoso
2016/05/04 08:58:03
Done.
|
| + break; |
| + case IrOpcode::kInt64Constant: |
| + value = OpParameter<uint64_t>(node->op()); |
|
Benedikt Meurer
2016/05/04 04:05:47
See ia32 comment.
epertoso
2016/05/04 08:58:03
Done.
|
| + break; |
| + default: |
| + return false; |
| + } |
| + if (is_uint8(value)) { |
| + *representation = MachineRepresentation::kWord8; |
| + } else if (is_uint16(value)) { |
| + *representation = MachineRepresentation::kWord16; |
| + } else if (is_uint32(value)) { |
| + *representation = MachineRepresentation::kWord32; |
| + } else { |
| + return false; |
| + } |
| + return true; |
| +} |
| + |
| // Tries to match the size of the given opcode to that of the operands, if |
| // possible. |
| InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, |
| @@ -1507,20 +1536,22 @@ InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, |
| if (opcode != kX64Cmp32 && opcode != kX64Test32) { |
| return opcode; |
| } |
| - // Currently, if one of the two operands is not a Load, we don't know what its |
| - // machine representation is, so we bail out. |
| - // TODO(epertoso): we can probably get some size information out of immediates |
| - // and phi nodes. |
| - if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) { |
| + // We only do this if at least one of the two operands is a load. |
| + // TODO(epertoso): we can probably get some size information out of phi nodes. |
| + if (left->opcode() != IrOpcode::kLoad && right->opcode() != IrOpcode::kLoad) { |
| return opcode; |
| } |
| - // If the load representations don't match, both operands will be |
| + MachineRepresentation left_representation, right_representation; |
| + if (!GetMachineRepresentation(left, &left_representation) || |
| + !GetMachineRepresentation(right, &right_representation)) { |
| + return opcode; |
| + } |
| + // If the 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())) { |
| + if (left_representation != right_representation) { |
| return opcode; |
| } |
| - switch (left_representation.representation()) { |
| + switch (left_representation) { |
| case MachineRepresentation::kBit: |
| case MachineRepresentation::kWord8: |
| return opcode == kX64Cmp32 ? kX64Cmp8 : kX64Test8; |
| @@ -1538,21 +1569,46 @@ void VisitWordCompare(InstructionSelector* selector, Node* node, |
| Node* left = node->InputAt(0); |
| Node* right = node->InputAt(1); |
| - opcode = TryNarrowOpcodeSize(opcode, left, right); |
| + InstructionCode narrowed_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)) || |
| - (g.CanBeMemoryOperand(opcode, node, right) && |
| - !g.CanBeMemoryOperand(opcode, node, left))) { |
| + (g.CanBeMemoryOperand(narrowed_opcode, node, right) && |
| + !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { |
| if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
| std::swap(left, right); |
| } |
| // Match immediates on right side of comparison. |
| if (g.CanBeImmediate(right)) { |
| - if (g.CanBeMemoryOperand(opcode, node, left)) { |
| - return VisitCompareWithMemoryOperand(selector, opcode, left, |
| + if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { |
| + // If we're truncating the immediate (32 bits to 16 or 8), comparison |
| + // semantics should take the signedness/unsignedness of the op into |
| + // account. |
| + if (narrowed_opcode != opcode && |
| + LoadRepresentationOf(left->op()).IsUnsigned()) { |
| + switch (cont->condition()) { |
| + case FlagsCondition::kSignedLessThan: |
| + cont->OverwriteAndNegateIfEqual(FlagsCondition::kUnsignedLessThan); |
| + break; |
| + case FlagsCondition::kSignedGreaterThan: |
| + cont->OverwriteAndNegateIfEqual( |
| + FlagsCondition::kUnsignedGreaterThan); |
| + break; |
| + case FlagsCondition::kSignedLessThanOrEqual: |
| + cont->OverwriteAndNegateIfEqual( |
| + FlagsCondition::kUnsignedLessThanOrEqual); |
| + break; |
| + case FlagsCondition::kSignedGreaterThanOrEqual: |
| + cont->OverwriteAndNegateIfEqual( |
| + FlagsCondition::kUnsignedGreaterThanOrEqual); |
| + break; |
| + default: |
| + break; |
| + } |
| + } |
| + return VisitCompareWithMemoryOperand(selector, narrowed_opcode, left, |
| g.UseImmediate(right), cont); |
| } |
| return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), |
| @@ -1560,8 +1616,8 @@ void VisitWordCompare(InstructionSelector* selector, Node* node, |
| } |
| // Match memory operands on left side of comparison. |
| - if (g.CanBeMemoryOperand(opcode, node, left)) { |
| - return VisitCompareWithMemoryOperand(selector, opcode, left, |
| + if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { |
| + return VisitCompareWithMemoryOperand(selector, narrowed_opcode, left, |
| g.UseRegister(right), cont); |
| } |