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

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

Issue 2006223004: X87: [x64/ia32] Deal with the non-transitivity of InstructionSelector::CanCover() when folding load… (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 {
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) { 30 bool CanBeMemoryOperand(InstructionCode opcode, Node* node, Node* input,
31 int effect_level) {
31 if (input->opcode() != IrOpcode::kLoad || 32 if (input->opcode() != IrOpcode::kLoad ||
32 !selector()->CanCover(node, input)) { 33 !selector()->CanCover(node, input)) {
33 return false; 34 return false;
34 } 35 }
36 if (effect_level != selector()->GetEffectLevel(input)) {
37 return false;
38 }
35 MachineRepresentation rep = 39 MachineRepresentation rep =
36 LoadRepresentationOf(input->op()).representation(); 40 LoadRepresentationOf(input->op()).representation();
37 switch (opcode) { 41 switch (opcode) {
38 case kX87Cmp: 42 case kX87Cmp:
39 case kX87Test: 43 case kX87Test:
40 return rep == MachineRepresentation::kWord32 || 44 return rep == MachineRepresentation::kWord32 ||
41 rep == MachineRepresentation::kTagged; 45 rep == MachineRepresentation::kTagged;
42 case kX87Cmp16: 46 case kX87Cmp16:
43 case kX87Test16: 47 case kX87Test16:
44 return rep == MachineRepresentation::kWord16; 48 return rep == MachineRepresentation::kWord16;
(...skipping 1216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 1265
1262 // Shared routine for multiple word compare operations. 1266 // Shared routine for multiple word compare operations.
1263 void VisitWordCompare(InstructionSelector* selector, Node* node, 1267 void VisitWordCompare(InstructionSelector* selector, Node* node,
1264 InstructionCode opcode, FlagsContinuation* cont) { 1268 InstructionCode opcode, FlagsContinuation* cont) {
1265 X87OperandGenerator g(selector); 1269 X87OperandGenerator g(selector);
1266 Node* left = node->InputAt(0); 1270 Node* left = node->InputAt(0);
1267 Node* right = node->InputAt(1); 1271 Node* right = node->InputAt(1);
1268 1272
1269 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right); 1273 InstructionCode narrowed_opcode = TryNarrowOpcodeSize(opcode, left, right);
1270 1274
1275 int effect_level = selector->GetEffectLevel(node);
1276 if (cont->IsBranch()) {
1277 effect_level = selector->GetEffectLevel(
1278 cont->true_block()->PredecessorAt(0)->control_input());
1279 }
1280
1271 // If one of the two inputs is an immediate, make sure it's on the right, or 1281 // If one of the two inputs is an immediate, make sure it's on the right, or
1272 // if one of the two inputs is a memory operand, make sure it's on the left. 1282 // if one of the two inputs is a memory operand, make sure it's on the left.
1273 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) || 1283 if ((!g.CanBeImmediate(right) && g.CanBeImmediate(left)) ||
1274 (g.CanBeMemoryOperand(narrowed_opcode, node, right) && 1284 (g.CanBeMemoryOperand(narrowed_opcode, node, right, effect_level) &&
1275 !g.CanBeMemoryOperand(narrowed_opcode, node, left))) { 1285 !g.CanBeMemoryOperand(narrowed_opcode, node, left, effect_level))) {
1276 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1286 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
1277 std::swap(left, right); 1287 std::swap(left, right);
1278 } 1288 }
1279 1289
1280 // Match immediates on right side of comparison. 1290 // Match immediates on right side of comparison.
1281 if (g.CanBeImmediate(right)) { 1291 if (g.CanBeImmediate(right)) {
1282 if (g.CanBeMemoryOperand(opcode, node, left)) { 1292 if (g.CanBeMemoryOperand(opcode, node, left, effect_level)) {
1283 // TODO(epertoso): we should use `narrowed_opcode' here once we match 1293 // TODO(epertoso): we should use `narrowed_opcode' here once we match
1284 // immediates too. 1294 // immediates too.
1285 return VisitCompareWithMemoryOperand(selector, opcode, left, 1295 return VisitCompareWithMemoryOperand(selector, opcode, left,
1286 g.UseImmediate(right), cont); 1296 g.UseImmediate(right), cont);
1287 } 1297 }
1288 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right), 1298 return VisitCompare(selector, opcode, g.Use(left), g.UseImmediate(right),
1289 cont); 1299 cont);
1290 } 1300 }
1291 1301
1292 // Match memory operands on left side of comparison. 1302 // Match memory operands on left side of comparison.
1293 if (g.CanBeMemoryOperand(narrowed_opcode, node, left)) { 1303 if (g.CanBeMemoryOperand(narrowed_opcode, node, left, effect_level)) {
1294 bool needs_byte_register = 1304 bool needs_byte_register =
1295 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8; 1305 narrowed_opcode == kX87Test8 || narrowed_opcode == kX87Cmp8;
1296 return VisitCompareWithMemoryOperand( 1306 return VisitCompareWithMemoryOperand(
1297 selector, narrowed_opcode, left, 1307 selector, narrowed_opcode, left,
1298 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right), 1308 needs_byte_register ? g.UseByteRegister(right) : g.UseRegister(right),
1299 cont); 1309 cont);
1300 } 1310 }
1301 1311
1302 if (g.CanBeBetterLeftOperand(right)) { 1312 if (g.CanBeBetterLeftOperand(right)) {
1303 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute(); 1313 if (!node->op()->HasProperty(Operator::kCommutative)) cont->Commute();
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after
1676 // static 1686 // static
1677 MachineOperatorBuilder::AlignmentRequirements 1687 MachineOperatorBuilder::AlignmentRequirements
1678 InstructionSelector::AlignmentRequirements() { 1688 InstructionSelector::AlignmentRequirements() {
1679 return MachineOperatorBuilder::AlignmentRequirements:: 1689 return MachineOperatorBuilder::AlignmentRequirements::
1680 FullUnalignedAccessSupport(); 1690 FullUnalignedAccessSupport();
1681 } 1691 }
1682 1692
1683 } // namespace compiler 1693 } // namespace compiler
1684 } // namespace internal 1694 } // namespace internal
1685 } // namespace v8 1695 } // 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