X87: Revert of [turbofan] Take the immediate size in account when narrowing ia32/x64 word comparison operators. (patchset #1 id:1 of https://codereview.chromium.org/1968453002/ ).

port 767c34dfae (r36413)

  original commit message:
  Reason for revert:
  Breaks a KCS demo:

  BUG=chromium:611976

  Original issue's description:
  > [turbofan] Take the immediate size in account when narrowing ia32/x64 word comparison operators.
  >
  > Trying to re-land http://crrev.com/1948453002 after fixing assembler-x64.cc in http://crrev.com/1962563003.
  >
  > Before this patch, we would emit a cmp or test with a memory operand only if both of the operands in the IR were loads. Now if either of them is a load and the other one is an immediate, we can use
  >
  > Committed: https://crrev.com/2da70f853d7f680d491c37c72d5ef04a85497ba9
  > Cr-Commit-Position: refs/heads/master@{#36136}

Review-Url: https://codereview.chromium.org/2003273002
Cr-Commit-Position: refs/heads/master@{#36456}
This commit is contained in:
zhengxing.li 2016-05-23 21:16:32 -07:00 committed by Commit bot
parent 11fcf1346c
commit 35e0f01fb9

View File

@ -1187,26 +1187,6 @@ void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
} }
bool InferMachineRepresentation(Node* node,
MachineRepresentation* representation) {
if (node->opcode() == IrOpcode::kLoad) {
*representation = LoadRepresentationOf(node->op()).representation();
return true;
}
if (node->opcode() != IrOpcode::kInt32Constant) {
return false;
}
int32_t value = OpParameter<int32_t>(node->op());
if (is_int8(value)) {
*representation = MachineRepresentation::kWord8;
} else if (is_int16(value)) {
*representation = MachineRepresentation::kWord16;
} else {
*representation = MachineRepresentation::kWord32;
}
return true;
}
// Tries to match the size of the given opcode to that of the operands, if // Tries to match the size of the given opcode to that of the operands, if
// possible. // possible.
InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left,
@ -1214,22 +1194,20 @@ InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left,
if (opcode != kX87Cmp && opcode != kX87Test) { if (opcode != kX87Cmp && opcode != kX87Test) {
return opcode; return opcode;
} }
// We only do this if at least one of the two operands is a load. // Currently, if one of the two operands is not a Load, we don't know what its
// TODO(epertoso): we can probably get some size information out of phi nodes. // machine representation is, so we bail out.
if (left->opcode() != IrOpcode::kLoad && right->opcode() != IrOpcode::kLoad) { // TODO(epertoso): we can probably get some size information out of immediates
// and phi nodes.
if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) {
return opcode; return opcode;
} }
MachineRepresentation left_representation, right_representation; // If the load representations don't match, both operands will be
if (!InferMachineRepresentation(left, &left_representation) ||
!InferMachineRepresentation(right, &right_representation)) {
return opcode;
}
// If the representations don't match, both operands will be
// zero/sign-extended to 32bit. // zero/sign-extended to 32bit.
if (left_representation != right_representation) { LoadRepresentation left_representation = LoadRepresentationOf(left->op());
if (left_representation != LoadRepresentationOf(right->op())) {
return opcode; return opcode;
} }
switch (left_representation) { switch (left_representation.representation()) {
case MachineRepresentation::kBit: case MachineRepresentation::kBit:
case MachineRepresentation::kWord8: case MachineRepresentation::kWord8:
return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8; return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8;
@ -1301,33 +1279,10 @@ void VisitWordCompare(InstructionSelector* selector, Node* node,
// Match immediates on right side of comparison. // Match immediates on right side of comparison.
if (g.CanBeImmediate(right)) { if (g.CanBeImmediate(right)) {
if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { if (g.CanBeMemoryOperand(opcode, node, left)) {
// If we're truncating the immediate (32 bits to 16 or 8), comparison // TODO(epertoso): we should use `narrowed_opcode' here once we match
// semantics should take the signedness/unsignedness of the op into // immediates too.
// account. return VisitCompareWithMemoryOperand(selector, opcode, left,
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); g.UseImmediate(right), cont);
} }
return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right),