Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(101)

Unified Diff: src/compiler/x64/instruction-selector-x64.cc

Issue 1780193003: [turbofan] Byte and word memory operands in x64 cmp/test. Fixes arithmetic_op_8 in assembler-x64.cc (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fixes cmpb. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/x64/instruction-scheduler-x64.cc ('k') | src/x64/assembler-x64.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 cdd2b052eadf68cca0bb0fad1527945cdb384a37..ecb99f34f4618903d1e0c77622611d274e2cfab4 100644
--- a/src/compiler/x64/instruction-selector-x64.cc
+++ b/src/compiler/x64/instruction-selector-x64.cc
@@ -43,11 +43,22 @@ class X64OperandGenerator final : public OperandGenerator {
}
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;
+ switch (opcode) {
+ case kX64Cmp:
+ case kX64Test:
+ return rep == MachineRepresentation::kWord64 ||
+ rep == MachineRepresentation::kTagged;
+ case kX64Cmp32:
+ case kX64Test32:
+ return rep == MachineRepresentation::kWord32;
+ case kX64Cmp16:
+ case kX64Test16:
+ return rep == MachineRepresentation::kWord16;
+ case kX64Cmp8:
+ case kX64Test8:
+ return rep == MachineRepresentation::kWord8;
+ default:
+ break;
}
return false;
}
@@ -1416,6 +1427,37 @@ void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
}
+// Tries to match the size of the given opcode to that of the operands, if
+// possible.
+InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left,
+ Node* right) {
+ 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) {
+ return opcode;
+ }
+ // If the load 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())) {
+ return opcode;
+ }
+ switch (left_representation.representation()) {
+ case MachineRepresentation::kBit:
+ case MachineRepresentation::kWord8:
+ return opcode == kX64Cmp32 ? kX64Cmp8 : kX64Test8;
+ case MachineRepresentation::kWord16:
+ return opcode == kX64Cmp32 ? kX64Cmp16 : kX64Test16;
+ default:
+ return opcode;
+ }
+}
+
// Shared routine for multiple word compare operations.
void VisitWordCompare(InstructionSelector* selector, Node* node,
InstructionCode opcode, FlagsContinuation* cont) {
@@ -1423,6 +1465,8 @@ void VisitWordCompare(InstructionSelector* selector, Node* node,
Node* left = node->InputAt(0);
Node* right = node->InputAt(1);
+ 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)) ||
« no previous file with comments | « src/compiler/x64/instruction-scheduler-x64.cc ('k') | src/x64/assembler-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698