| Index: src/compiler/ia32/instruction-selector-ia32.cc
|
| diff --git a/src/compiler/ia32/instruction-selector-ia32.cc b/src/compiler/ia32/instruction-selector-ia32.cc
|
| index 8e55a327c82b94a37ae777c88c66a157263092e8..24f30c637b031ae5bf28901746f2664fe1f963c6 100644
|
| --- a/src/compiler/ia32/instruction-selector-ia32.cc
|
| +++ b/src/compiler/ia32/instruction-selector-ia32.cc
|
| @@ -991,29 +991,69 @@ 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 <= 4);
|
| IA32OperandGenerator 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(cont->Encode(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(cont->Encode(opcode), g.DefineAsByteRegister(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 CanUseMemoryOperand(InstructionSelector* selector, InstructionCode opcode,
|
| + Node* node, Node* input) {
|
| + if (input->opcode() != IrOpcode::kLoad || !selector->CanCover(node, input) ||
|
| + selector->GetEffectLevel(input) != selector->GetEffectLevel(node)) {
|
| + return false;
|
| }
|
| + if (LoadRepresentationOf(input->op()).representation() ==
|
| + MachineRepresentation::kWord32) {
|
| + return (opcode == kIA32Cmp || opcode == kIA32Test);
|
| + }
|
| + 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) {
|
| IA32OperandGenerator g(selector);
|
| if (commutative && g.CanBeBetterLeftOperand(right)) {
|
| std::swap(left, right);
|
| }
|
| - VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
|
| + if (node && CanUseMemoryOperand(selector, opcode, node, left)) {
|
| + size_t input_count = 0;
|
| + InstructionOperand inputs[4];
|
| + AddressingMode addressing_mode =
|
| + g.GetEffectiveAddressMemoryOperand(left, inputs, &input_count);
|
| + opcode |= AddressingModeField::encode(addressing_mode);
|
| + VisitCompare(selector, opcode, input_count, inputs, g.Use(right), cont);
|
| + } else {
|
| + VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
|
| + }
|
| }
|
|
|
|
|
| @@ -1039,18 +1079,30 @@ void VisitFloat64Compare(InstructionSelector* selector, Node* node,
|
| void VisitWordCompare(InstructionSelector* selector, Node* node,
|
| InstructionCode opcode, FlagsContinuation* cont) {
|
| IA32OperandGenerator 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 (CanUseMemoryOperand(selector, 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);
|
| }
|
| }
|
|
|
|
|