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

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

Issue 1967913003: X87: [turbofan] Take the immediate size in account when narrowing ia32/x64 word comparison operator… (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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 | « no previous file | no next file » | 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 {
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, 1167 void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
1168 Node* left, Node* right, FlagsContinuation* cont, 1168 Node* left, Node* right, FlagsContinuation* cont,
1169 bool commutative) { 1169 bool commutative) {
1170 X87OperandGenerator g(selector); 1170 X87OperandGenerator g(selector);
1171 if (commutative && g.CanBeBetterLeftOperand(right)) { 1171 if (commutative && g.CanBeBetterLeftOperand(right)) {
1172 std::swap(left, right); 1172 std::swap(left, right);
1173 } 1173 }
1174 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); 1174 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
1175 } 1175 }
1176 1176
1177 bool InferMachineRepresentation(Node* node,
1178 MachineRepresentation* representation) {
1179 if (node->opcode() == IrOpcode::kLoad) {
1180 *representation = LoadRepresentationOf(node->op()).representation();
1181 return true;
1182 }
1183 if (node->opcode() != IrOpcode::kInt32Constant) {
1184 return false;
1185 }
1186 int32_t value = OpParameter<int32_t>(node->op());
1187 if (is_int8(value)) {
1188 *representation = MachineRepresentation::kWord8;
1189 } else if (is_int16(value)) {
1190 *representation = MachineRepresentation::kWord16;
1191 } else {
1192 *representation = MachineRepresentation::kWord32;
1193 }
1194 return true;
1195 }
1196
1177 // Tries to match the size of the given opcode to that of the operands, if 1197 // Tries to match the size of the given opcode to that of the operands, if
1178 // possible. 1198 // possible.
1179 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, 1199 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left,
1180 Node* right) { 1200 Node* right) {
1181 if (opcode != kX87Cmp && opcode != kX87Test) { 1201 if (opcode != kX87Cmp && opcode != kX87Test) {
1182 return opcode; 1202 return opcode;
1183 } 1203 }
1184 // Currently, if one of the two operands is not a Load, we don't know what its 1204 // We only do this if at least one of the two operands is a load.
1185 // machine representation is, so we bail out. 1205 // TODO(epertoso): we can probably get some size information out of phi nodes.
1186 // TODO(epertoso): we can probably get some size information out of immediates 1206 if (left->opcode() != IrOpcode::kLoad && right->opcode() != IrOpcode::kLoad) {
1187 // and phi nodes.
1188 if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) {
1189 return opcode; 1207 return opcode;
1190 } 1208 }
1191 // If the load representations don't match, both operands will be 1209 MachineRepresentation left_representation, right_representation;
1192 // zero/sign-extended to 32bit. 1210 if (!InferMachineRepresentation(left, &left_representation) ||
1193 LoadRepresentation left_representation = LoadRepresentationOf(left->op()); 1211 !InferMachineRepresentation(right, &right_representation)) {
1194 if (left_representation != LoadRepresentationOf(right->op())) {
1195 return opcode; 1212 return opcode;
1196 } 1213 }
1197 switch (left_representation.representation()) { 1214 // If the representations don't match, both operands will be
1215 // zero/sign-extended to 32bit.
1216 if (left_representation != right_representation) {
1217 return opcode;
1218 }
1219 switch (left_representation) {
1198 case MachineRepresentation::kBit: 1220 case MachineRepresentation::kBit:
1199 case MachineRepresentation::kWord8: 1221 case MachineRepresentation::kWord8:
1200 return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8; 1222 return opcode == kX87Cmp ? kX87Cmp8 : kX87Test8;
1201 case MachineRepresentation::kWord16: 1223 case MachineRepresentation::kWord16:
1202 return opcode == kX87Cmp ? kX87Cmp16 : kX87Test16; 1224 return opcode == kX87Cmp ? kX87Cmp16 : kX87Test16;
1203 default: 1225 default:
1204 return opcode; 1226 return opcode;
1205 } 1227 }
1206 } 1228 }
1207 1229
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1259 // if one of the two inputs is a memory operand, make sure it's on the left. 1281 // if one of the two inputs is a memory operand, make sure it's on the left.
1260 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || 1282 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) ||
1261 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && 1283 (g.CanBeMemoryOperand(narrowed_opcode, node, right) &&
1262 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { 1284 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) {
1263 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1285 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
1264 std::swap(left, right); 1286 std::swap(left, right);
1265 } 1287 }
1266 1288
1267 // Match immediates on right side of comparison. 1289 // Match immediates on right side of comparison.
1268 if (g.CanBeImmediate(right)) { 1290 if (g.CanBeImmediate(right)) {
1269 if (g.CanBeMemoryOperand(opcode, node, left)) { 1291 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) {
1270 // TODO(epertoso): we should use `narrowed_opcode' here once we match 1292 // If we're truncating the immediate (32 bits to 16 or 8), comparison
1271 // immediates too. 1293 // semantics should take the signedness/unsignedness of the op into
1272 return VisitCompareWithMemoryOperand(selector, opcode, left, 1294 // account.
1295 if (narrowed_opcode != opcode &&
1296 LoadRepresentationOf(left->op()).IsUnsigned()) {
1297 switch (cont->condition()) {
1298 case FlagsCondition::kSignedLessThan:
1299 cont->OverwriteAndNegateIfEqual(FlagsCondition::kUnsignedLessThan);
1300 break;
1301 case FlagsCondition::kSignedGreaterThan:
1302 cont->OverwriteAndNegateIfEqual(
1303 FlagsCondition::kUnsignedGreaterThan);
1304 break;
1305 case FlagsCondition::kSignedLessThanOrEqual:
1306 cont->OverwriteAndNegateIfEqual(
1307 FlagsCondition::kUnsignedLessThanOrEqual);
1308 break;
1309 case FlagsCondition::kSignedGreaterThanOrEqual:
1310 cont->OverwriteAndNegateIfEqual(
1311 FlagsCondition::kUnsignedGreaterThanOrEqual);
1312 break;
1313 default:
1314 break;
1315 }
1316 }
1317 return VisitCompareWithMemoryOperand(selector, narrowed_opcode, left,
1273 g.UseImmediate(right), cont); 1318 g.UseImmediate(right), cont);
1274 } 1319 }
1275 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), 1320 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right),
1276 cont); 1321 cont);
1277 } 1322 }
1278 1323
1279 // Match memory operands on left side of comparison. 1324 // Match memory operands on left side of comparison.
1280 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { 1325 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) {
1281 bool needs_byte_register = 1326 bool needs_byte_register =
1282 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8; 1327 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8;
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1656 MachineOperatorBuilder::kFloat32RoundTruncate | 1701 MachineOperatorBuilder::kFloat32RoundTruncate |
1657 MachineOperatorBuilder::kFloat64RoundTruncate | 1702 MachineOperatorBuilder::kFloat64RoundTruncate |
1658 MachineOperatorBuilder::kFloat32RoundTiesEven | 1703 MachineOperatorBuilder::kFloat32RoundTiesEven |
1659 MachineOperatorBuilder::kFloat64RoundTiesEven; 1704 MachineOperatorBuilder::kFloat64RoundTiesEven;
1660 return flags; 1705 return flags;
1661 } 1706 }
1662 1707
1663 } // namespace compiler 1708 } // namespace compiler
1664 } // namespace internal 1709 } // namespace internal
1665 } // namespace v8 1710 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698