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

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

Issue 1968453002: [turbofan] Take the immediate size in account when narrowing ia32/x64 word comparison operators. (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 | src/compiler/x64/instruction-selector-x64.cc » ('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 {
(...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1165 void VisitCompare(InstructionSelector* selector, InstructionCode opcode, 1165 void VisitCompare(InstructionSelector* selector, InstructionCode opcode,
1166 Node* left, Node* right, FlagsContinuation* cont, 1166 Node* left, Node* right, FlagsContinuation* cont,
1167 bool commutative) { 1167 bool commutative) {
1168 IA32OperandGenerator g(selector); 1168 IA32OperandGenerator g(selector);
1169 if (commutative && g.CanBeBetterLeftOperand(right)) { 1169 if (commutative && g.CanBeBetterLeftOperand(right)) {
1170 std::swap(left, right); 1170 std::swap(left, right);
1171 } 1171 }
1172 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont); 1172 VisitCompare(selector, opcode, g.UseRegister(left), g.Use(right), cont);
1173 } 1173 }
1174 1174
1175 bool InferMachineRepresentation(Node* node,
1176 MachineRepresentation* representation) {
1177 if (node->opcode() == IrOpcode::kLoad) {
1178 *representation = LoadRepresentationOf(node->op()).representation();
1179 return true;
1180 }
1181 if (node->opcode() != IrOpcode::kInt32Constant) {
1182 return false;
1183 }
1184 int32_t value = OpParameter<int32_t>(node->op());
1185 if (is_int8(value)) {
1186 *representation = MachineRepresentation::kWord8;
1187 } else if (is_int16(value)) {
1188 *representation = MachineRepresentation::kWord16;
1189 } else {
1190 *representation = MachineRepresentation::kWord32;
1191 }
1192 return true;
1193 }
1194
1175 // Tries to match the size of the given opcode to that of the operands, if 1195 // Tries to match the size of the given opcode to that of the operands, if
1176 // possible. 1196 // possible.
1177 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, 1197 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left,
1178 Node* right) { 1198 Node* right) {
1179 if (opcode != kIA32Cmp && opcode != kIA32Test) { 1199 if (opcode != kIA32Cmp && opcode != kIA32Test) {
1180 return opcode; 1200 return opcode;
1181 } 1201 }
1182 // Currently, if one of the two operands is not a Load, we don't know what its 1202 // We only do this if at least one of the two operands is a load.
1183 // machine representation is, so we bail out. 1203 // TODO(epertoso): we can probably get some size information out of phi nodes.
1184 // TODO(epertoso): we can probably get some size information out of immediates 1204 if (left->opcode() != IrOpcode::kLoad && right->opcode() != IrOpcode::kLoad) {
1185 // and phi nodes.
1186 if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) {
1187 return opcode; 1205 return opcode;
1188 } 1206 }
1189 // If the load representations don't match, both operands will be 1207 MachineRepresentation left_representation, right_representation;
1190 // zero/sign-extended to 32bit. 1208 if (!InferMachineRepresentation(left, &left_representation) ||
1191 LoadRepresentation left_representation = LoadRepresentationOf(left->op()); 1209 !InferMachineRepresentation(right, &right_representation)) {
1192 if (left_representation != LoadRepresentationOf(right->op())) {
1193 return opcode; 1210 return opcode;
1194 } 1211 }
1195 switch (left_representation.representation()) { 1212 // If the representations don't match, both operands will be
1213 // zero/sign-extended to 32bit.
1214 if (left_representation != right_representation) {
1215 return opcode;
1216 }
1217 switch (left_representation) {
1196 case MachineRepresentation::kBit: 1218 case MachineRepresentation::kBit:
1197 case MachineRepresentation::kWord8: 1219 case MachineRepresentation::kWord8:
1198 return opcode == kIA32Cmp ? kIA32Cmp8 : kIA32Test8; 1220 return opcode == kIA32Cmp ? kIA32Cmp8 : kIA32Test8;
1199 case MachineRepresentation::kWord16: 1221 case MachineRepresentation::kWord16:
1200 return opcode == kIA32Cmp ? kIA32Cmp16 : kIA32Test16; 1222 return opcode == kIA32Cmp ? kIA32Cmp16 : kIA32Test16;
1201 default: 1223 default:
1202 return opcode; 1224 return opcode;
1203 } 1225 }
1204 } 1226 }
1205 1227
(...skipping 27 matching lines...) Expand all
1233 // if one of the two inputs is a memory operand, make sure it's on the left. 1255 // if one of the two inputs is a memory operand, make sure it's on the left.
1234 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || 1256 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) ||
1235 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && 1257 (g.CanBeMemoryOperand(narrowed_opcode, node, right) &&
1236 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { 1258 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) {
1237 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1259 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
1238 std::swap(left, right); 1260 std::swap(left, right);
1239 } 1261 }
1240 1262
1241 // Match immediates on right side of comparison. 1263 // Match immediates on right side of comparison.
1242 if (g.CanBeImmediate(right)) { 1264 if (g.CanBeImmediate(right)) {
1243 if (g.CanBeMemoryOperand(opcode, node, left)) { 1265 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) {
1244 // TODO(epertoso): we should use `narrowed_opcode' here once we match 1266 // If we're truncating the immediate (32 bits to 16 or 8), comparison
1245 // immediates too. 1267 // semantics should take the signedness/unsignedness of the op into
1246 return VisitCompareWithMemoryOperand(selector, opcode, left, 1268 // account.
1269 if (narrowed_opcode != opcode &&
1270 LoadRepresentationOf(left->op()).IsUnsigned()) {
1271 switch (cont->condition()) {
1272 case FlagsCondition::kSignedLessThan:
1273 cont->OverwriteAndNegateIfEqual(FlagsCondition::kUnsignedLessThan);
1274 break;
1275 case FlagsCondition::kSignedGreaterThan:
1276 cont->OverwriteAndNegateIfEqual(
1277 FlagsCondition::kUnsignedGreaterThan);
1278 break;
1279 case FlagsCondition::kSignedLessThanOrEqual:
1280 cont->OverwriteAndNegateIfEqual(
1281 FlagsCondition::kUnsignedLessThanOrEqual);
1282 break;
1283 case FlagsCondition::kSignedGreaterThanOrEqual:
1284 cont->OverwriteAndNegateIfEqual(
1285 FlagsCondition::kUnsignedGreaterThanOrEqual);
1286 break;
1287 default:
1288 break;
1289 }
1290 }
1291 return VisitCompareWithMemoryOperand(selector, narrowed_opcode, left,
1247 g.UseImmediate(right), cont); 1292 g.UseImmediate(right), cont);
1248 } 1293 }
1249 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), 1294 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right),
1250 cont); 1295 cont);
1251 } 1296 }
1252 1297
1253 // Match memory operands on left side of comparison. 1298 // Match memory operands on left side of comparison.
1254 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { 1299 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) {
1255 bool needs_byte_register = 1300 bool needs_byte_register =
1256 narrowed_opcode == kIA32Test8 || narrowed_opcode == kIA32Cmp8; 1301 narrowed_opcode == kIA32Test8 || narrowed_opcode == kIA32Cmp8;
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1636 MachineOperatorBuilder::kFloat64RoundTruncate | 1681 MachineOperatorBuilder::kFloat64RoundTruncate |
1637 MachineOperatorBuilder::kFloat32RoundTiesEven | 1682 MachineOperatorBuilder::kFloat32RoundTiesEven |
1638 MachineOperatorBuilder::kFloat64RoundTiesEven; 1683 MachineOperatorBuilder::kFloat64RoundTiesEven;
1639 } 1684 }
1640 return flags; 1685 return flags;
1641 } 1686 }
1642 1687
1643 } // namespace compiler 1688 } // namespace compiler
1644 } // namespace internal 1689 } // namespace internal
1645 } // namespace v8 1690 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/compiler/x64/instruction-selector-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698