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

Side by Side Diff: src/compiler/simplified-lowering.cc

Issue 954173002: [turbofan] Fix simplified lowering of Int32Div. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 9 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/compiler/simplified-lowering.h" 5 #include "src/compiler/simplified-lowering.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "src/base/bits.h" 9 #include "src/base/bits.h"
10 #include "src/code-factory.h" 10 #include "src/code-factory.h"
(...skipping 1293 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 NodeProperties::GetValueInput(node, 1), 1304 NodeProperties::GetValueInput(node, 1),
1305 jsgraph()->ExternalConstant(ref), 1305 jsgraph()->ExternalConstant(ref),
1306 jsgraph()->Int32Constant(2), 1306 jsgraph()->Int32Constant(2),
1307 jsgraph()->UndefinedConstant()); 1307 jsgraph()->UndefinedConstant());
1308 } 1308 }
1309 1309
1310 1310
1311 Node* SimplifiedLowering::Int32Div(Node* const node) { 1311 Node* SimplifiedLowering::Int32Div(Node* const node) {
1312 Int32BinopMatcher m(node); 1312 Int32BinopMatcher m(node);
1313 Node* const zero = jsgraph()->Int32Constant(0); 1313 Node* const zero = jsgraph()->Int32Constant(0);
1314 Node* const minus_one = jsgraph()->Int32Constant(-1);
1314 Node* const lhs = m.left().node(); 1315 Node* const lhs = m.left().node();
1315 Node* const rhs = m.right().node(); 1316 Node* const rhs = m.right().node();
1316 1317
1317 if (m.right().Is(-1)) { 1318 if (m.right().Is(-1)) {
1318 return graph()->NewNode(machine()->Int32Sub(), zero, lhs); 1319 return graph()->NewNode(machine()->Int32Sub(), zero, lhs);
1319 } else if (m.right().Is(0)) { 1320 } else if (m.right().Is(0)) {
1320 return rhs; 1321 return rhs;
1321 } else if (machine()->Int32DivIsSafe() || m.right().HasValue()) { 1322 } else if (machine()->Int32DivIsSafe() || m.right().HasValue()) {
1322 return graph()->NewNode(machine()->Int32Div(), lhs, rhs, graph()->start()); 1323 return graph()->NewNode(machine()->Int32Div(), lhs, rhs, graph()->start());
1323 } 1324 }
1324 1325
1325 Diamond if_zero(graph(), common(), 1326 // General case for signed integer division.
1326 graph()->NewNode(machine()->Word32Equal(), rhs, zero), 1327 //
1327 BranchHint::kFalse); 1328 // if 0 < rhs then
1329 // lhs / rhs
1330 // else
1331 // if rhs < -1 then
1332 // lhs / rhs
1333 // else if rhs == 0 then
1334 // 0
1335 // else
1336 // 0 - lhs
1337 //
1338 // Note: We do not use the Diamond helper class here, because it really hurts
1339 // readability with nested diamonds.
1340 const Operator* const merge_op = common()->Merge(2);
1341 const Operator* const phi_op = common()->Phi(kMachInt32, 2);
1328 1342
1329 Diamond if_minus_one(graph(), common(), 1343 Node* check0 = graph()->NewNode(machine()->Int32LessThan(), zero, rhs);
1330 graph()->NewNode(machine()->Word32Equal(), rhs, 1344 Node* branch0 = graph()->NewNode(common()->Branch(BranchHint::kTrue), check0,
1331 jsgraph()->Int32Constant(-1)), 1345 graph()->start());
1332 BranchHint::kFalse);
1333 if_minus_one.Nest(if_zero, false);
1334 Node* sub = graph()->NewNode(machine()->Int32Sub(), zero, lhs);
1335 Node* div =
1336 graph()->NewNode(machine()->Int32Div(), lhs, rhs, if_minus_one.if_false);
1337 1346
1338 return if_zero.Phi(kMachInt32, zero, if_minus_one.Phi(kMachInt32, sub, div)); 1347 Node* if_true0 = graph()->NewNode(common()->IfTrue(), branch0);
1348 Node* true0 = graph()->NewNode(machine()->Int32Div(), lhs, rhs, if_true0);
1349
1350 Node* if_false0 = graph()->NewNode(common()->IfFalse(), branch0);
1351 Node* false0;
1352 {
1353 Node* check1 = graph()->NewNode(machine()->Int32LessThan(), rhs, minus_one);
1354 Node* branch1 = graph()->NewNode(common()->Branch(), check1, if_false0);
1355
1356 Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1);
1357 Node* true1 = graph()->NewNode(machine()->Int32Div(), lhs, rhs, if_true1);
1358
1359 Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1);
1360 Node* false1;
1361 {
1362 Node* check2 = graph()->NewNode(machine()->Word32Equal(), rhs, zero);
1363 Node* branch2 = graph()->NewNode(common()->Branch(), check2, if_false1);
1364
1365 Node* if_true2 = graph()->NewNode(common()->IfTrue(), branch2);
1366 Node* true2 = zero;
1367
1368 Node* if_false2 = graph()->NewNode(common()->IfFalse(), branch2);
1369 Node* false2 = graph()->NewNode(machine()->Int32Sub(), zero, lhs);
1370
1371 if_false1 = graph()->NewNode(merge_op, if_true2, if_false2);
1372 false1 = graph()->NewNode(phi_op, true2, false2, if_false1);
1373 }
1374
1375 if_false0 = graph()->NewNode(merge_op, if_true1, if_false1);
1376 false0 = graph()->NewNode(phi_op, true1, false1, if_false0);
1377 }
1378
1379 Node* merge0 = graph()->NewNode(merge_op, if_true0, if_false0);
1380 return graph()->NewNode(phi_op, true0, false0, merge0);
1339 } 1381 }
1340 1382
1341 1383
1342 Node* SimplifiedLowering::Int32Mod(Node* const node) { 1384 Node* SimplifiedLowering::Int32Mod(Node* const node) {
1343 Int32BinopMatcher m(node); 1385 Int32BinopMatcher m(node);
1344 Node* const zero = jsgraph()->Int32Constant(0); 1386 Node* const zero = jsgraph()->Int32Constant(0);
1345 Node* const minus_one = jsgraph()->Int32Constant(-1); 1387 Node* const minus_one = jsgraph()->Int32Constant(-1);
1346 Node* const lhs = m.left().node(); 1388 Node* const lhs = m.left().node();
1347 Node* const rhs = m.right().node(); 1389 Node* const rhs = m.right().node();
1348 1390
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1531 1573
1532 void SimplifiedLowering::DoStringLessThanOrEqual(Node* node) { 1574 void SimplifiedLowering::DoStringLessThanOrEqual(Node* node) {
1533 node->set_op(machine()->IntLessThanOrEqual()); 1575 node->set_op(machine()->IntLessThanOrEqual());
1534 node->ReplaceInput(0, StringComparison(node, true)); 1576 node->ReplaceInput(0, StringComparison(node, true));
1535 node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL)); 1577 node->ReplaceInput(1, jsgraph()->SmiConstant(EQUAL));
1536 } 1578 }
1537 1579
1538 } // namespace compiler 1580 } // namespace compiler
1539 } // namespace internal 1581 } // namespace internal
1540 } // namespace v8 1582 } // 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