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

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

Issue 1995303003: Revert of [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
1195 // Tries to match the size of the given opcode to that of the operands, if 1175 // Tries to match the size of the given opcode to that of the operands, if
1196 // possible. 1176 // possible.
1197 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left, 1177 InstructionCode TryNarrowOpcodeSize(InstructionCode opcode, Node* left,
1198 Node* right) { 1178 Node* right) {
1199 if (opcode != kIA32Cmp && opcode != kIA32Test) { 1179 if (opcode != kIA32Cmp && opcode != kIA32Test) {
1200 return opcode; 1180 return opcode;
1201 } 1181 }
1202 // We only do this if at least one of the two operands is a load. 1182 // Currently, if one of the two operands is not a Load, we don't know what its
1203 // TODO(epertoso): we can probably get some size information out of phi nodes. 1183 // machine representation is, so we bail out.
1204 if (left->opcode() != IrOpcode::kLoad && right->opcode() != IrOpcode::kLoad) { 1184 // TODO(epertoso): we can probably get some size information out of immediates
1185 // and phi nodes.
1186 if (left->opcode() != IrOpcode::kLoad || right->opcode() != IrOpcode::kLoad) {
1205 return opcode; 1187 return opcode;
1206 } 1188 }
1207 MachineRepresentation left_representation, right_representation; 1189 // If the load representations don't match, both operands will be
1208 if (!InferMachineRepresentation(left, &left_representation) || 1190 // zero/sign-extended to 32bit.
1209 !InferMachineRepresentation(right, &right_representation)) { 1191 LoadRepresentation left_representation = LoadRepresentationOf(left->op());
1192 if (left_representation != LoadRepresentationOf(right->op())) {
1210 return opcode; 1193 return opcode;
1211 } 1194 }
1212 // If the representations don't match, both operands will be 1195 switch (left_representation.representation()) {
1213 // zero/sign-extended to 32bit.
1214 if (left_representation != right_representation) {
1215 return opcode;
1216 }
1217 switch (left_representation) {
1218 case MachineRepresentation::kBit: 1196 case MachineRepresentation::kBit:
1219 case MachineRepresentation::kWord8: 1197 case MachineRepresentation::kWord8:
1220 return opcode == kIA32Cmp ? kIA32Cmp8 : kIA32Test8; 1198 return opcode == kIA32Cmp ? kIA32Cmp8 : kIA32Test8;
1221 case MachineRepresentation::kWord16: 1199 case MachineRepresentation::kWord16:
1222 return opcode == kIA32Cmp ? kIA32Cmp16 : kIA32Test16; 1200 return opcode == kIA32Cmp ? kIA32Cmp16 : kIA32Test16;
1223 default: 1201 default:
1224 return opcode; 1202 return opcode;
1225 } 1203 }
1226 } 1204 }
1227 1205
(...skipping 27 matching lines...) Expand all
1255 // if one of the two inputs is a memory operand, make sure it's on the left. 1233 // if one of the two inputs is a memory operand, make sure it's on the left.
1256 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || 1234 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) ||
1257 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && 1235 (g.CanBeMemoryOperand(narrowed_opcode, node, right) &&
1258 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { 1236 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) {
1259 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1237 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
1260 std::swap(left, right); 1238 std::swap(left, right);
1261 } 1239 }
1262 1240
1263 // Match immediates on right side of comparison. 1241 // Match immediates on right side of comparison.
1264 if (g.CanBeImmediate(right)) { 1242 if (g.CanBeImmediate(right)) {
1265 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { 1243 if (g.CanBeMemoryOperand(opcode, node, left)) {
1266 // If we're truncating the immediate (32 bits to 16 or 8), comparison 1244 // TODO(epertoso): we should use `narrowed_opcode' here once we match
1267 // semantics should take the signedness/unsignedness of the op into 1245 // immediates too.
1268 // account. 1246 return VisitCompareWithMemoryOperand(selector, opcode, left,
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,
1292 g.UseImmediate(right), cont); 1247 g.UseImmediate(right), cont);
1293 } 1248 }
1294 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), 1249 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right),
1295 cont); 1250 cont);
1296 } 1251 }
1297 1252
1298 // Match memory operands on left side of comparison. 1253 // Match memory operands on left side of comparison.
1299 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { 1254 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) {
1300 bool needs_byte_register = 1255 bool needs_byte_register =
1301 narrowed_opcode == kIA32Test8 || narrowed_opcode == kIA32Cmp8; 1256 narrowed_opcode == kIA32Test8 || narrowed_opcode == kIA32Cmp8;
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
1681 MachineOperatorBuilder::kFloat64RoundTruncate | 1636 MachineOperatorBuilder::kFloat64RoundTruncate |
1682 MachineOperatorBuilder::kFloat32RoundTiesEven | 1637 MachineOperatorBuilder::kFloat32RoundTiesEven |
1683 MachineOperatorBuilder::kFloat64RoundTiesEven; 1638 MachineOperatorBuilder::kFloat64RoundTiesEven;
1684 } 1639 }
1685 return flags; 1640 return flags;
1686 } 1641 }
1687 1642
1688 } // namespace compiler 1643 } // namespace compiler
1689 } // namespace internal 1644 } // namespace internal
1690 } // namespace v8 1645 } // 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