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

Side by Side Diff: src/x64/lithium-x64.cc

Issue 23703014: Orthogonalize Lithium binary op instructions. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« src/ia32/lithium-ia32.cc ('K') | « src/x64/lithium-x64.h ('k') | 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 701 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 } 712 }
713 713
714 714
715 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) { 715 LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) {
716 return AssignEnvironment(new(zone()) LDeoptimize); 716 return AssignEnvironment(new(zone()) LDeoptimize);
717 } 717 }
718 718
719 719
720 LInstruction* LChunkBuilder::DoShift(Token::Value op, 720 LInstruction* LChunkBuilder::DoShift(Token::Value op,
721 HBitwiseBinaryOperation* instr) { 721 HBitwiseBinaryOperation* instr) {
722 if (instr->representation().IsTagged()) { 722 if (instr->representation().IsSmiOrInteger32()) {
723 ASSERT(instr->left()->representation().IsTagged()); 723 ASSERT(instr->left()->representation().Equals(instr->representation()));
724 ASSERT(instr->right()->representation().IsTagged()); 724 ASSERT(instr->right()->representation().Equals(instr->representation()));
725 LOperand* left = UseRegisterAtStart(instr->left());
725 726
726 LOperand* left = UseFixed(instr->left(), rdx); 727 HValue* right_value = instr->right();
727 LOperand* right = UseFixed(instr->right(), rax); 728 LOperand* right = NULL;
728 LArithmeticT* result = new(zone()) LArithmeticT(op, left, right); 729 int constant_value = 0;
729 return MarkAsCall(DefineFixed(result, rax), instr); 730 if (right_value->IsConstant()) {
731 HConstant* constant = HConstant::cast(right_value);
732 right = chunk_->DefineConstantOperand(constant);
733 constant_value = constant->Integer32Value() & 0x1f;
734 } else {
735 right = UseFixed(right_value, rcx);
736 }
737
738 // Shift operations can only deoptimize if we do a logical shift by 0 and
739 // the result cannot be truncated to int32.
740 bool does_deopt = false;
741 if (op == Token::SHR && constant_value == 0) {
742 if (FLAG_opt_safe_uint32_operations) {
743 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
744 } else {
745 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToInt32);
746 }
747 }
748
749 LInstruction* result =
750 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
751 return does_deopt ? AssignEnvironment(result) : result;
752 } else {
753 return DoArithmeticT(op, instr);
730 } 754 }
731
732 ASSERT(instr->representation().IsSmiOrInteger32());
733 ASSERT(instr->left()->representation().Equals(instr->representation()));
734 ASSERT(instr->right()->representation().Equals(instr->representation()));
735 LOperand* left = UseRegisterAtStart(instr->left());
736
737 HValue* right_value = instr->right();
738 LOperand* right = NULL;
739 int constant_value = 0;
740 if (right_value->IsConstant()) {
741 HConstant* constant = HConstant::cast(right_value);
742 right = chunk_->DefineConstantOperand(constant);
743 constant_value = constant->Integer32Value() & 0x1f;
744 } else {
745 right = UseFixed(right_value, rcx);
746 }
747
748 // Shift operations can only deoptimize if we do a logical shift by 0 and
749 // the result cannot be truncated to int32.
750 bool does_deopt = false;
751 if (op == Token::SHR && constant_value == 0) {
752 if (FLAG_opt_safe_uint32_operations) {
753 does_deopt = !instr->CheckFlag(HInstruction::kUint32);
754 } else {
755 does_deopt = !instr->CheckUsesForFlag(HValue::kTruncatingToInt32);
756 }
757 }
758
759 LInstruction* result =
760 DefineSameAsFirst(new(zone()) LShiftI(op, left, right, does_deopt));
761 return does_deopt ? AssignEnvironment(result) : result;
762 } 755 }
763 756
764 757
765 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op, 758 LInstruction* LChunkBuilder::DoArithmeticD(Token::Value op,
766 HArithmeticBinaryOperation* instr) { 759 HArithmeticBinaryOperation* instr) {
767 ASSERT(instr->representation().IsDouble()); 760 ASSERT(instr->representation().IsDouble());
768 ASSERT(instr->left()->representation().IsDouble()); 761 ASSERT(instr->left()->representation().IsDouble());
769 ASSERT(instr->right()->representation().IsDouble()); 762 ASSERT(instr->right()->representation().IsDouble());
770 ASSERT(op != Token::MOD);
771 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); 763 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
772 LOperand* right = UseRegisterAtStart(instr->BetterRightOperand()); 764 LOperand* right = (op == Token::MOD)
Sven Panne 2013/09/16 13:10:32 Same remark for MOD here...
765 ? UseFixedDouble(instr->BetterRightOperand(), xmm1)
766 : UseRegisterAtStart(instr->BetterRightOperand());
773 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right); 767 LArithmeticD* result = new(zone()) LArithmeticD(op, left, right);
768 if (op == Token::MOD) return MarkAsCall(DefineSameAsFirst(result), instr);
774 return DefineSameAsFirst(result); 769 return DefineSameAsFirst(result);
775 } 770 }
776 771
777 772
778 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op, 773 LInstruction* LChunkBuilder::DoArithmeticT(Token::Value op,
779 HArithmeticBinaryOperation* instr) { 774 HBinaryOperation* instr) {
780 ASSERT(op == Token::ADD ||
781 op == Token::DIV ||
782 op == Token::MOD ||
783 op == Token::MUL ||
784 op == Token::SUB);
785 HValue* left = instr->left(); 775 HValue* left = instr->left();
786 HValue* right = instr->right(); 776 HValue* right = instr->right();
787 ASSERT(left->representation().IsTagged()); 777 ASSERT(left->representation().IsTagged());
788 ASSERT(right->representation().IsTagged()); 778 ASSERT(right->representation().IsTagged());
789 LOperand* left_operand = UseFixed(left, rdx); 779 LOperand* left_operand = UseFixed(left, rdx);
790 LOperand* right_operand = UseFixed(right, rax); 780 LOperand* right_operand = UseFixed(right, rax);
791 LArithmeticT* result = 781 LArithmeticT* result =
792 new(zone()) LArithmeticT(op, left_operand, right_operand); 782 new(zone()) LArithmeticT(op, left_operand, right_operand);
793 return MarkAsCall(DefineFixed(result, rax), instr); 783 return MarkAsCall(DefineFixed(result, rax), instr);
794 } 784 }
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 1331
1342 LInstruction* LChunkBuilder::DoShl(HShl* instr) { 1332 LInstruction* LChunkBuilder::DoShl(HShl* instr) {
1343 return DoShift(Token::SHL, instr); 1333 return DoShift(Token::SHL, instr);
1344 } 1334 }
1345 1335
1346 1336
1347 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) { 1337 LInstruction* LChunkBuilder::DoBitwise(HBitwise* instr) {
1348 if (instr->representation().IsSmiOrInteger32()) { 1338 if (instr->representation().IsSmiOrInteger32()) {
1349 ASSERT(instr->left()->representation().Equals(instr->representation())); 1339 ASSERT(instr->left()->representation().Equals(instr->representation()));
1350 ASSERT(instr->right()->representation().Equals(instr->representation())); 1340 ASSERT(instr->right()->representation().Equals(instr->representation()));
1341 ASSERT(instr->CheckFlag(HValue::kTruncatingToInt32));
1351 1342
1352 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); 1343 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1353 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand()); 1344 LOperand* right = UseOrConstantAtStart(instr->BetterRightOperand());
1354 return DefineSameAsFirst(new(zone()) LBitI(left, right)); 1345 return DefineSameAsFirst(new(zone()) LBitI(left, right));
1355 } else { 1346 } else {
1356 ASSERT(instr->representation().IsTagged()); 1347 return DoArithmeticT(instr->op(), instr);
1357 ASSERT(instr->left()->representation().IsTagged());
1358 ASSERT(instr->right()->representation().IsTagged());
1359
1360 LOperand* left = UseFixed(instr->left(), rdx);
1361 LOperand* right = UseFixed(instr->right(), rax);
1362 LArithmeticT* result = new(zone()) LArithmeticT(instr->op(), left, right);
1363 return MarkAsCall(DefineFixed(result, rax), instr);
1364 } 1348 }
1365 } 1349 }
1366 1350
1367 1351
1368 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { 1352 LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
1369 if (instr->representation().IsDouble()) { 1353 if (instr->representation().IsSmiOrInteger32()) {
1370 return DoArithmeticD(Token::DIV, instr);
1371 } else if (instr->representation().IsSmiOrInteger32()) {
1372 ASSERT(instr->left()->representation().Equals(instr->representation())); 1354 ASSERT(instr->left()->representation().Equals(instr->representation()));
1373 ASSERT(instr->right()->representation().Equals(instr->representation())); 1355 ASSERT(instr->right()->representation().Equals(instr->representation()));
1374 if (instr->HasPowerOf2Divisor()) { 1356 if (instr->HasPowerOf2Divisor()) {
1375 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero)); 1357 ASSERT(!instr->CheckFlag(HValue::kCanBeDivByZero));
1376 LOperand* value = UseRegisterAtStart(instr->left()); 1358 LOperand* value = UseRegisterAtStart(instr->left());
1377 LDivI* div = 1359 LDivI* div =
1378 new(zone()) LDivI(value, UseOrConstant(instr->right()), NULL); 1360 new(zone()) LDivI(value, UseOrConstant(instr->right()), NULL);
1379 return AssignEnvironment(DefineSameAsFirst(div)); 1361 return AssignEnvironment(DefineSameAsFirst(div));
1380 } 1362 }
1381 // The temporary operand is necessary to ensure that right is not allocated 1363 // The temporary operand is necessary to ensure that right is not allocated
1382 // into rdx. 1364 // into rdx.
1383 LOperand* temp = FixedTemp(rdx); 1365 LOperand* temp = FixedTemp(rdx);
1384 LOperand* dividend = UseFixed(instr->left(), rax); 1366 LOperand* dividend = UseFixed(instr->left(), rax);
1385 LOperand* divisor = UseRegister(instr->right()); 1367 LOperand* divisor = UseRegister(instr->right());
1386 LDivI* result = new(zone()) LDivI(dividend, divisor, temp); 1368 LDivI* result = new(zone()) LDivI(dividend, divisor, temp);
1387 return AssignEnvironment(DefineFixed(result, rax)); 1369 return AssignEnvironment(DefineFixed(result, rax));
1370 } else if (instr->representation().IsDouble()) {
1371 return DoArithmeticD(Token::DIV, instr);
1388 } else { 1372 } else {
1389 ASSERT(instr->representation().IsTagged());
1390 return DoArithmeticT(Token::DIV, instr); 1373 return DoArithmeticT(Token::DIV, instr);
1391 } 1374 }
1392 } 1375 }
1393 1376
1394 1377
1395 HValue* LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(HValue* divisor) { 1378 HValue* LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(HValue* divisor) {
1396 if (divisor->IsConstant() && 1379 if (divisor->IsConstant() &&
1397 HConstant::cast(divisor)->HasInteger32Value()) { 1380 HConstant::cast(divisor)->HasInteger32Value()) {
1398 HConstant* constant_val = HConstant::cast(divisor); 1381 HConstant* constant_val = HConstant::cast(divisor);
1399 return constant_val->CopyToRepresentation(Representation::Integer32(), 1382 return constant_val->CopyToRepresentation(Representation::Integer32(),
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1478 return (right->CanBeZero() || 1461 return (right->CanBeZero() ||
1479 (left->RangeCanInclude(kMinInt) && 1462 (left->RangeCanInclude(kMinInt) &&
1480 right->RangeCanInclude(-1) && 1463 right->RangeCanInclude(-1) &&
1481 instr->CheckFlag(HValue::kBailoutOnMinusZero)) || 1464 instr->CheckFlag(HValue::kBailoutOnMinusZero)) ||
1482 (left->CanBeNegative() && 1465 (left->CanBeNegative() &&
1483 instr->CanBeZero() && 1466 instr->CanBeZero() &&
1484 instr->CheckFlag(HValue::kBailoutOnMinusZero))) 1467 instr->CheckFlag(HValue::kBailoutOnMinusZero)))
1485 ? AssignEnvironment(result) 1468 ? AssignEnvironment(result)
1486 : result; 1469 : result;
1487 } 1470 }
1488 } else if (instr->representation().IsTagged()) { 1471 } else if (instr->representation().IsDouble()) {
1472 return DoArithmeticD(Token::MOD, instr);
1473 } else {
1489 return DoArithmeticT(Token::MOD, instr); 1474 return DoArithmeticT(Token::MOD, instr);
1490 } else {
1491 ASSERT(instr->representation().IsDouble());
1492 // We call a C function for double modulo. It can't trigger a GC. We need to
1493 // use fixed result register for the call.
1494 // TODO(fschneider): Allow any register as input registers.
1495 LArithmeticD* mod = new(zone()) LArithmeticD(Token::MOD,
1496 UseFixedDouble(left, xmm2),
1497 UseFixedDouble(right, xmm1));
1498 return MarkAsCall(DefineFixedDouble(mod, xmm1), instr);
1499 } 1475 }
1500 } 1476 }
1501 1477
1502 1478
1503 LInstruction* LChunkBuilder::DoMul(HMul* instr) { 1479 LInstruction* LChunkBuilder::DoMul(HMul* instr) {
1504 if (instr->representation().IsSmiOrInteger32()) { 1480 if (instr->representation().IsSmiOrInteger32()) {
1505 ASSERT(instr->left()->representation().Equals(instr->representation())); 1481 ASSERT(instr->left()->representation().Equals(instr->representation()));
1506 ASSERT(instr->right()->representation().Equals(instr->representation())); 1482 ASSERT(instr->right()->representation().Equals(instr->representation()));
1507 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand()); 1483 LOperand* left = UseRegisterAtStart(instr->BetterLeftOperand());
1508 LOperand* right = UseOrConstant(instr->BetterRightOperand()); 1484 LOperand* right = UseOrConstant(instr->BetterRightOperand());
1509 LMulI* mul = new(zone()) LMulI(left, right); 1485 LMulI* mul = new(zone()) LMulI(left, right);
1510 if (instr->CheckFlag(HValue::kCanOverflow) || 1486 if (instr->CheckFlag(HValue::kCanOverflow) ||
1511 instr->CheckFlag(HValue::kBailoutOnMinusZero)) { 1487 instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
1512 AssignEnvironment(mul); 1488 AssignEnvironment(mul);
1513 } 1489 }
1514 return DefineSameAsFirst(mul); 1490 return DefineSameAsFirst(mul);
1515 } else if (instr->representation().IsDouble()) { 1491 } else if (instr->representation().IsDouble()) {
1516 return DoArithmeticD(Token::MUL, instr); 1492 return DoArithmeticD(Token::MUL, instr);
1517 } else { 1493 } else {
1518 ASSERT(instr->representation().IsTagged());
1519 return DoArithmeticT(Token::MUL, instr); 1494 return DoArithmeticT(Token::MUL, instr);
1520 } 1495 }
1521 } 1496 }
1522 1497
1523 1498
1524 LInstruction* LChunkBuilder::DoSub(HSub* instr) { 1499 LInstruction* LChunkBuilder::DoSub(HSub* instr) {
1525 if (instr->representation().IsSmiOrInteger32()) { 1500 if (instr->representation().IsSmiOrInteger32()) {
1526 ASSERT(instr->left()->representation().Equals(instr->representation())); 1501 ASSERT(instr->left()->representation().Equals(instr->representation()));
1527 ASSERT(instr->right()->representation().Equals(instr->representation())); 1502 ASSERT(instr->right()->representation().Equals(instr->representation()));
1528 LOperand* left = UseRegisterAtStart(instr->left()); 1503 LOperand* left = UseRegisterAtStart(instr->left());
1529 LOperand* right = UseOrConstantAtStart(instr->right()); 1504 LOperand* right = UseOrConstantAtStart(instr->right());
1530 LSubI* sub = new(zone()) LSubI(left, right); 1505 LSubI* sub = new(zone()) LSubI(left, right);
1531 LInstruction* result = DefineSameAsFirst(sub); 1506 LInstruction* result = DefineSameAsFirst(sub);
1532 if (instr->CheckFlag(HValue::kCanOverflow)) { 1507 if (instr->CheckFlag(HValue::kCanOverflow)) {
1533 result = AssignEnvironment(result); 1508 result = AssignEnvironment(result);
1534 } 1509 }
1535 return result; 1510 return result;
1536 } else if (instr->representation().IsDouble()) { 1511 } else if (instr->representation().IsDouble()) {
1537 return DoArithmeticD(Token::SUB, instr); 1512 return DoArithmeticD(Token::SUB, instr);
1538 } else { 1513 } else {
1539 ASSERT(instr->representation().IsTagged());
1540 return DoArithmeticT(Token::SUB, instr); 1514 return DoArithmeticT(Token::SUB, instr);
1541 } 1515 }
1542 } 1516 }
1543 1517
1544 1518
1545 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) { 1519 LInstruction* LChunkBuilder::DoAdd(HAdd* instr) {
1546 if (instr->representation().IsSmiOrInteger32()) { 1520 if (instr->representation().IsSmiOrInteger32()) {
1547 // Check to see if it would be advantageous to use an lea instruction rather 1521 // Check to see if it would be advantageous to use an lea instruction rather
1548 // than an add. This is the case when no overflow check is needed and there 1522 // than an add. This is the case when no overflow check is needed and there
1549 // are multiple uses of the add's inputs, so using a 3-register add will 1523 // are multiple uses of the add's inputs, so using a 3-register add will
(...skipping 11 matching lines...) Expand all
1561 LInstruction* result = use_lea 1535 LInstruction* result = use_lea
1562 ? DefineAsRegister(add) 1536 ? DefineAsRegister(add)
1563 : DefineSameAsFirst(add); 1537 : DefineSameAsFirst(add);
1564 if (can_overflow) { 1538 if (can_overflow) {
1565 result = AssignEnvironment(result); 1539 result = AssignEnvironment(result);
1566 } 1540 }
1567 return result; 1541 return result;
1568 } else if (instr->representation().IsDouble()) { 1542 } else if (instr->representation().IsDouble()) {
1569 return DoArithmeticD(Token::ADD, instr); 1543 return DoArithmeticD(Token::ADD, instr);
1570 } else { 1544 } else {
1571 ASSERT(instr->representation().IsTagged());
1572 return DoArithmeticT(Token::ADD, instr); 1545 return DoArithmeticT(Token::ADD, instr);
1573 } 1546 }
1574 return NULL; 1547 return NULL;
1575 } 1548 }
1576 1549
1577 1550
1578 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { 1551 LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) {
1579 LOperand* left = NULL; 1552 LOperand* left = NULL;
1580 LOperand* right = NULL; 1553 LOperand* right = NULL;
1581 if (instr->representation().IsSmiOrInteger32()) { 1554 if (instr->representation().IsSmiOrInteger32()) {
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after
2548 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { 2521 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) {
2549 LOperand* object = UseRegister(instr->object()); 2522 LOperand* object = UseRegister(instr->object());
2550 LOperand* index = UseTempRegister(instr->index()); 2523 LOperand* index = UseTempRegister(instr->index());
2551 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index)); 2524 return DefineSameAsFirst(new(zone()) LLoadFieldByIndex(object, index));
2552 } 2525 }
2553 2526
2554 2527
2555 } } // namespace v8::internal 2528 } } // namespace v8::internal
2556 2529
2557 #endif // V8_TARGET_ARCH_X64 2530 #endif // V8_TARGET_ARCH_X64
OLDNEW
« src/ia32/lithium-ia32.cc ('K') | « src/x64/lithium-x64.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698