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

Side by Side Diff: src/compiler/x87/instruction-selector-x87.cc

Issue 1883373002: X87: [ia32] Byte and word memory operands in ia32 cmp/test. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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 unified diff | Download patch
« no previous file with comments | « src/compiler/x87/instruction-codes-x87.h ('k') | src/x87/assembler-x87.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/base/adapters.h" 5 #include "src/base/adapters.h"
6 #include "src/compiler/instruction-selector-impl.h" 6 #include "src/compiler/instruction-selector-impl.h"
7 #include "src/compiler/node-matchers.h" 7 #include "src/compiler/node-matchers.h"
8 #include "src/compiler/node-properties.h" 8 #include "src/compiler/node-properties.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 namespace compiler { 12 namespace compiler {
13 13
14 // Adds X87-specific methods for generating operands. 14 // Adds X87-specific methods for generating operands.
15 class X87OperandGenerator final : public OperandGenerator { 15 class X87OperandGenerator final : public OperandGenerator {
16 public: 16 public:
17 explicit X87OperandGenerator(InstructionSelector* selector) 17 explicit X87OperandGenerator(InstructionSelector* selector)
18 : OperandGenerator(selector) {} 18 : OperandGenerator(selector) {}
19 19
20 InstructionOperand UseByteRegister(Node* node) { 20 InstructionOperand UseByteRegister(Node* node) {
21 // TODO(titzer): encode byte register use constraints. 21 // TODO(titzer): encode byte register use constraints.
22 return UseFixed(node, edx); 22 return UseFixed(node, edx);
23 } 23 }
24 24
25 InstructionOperand DefineAsByteRegister(Node* node) { 25 InstructionOperand DefineAsByteRegister(Node* node) {
26 // TODO(titzer): encode byte register def constraints. 26 // TODO(titzer): encode byte register def constraints.
27 return DefineAsRegister(node); 27 return DefineAsRegister(node);
28 } 28 }
29 29
30 bool CanBeMemoryOperand(InstructionCode opcode, Node* node, Node* input) {
31 if (input->opcode() != IrOpcode::kLoad ||
32 !selector()->CanCover(node, input)) {
33 return false;
34 }
35 MachineRepresentation rep =
36 LoadRepresentationOf(input->op()).representation();
37 switch (opcode) {
38 case kX87Cmp:
39 case kX87Test:
40 return rep == MachineRepresentation::kWord32 ||
41 rep == MachineRepresentation::kTagged;
42 case kX87Cmp16:
43 case kX87Test16:
44 return rep == MachineRepresentation::kWord16;
45 case kX87Cmp8:
46 case kX87Test8:
47 return rep == MachineRepresentation::kWord8;
48 default:
49 break;
50 }
51 return false;
52 }
53
30 InstructionOperand CreateImmediate(int imm) { 54 InstructionOperand CreateImmediate(int imm) {
31 return sequence()->AddImmediate(Constant(imm)); 55 return sequence()->AddImmediate(Constant(imm));
32 } 56 }
33 57
34 bool CanBeImmediate(Node* node) { 58 bool CanBeImmediate(Node* node) {
35 switch (node->opcode()) { 59 switch (node->opcode()) {
36 case IrOpcode::kInt32Constant: 60 case IrOpcode::kInt32Constant:
37 case IrOpcode::kNumberConstant: 61 case IrOpcode::kNumberConstant:
38 case IrOpcode::kExternalConstant: 62 case IrOpcode::kExternalConstant:
39 return true; 63 return true;
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after
1112 } else if (cont->IsDeoptimize()) { 1136 } else if (cont->IsDeoptimize()) {
1113 selector->EmitDeoptimize(opcode, 0, nullptr, input_count, inputs, 1137 selector->EmitDeoptimize(opcode, 0, nullptr, input_count, inputs,
1114 cont->frame_state()); 1138 cont->frame_state());
1115 } else { 1139 } else {
1116 DCHECK(cont->IsSet()); 1140 DCHECK(cont->IsSet());
1117 InstructionOperand output = g.DefineAsRegister(cont->result()); 1141 InstructionOperand output = g.DefineAsRegister(cont->result());
1118 selector->Emit(opcode, 1, &output, input_count, inputs); 1142 selector->Emit(opcode, 1, &output, input_count, inputs);
1119 } 1143 }
1120 } 1144 }
1121 1145
1122 // Determines if {input} of {node} can be replaced by a memory operand.
1123 bool CanUseMemoryOperand(InstructionSelector* selector, InstructionCode opcode,
1124 Node* node, Node* input) {
1125 if (input->opcode() != IrOpcode::kLoad || !selector->CanCover(node, input)) {
1126 return false;
1127 }
1128 MachineRepresentation load_representation =
1129 LoadRepresentationOf(input->op()).representation();
1130 if (load_representation == MachineRepresentation::kWord32 ||
1131 load_representation == MachineRepresentation::kTagged) {
1132 return opcode == kX87Cmp || opcode == kX87Test;
1133 }
1134 return false;
1135 }
1136
1137 // Shared routine for multiple compare operations. 1146 // Shared routine for multiple compare operations.
1138 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, 1147 void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
1139 InstructionOperand left, InstructionOperand right, 1148 InstructionOperand left, InstructionOperand right,
1140 FlagsContinuation* cont) { 1149 FlagsContinuation* cont) {
1141 X87OperandGenerator g(selector); 1150 X87OperandGenerator g(selector);
1142 opcode = cont->Encode(opcode); 1151 opcode = cont->Encode(opcode);
1143 if (cont->IsBranch()) { 1152 if (cont->IsBranch()) {
1144 selector->Emit(opcode, g.NoOutput(), left, right, 1153 selector->Emit(opcode, g.NoOutput(), left, right,
1145 g.Label(cont->true_block()), g.Label(cont->false_block())); 1154 g.Label(cont->true_block()), g.Label(cont->false_block()));
1146 } else if (cont->IsDeoptimize()) { 1155 } else if (cont->IsDeoptimize()) {
(...skipping 10 matching lines...) Expand all
1157 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, 1166 void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
1158 Node* left, Node* right, FlagsContinuation* cont, 1167 Node* left, Node* right, FlagsContinuation* cont,
1159 bool commutative) { 1168 bool commutative) {
1160 X87OperandGenerator g(selector); 1169 X87OperandGenerator g(selector);
1161 if (commutative && g.CanBeBetterLeftOperand(right)) { 1170 if (commutative && g.CanBeBetterLeftOperand(right)) {
1162 std::swap(left, right); 1171 std::swap(left, right);
1163 } 1172 }
1164 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); 1173 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
1165 } 1174 }
1166 1175
1176 // Tries to match the size of the given opcode to that of the operands, if
1177 // possible.
1178 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left,
1179 Node* right) {
1180 if (opcode != kX87Cmp && opcode != kX87Test) {
1181 return opcode;
1182 }
1183 // Currently, if one of the two operands is not a Load, we don't know what its
1184 // machine representation is, so we bail out.
1185 // TODO(epertoso): we can probably get some size information out of immediates
1186 // and phi nodes.
1187 if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) {
1188 return opcode;
1189 }
1190 // If the load representations don't match, both operands will be
1191 // zero/sign-extended to 32bit.
1192 LoadRepresentation left_representation = LoadRepresentationOf(left->op());
1193 if (left_representation != LoadRepresentationOf(right->op())) {
1194 return opcode;
1195 }
1196 switch (left_representation.representation()) {
1197 case MachineRepresentation::kBit:
1198 case MachineRepresentation::kWord8:
1199 return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8;
1200 case MachineRepresentation::kWord16:
1201 return opcode == kX87Cmp ? kX87Cmp16 : kX87Test16;
1202 default:
1203 return opcode;
1204 }
1205 }
1167 1206
1168 // Shared routine for multiple float32 compare operations (inputs commuted). 1207 // Shared routine for multiple float32 compare operations (inputs commuted).
1169 void VisitFloat32Compare(InstructionSelector* selector, Node* node, 1208 void VisitFloat32Compare(InstructionSelector* selector, Node* node,
1170 FlagsContinuation* cont) { 1209 FlagsContinuation* cont) {
1171 X87OperandGenerator g(selector); 1210 X87OperandGenerator g(selector);
1172 selector->Emit(kX87PushFloat32, g.NoOutput(), g.Use(node->InputAt(0))); 1211 selector->Emit(kX87PushFloat32, g.NoOutput(), g.Use(node->InputAt(0)));
1173 selector->Emit(kX87PushFloat32, g.NoOutput(), g.Use(node->InputAt(1))); 1212 selector->Emit(kX87PushFloat32, g.NoOutput(), g.Use(node->InputAt(1)));
1174 if (cont->IsBranch()) { 1213 if (cont->IsBranch()) {
1175 selector->Emit(cont->Encode(kX87Float32Cmp), g.NoOutput(), 1214 selector->Emit(cont->Encode(kX87Float32Cmp), g.NoOutput(),
1176 g.Label(cont->true_block()), g.Label(cont->false_block())); 1215 g.Label(cont->true_block()), g.Label(cont->false_block()));
(...skipping 29 matching lines...) Expand all
1206 } 1245 }
1207 } 1246 }
1208 1247
1209 // Shared routine for multiple word compare operations. 1248 // Shared routine for multiple word compare operations.
1210 void VisitWordCompare(InstructionSelector* selector, Node* node, 1249 void VisitWordCompare(InstructionSelector* selector, Node* node,
1211 InstructionCode opcode, FlagsContinuation* cont) { 1250 InstructionCode opcode, FlagsContinuation* cont) {
1212 X87OperandGenerator g(selector); 1251 X87OperandGenerator g(selector);
1213 Node* left = node->InputAt(0); 1252 Node* left = node->InputAt(0);
1214 Node* right = node->InputAt(1); 1253 Node* right = node->InputAt(1);
1215 1254
1216 // If one of the two inputs is an immediate, make sure it's on the right. 1255 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right);
1217 if (!g.CanBeImmediate(right) && g.CanBeImmediate(left)) { 1256
1257 // If one of the two inputs is an immediate, make sure it's on the right, or
1258 // if one of the two inputs is a memory operand, make sure it's on the left.
1259 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) ||
1260 (g.CanBeMemoryOperand(narrowed_opcode, node, right) &&
1261 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) {
1218 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1262 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
1219 std::swap(left, right); 1263 std::swap(left, right);
1220 } 1264 }
1221 1265
1222 // Match immediates on right side of comparison. 1266 // Match immediates on right side of comparison.
1223 if (g.CanBeImmediate(right)) { 1267 if (g.CanBeImmediate(right)) {
1224 if (CanUseMemoryOperand(selector, opcode, node, left)) { 1268 if (g.CanBeMemoryOperand(opcode, node, left)) {
1269 // TODO(epertoso): we should use `narrowed_opcode' here once we match
1270 // immediates too.
1225 return VisitCompareWithMemoryOperand(selector, opcode, left, 1271 return VisitCompareWithMemoryOperand(selector, opcode, left,
1226 g.UseImmediate(right), cont); 1272 g.UseImmediate(right), cont);
1227 } 1273 }
1228 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), 1274 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right),
1229 cont); 1275 cont);
1230 } 1276 }
1231 1277
1278 // Match memory operands on left side of comparison.
1279 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) {
1280 bool needs_byte_register =
1281 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8;
1282 return VisitCompareWithMemoryOperand(
1283 selector, narrowed_opcode, left,
1284 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right),
1285 cont);
1286 }
1287
1232 if (g.CanBeBetterLeftOperand(right)) { 1288 if (g.CanBeBetterLeftOperand(right)) {
1233 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1289 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
1234 std::swap(left, right); 1290 std::swap(left, right);
1235 } 1291 }
1236 1292
1237 if (CanUseMemoryOperand(selector, opcode, node, left)) {
1238 return VisitCompareWithMemoryOperand(selector, opcode, left,
1239 g.UseRegister(right), cont);
1240 }
1241 return VisitCompare(selector, opcode, left, right, cont, 1293 return VisitCompare(selector, opcode, left, right, cont,
1242 node->op()->HasProperty(Operator::kCommutative)); 1294 node->op()->HasProperty(Operator::kCommutative));
1243 } 1295 }
1244 1296
1245 void VisitWordCompare(InstructionSelector* selector, Node* node, 1297 void VisitWordCompare(InstructionSelector* selector, Node* node,
1246 FlagsContinuation* cont) { 1298 FlagsContinuation* cont) {
1247 X87OperandGenerator g(selector); 1299 X87OperandGenerator g(selector);
1248 Int32BinopMatcher m(node); 1300 Int32BinopMatcher m(node);
1249 if (m.left().IsLoad() && m.right().IsLoadStackPointer()) { 1301 if (m.left().IsLoad() && m.right().IsLoadStackPointer()) {
1250 LoadMatcher<ExternalReferenceMatcher> mleft(m.left().node()); 1302 LoadMatcher<ExternalReferenceMatcher> mleft(m.left().node());
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after
1557 MachineOperatorBuilder::kFloat32RoundTruncate | 1609 MachineOperatorBuilder::kFloat32RoundTruncate |
1558 MachineOperatorBuilder::kFloat64RoundTruncate | 1610 MachineOperatorBuilder::kFloat64RoundTruncate |
1559 MachineOperatorBuilder::kFloat32RoundTiesEven | 1611 MachineOperatorBuilder::kFloat32RoundTiesEven |
1560 MachineOperatorBuilder::kFloat64RoundTiesEven; 1612 MachineOperatorBuilder::kFloat64RoundTiesEven;
1561 return flags; 1613 return flags;
1562 } 1614 }
1563 1615
1564 } // namespace compiler 1616 } // namespace compiler
1565 } // namespace internal 1617 } // namespace internal
1566 } // namespace v8 1618 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/x87/instruction-codes-x87.h ('k') | src/x87/assembler-x87.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698