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 f7a797c2d808dbe887fb087e57814214ca105b18..30939683f85c92c2c7dcf7ea05911ce4eda56660 100644 |
| --- a/src/compiler/x64/instruction-selector-x64.cc |
| +++ b/src/compiler/x64/instruction-selector-x64.cc |
| @@ -1338,6 +1338,47 @@ bool InstructionSelector::IsTailCallAddressImmediate() { return true; } |
| namespace { |
| +void VisitCompareWithMemoryOperand(InstructionSelector* selector, |
| + InstructionCode opcode, Node* left, |
| + InstructionOperand right, |
| + FlagsContinuation* cont) { |
| + DCHECK(left_operands_count > 0 && left_operands_count <= 3); |
|
epertoso
2016/02/18 13:31:35
Already deleted this.
|
| + X64OperandGenerator g(selector); |
| + size_t input_count = 0; |
| + InstructionOperand inputs[6]; |
| + AddressingMode addressing_mode = |
| + g.GetEffectiveAddressMemoryOperand(left, inputs, &input_count); |
| + opcode |= AddressingModeField::encode(addressing_mode); |
| + opcode = cont->Encode(opcode); |
| + |
| + if (cont->IsBranch()) { |
| + 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()); |
| + 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)) { |
| + return false; |
| + } |
| + 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, |
| @@ -1365,7 +1406,6 @@ void VisitCompare(InstructionSelector* selector, InstructionCode opcode, |
| VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); |
| } |
| - |
| // Shared routine for multiple word compare operations. |
| void VisitWordCompare(InstructionSelector* selector, Node* node, |
| InstructionCode opcode, FlagsContinuation* cont) { |
| @@ -1375,17 +1415,23 @@ void VisitWordCompare(InstructionSelector* selector, Node* node, |
| // Match immediates on left or right side of comparison. |
| if (g.CanBeImmediate(right)) { |
| - VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), cont); |
| + return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), |
| + cont); |
| } else if (g.CanBeImmediate(left)) { |
| if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); |
| - VisitCompare(selector, opcode, g.Use(right), g.UseImmediate(left), cont); |
| - } else { |
| - VisitCompare(selector, opcode, left, right, cont, |
| - node->op()->HasProperty(Operator::kCommutative)); |
| + return VisitCompare(selector, opcode, g.Use(right), g.UseImmediate(left), |
| + cont); |
| } |
| + // TODO(epertoso): emit memory operands for comparisons againt immediates as |
| + // well. |
| + if (CanUseMemoryOperand(selector, opcode, node, left)) { |
| + return VisitCompareWithMemoryOperand(selector, opcode, left, |
| + g.UseRegister(right), cont); |
| + } |
| + return VisitCompare(selector, opcode, left, right, cont, |
| + node->op()->HasProperty(Operator::kCommutative)); |
| } |
| - |
| // Shared routine for 64-bit word comparison operations. |
| void VisitWord64Compare(InstructionSelector* selector, Node* node, |
| FlagsContinuation* cont) { |