| 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 96f8e32f8d607d7f95692bbeb4615137261da3a6..c361678578ef653f45d963a7906b8ff502cc852b 100644
|
| --- a/src/compiler/x64/instruction-selector-x64.cc
|
| +++ b/src/compiler/x64/instruction-selector-x64.cc
|
| @@ -1328,31 +1328,72 @@ bool InstructionSelector::IsTailCallAddressImmediate() { return true; }
|
|
|
| namespace {
|
|
|
| -// Shared routine for multiple compare operations.
|
| void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
|
| - InstructionOperand left, InstructionOperand right,
|
| - FlagsContinuation* cont) {
|
| + size_t left_operands_count, InstructionOperand* left_operands,
|
| + InstructionOperand right, FlagsContinuation* cont) {
|
| + DCHECK(left_operands_count > 0 && left_operands_count <= 3);
|
| X64OperandGenerator g(selector);
|
| opcode = cont->Encode(opcode);
|
| + int input_count = 0;
|
| + InstructionOperand inputs[6];
|
| + do {
|
| + inputs[input_count] = left_operands[input_count];
|
| + } while (++input_count < left_operands_count);
|
| + inputs[input_count++] = right;
|
| +
|
| if (cont->IsBranch()) {
|
| - selector->Emit(opcode, g.NoOutput(), left, right,
|
| - g.Label(cont->true_block()), g.Label(cont->false_block()));
|
| + inputs[input_count++] = g.Label(cont->true_block());
|
| + inputs[input_count++] = g.Label(cont->false_block());
|
| + selector->Emit(opcode, 0, nullptr, input_count, inputs);
|
| } else {
|
| DCHECK(cont->IsSet());
|
| - selector->Emit(opcode, g.DefineAsRegister(cont->result()), left, right);
|
| + InstructionOperand output = g.DefineAsRegister(cont->result());
|
| + selector->Emit(opcode, 1, &output, input_count, inputs);
|
| }
|
| }
|
|
|
| +// Determines if `input' of `node' can be replaced by a memory operand.
|
| +bool CanUseMemOp(InstructionCode opcode, Node* node, Node* input) {
|
| + if (input->opcode() == IrOpcode::kLoad && input->OwnedBy(node)) {
|
| + 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;
|
| + }
|
| + }
|
| + return false;
|
| +}
|
| +
|
| +// Shared routine for multiple compare operations.
|
| +void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
|
| + InstructionOperand left, InstructionOperand right,
|
| + FlagsContinuation* cont) {
|
| + VisitCompare(selector, opcode, 1, &left, right, cont);
|
| +}
|
| +
|
|
|
| // Shared routine for multiple compare operations.
|
| void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
|
| Node* left, Node* right, FlagsContinuation* cont,
|
| - bool commutative) {
|
| + bool commutative, Node* node = nullptr) {
|
| X64OperandGenerator g(selector);
|
| if (commutative && g.CanBeBetterLeftOperand(right)) {
|
| std::swap(left, right);
|
| }
|
| - VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
|
| + if (node && CanUseMemOp(opcode, node, left)) {
|
| + size_t left_operands_count = 0;
|
| + InstructionOperand left_operands[4];
|
| + AddressingMode addressing_mode = g.GetEffectiveAddressMemoryOperand(
|
| + left, left_operands, &left_operands_count);
|
| + opcode |= AddressingModeField::encode(addressing_mode);
|
| + VisitCompare(selector, opcode, left_operands_count, left_operands,
|
| + g.Use(right), cont);
|
| + } else {
|
| + VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
|
| + }
|
| }
|
|
|
|
|
| @@ -1360,22 +1401,33 @@ void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
|
| void VisitWordCompare(InstructionSelector* selector, Node* node,
|
| InstructionCode opcode, FlagsContinuation* cont) {
|
| X64OperandGenerator g(selector);
|
| - Node* const left = node->InputAt(0);
|
| - Node* const right = node->InputAt(1);
|
| + Node* left = node->InputAt(0);
|
| + Node* right = node->InputAt(1);
|
|
|
| - // Match immediates on left or right side of comparison.
|
| - if (g.CanBeImmediate(right)) {
|
| - VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), cont);
|
| - } else if (g.CanBeImmediate(left)) {
|
| + if (!g.CanBeImmediate(right) && g.CanBeImmediate(left)) {
|
| if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
|
| - VisitCompare(selector, opcode, g.Use(right), g.UseImmediate(left), cont);
|
| + std::swap(left, right);
|
| + }
|
| +
|
| + // Match immediates on right side of comparison.
|
| + if (g.CanBeImmediate(right)) {
|
| + if (CanUseMemOp(opcode, node, left)) {
|
| + size_t left_operands_count = 0;
|
| + InstructionOperand left_operands[4];
|
| + AddressingMode addressing_mode = g.GetEffectiveAddressMemoryOperand(
|
| + left, left_operands, &left_operands_count);
|
| + opcode |= AddressingModeField::encode(addressing_mode);
|
| + VisitCompare(selector, opcode, left_operands_count, left_operands,
|
| + g.UseImmediate(right), cont);
|
| + } else {
|
| + VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), cont);
|
| + }
|
| } else {
|
| VisitCompare(selector, opcode, left, right, cont,
|
| - node->op()->HasProperty(Operator::kCommutative));
|
| + node->op()->HasProperty(Operator::kCommutative), node);
|
| }
|
| }
|
|
|
| -
|
| // Shared routine for 64-bit word comparison operations.
|
| void VisitWord64Compare(InstructionSelector* selector, Node* node,
|
| FlagsContinuation* cont) {
|
|
|