OLD | NEW |
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 1451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1462 } else { | 1462 } else { |
1463 return DoArithmeticT(Token::MOD, instr); | 1463 return DoArithmeticT(Token::MOD, instr); |
1464 } | 1464 } |
1465 } | 1465 } |
1466 | 1466 |
1467 | 1467 |
1468 LInstruction* LChunkBuilder::DoMul(HMul* instr) { | 1468 LInstruction* LChunkBuilder::DoMul(HMul* instr) { |
1469 if (instr->representation().IsSmiOrInteger32()) { | 1469 if (instr->representation().IsSmiOrInteger32()) { |
1470 ASSERT(instr->left()->representation().Equals(instr->representation())); | 1470 ASSERT(instr->left()->representation().Equals(instr->representation())); |
1471 ASSERT(instr->right()->representation().Equals(instr->representation())); | 1471 ASSERT(instr->right()->representation().Equals(instr->representation())); |
1472 LOperand* left; | 1472 HValue* left = instr->BetterLeftOperand(); |
1473 LOperand* right = UseOrConstant(instr->BetterRightOperand()); | 1473 HValue* right = instr->BetterRightOperand(); |
1474 LOperand* temp = NULL; | 1474 LOperand* left_op; |
1475 if (instr->CheckFlag(HValue::kBailoutOnMinusZero) && | 1475 LOperand* right_op; |
1476 (instr->CheckFlag(HValue::kCanOverflow) || | 1476 bool can_overflow = instr->CheckFlag(HValue::kCanOverflow); |
1477 !right->IsConstantOperand())) { | 1477 bool bailout_on_minus_zero = instr->CheckFlag(HValue::kBailoutOnMinusZero); |
1478 left = UseRegister(instr->BetterLeftOperand()); | 1478 |
1479 temp = TempRegister(); | 1479 if (right->IsConstant()) { |
| 1480 HConstant* constant = HConstant::cast(right); |
| 1481 int32_t constant_value = constant->Integer32Value(); |
| 1482 // Constants -1, 0 and 1 can be optimized if the result can overflow. |
| 1483 // For other constants, it can be optimized only without overflow. |
| 1484 if (!can_overflow || ((constant_value >= -1) && (constant_value <= 1))) { |
| 1485 left_op = UseRegisterAtStart(left); |
| 1486 right_op = UseConstant(right); |
| 1487 } else { |
| 1488 if (bailout_on_minus_zero) { |
| 1489 left_op = UseRegister(left); |
| 1490 } else { |
| 1491 left_op = UseRegisterAtStart(left); |
| 1492 } |
| 1493 right_op = UseRegister(right); |
| 1494 } |
1480 } else { | 1495 } else { |
1481 left = UseRegisterAtStart(instr->BetterLeftOperand()); | 1496 if (bailout_on_minus_zero) { |
| 1497 left_op = UseRegister(left); |
| 1498 } else { |
| 1499 left_op = UseRegisterAtStart(left); |
| 1500 } |
| 1501 right_op = UseRegister(right); |
1482 } | 1502 } |
1483 LMulI* mul = new(zone()) LMulI(left, right, temp); | 1503 LMulI* mul = new(zone()) LMulI(left_op, right_op); |
1484 if (instr->CheckFlag(HValue::kCanOverflow) || | 1504 if (can_overflow || bailout_on_minus_zero) { |
1485 instr->CheckFlag(HValue::kBailoutOnMinusZero)) { | |
1486 AssignEnvironment(mul); | 1505 AssignEnvironment(mul); |
1487 } | 1506 } |
1488 return DefineAsRegister(mul); | 1507 return DefineAsRegister(mul); |
1489 | 1508 |
1490 } else if (instr->representation().IsDouble()) { | 1509 } else if (instr->representation().IsDouble()) { |
1491 if (kArchVariant == kMips32r2) { | 1510 if (kArchVariant == kMips32r2) { |
1492 if (instr->UseCount() == 1 && instr->uses().value()->IsAdd()) { | 1511 if (instr->UseCount() == 1 && instr->uses().value()->IsAdd()) { |
1493 HAdd* add = HAdd::cast(instr->uses().value()); | 1512 HAdd* add = HAdd::cast(instr->uses().value()); |
1494 if (instr == add->left()) { | 1513 if (instr == add->left()) { |
1495 // This mul is the lhs of an add. The add and mul will be folded | 1514 // This mul is the lhs of an add. The add and mul will be folded |
(...skipping 1008 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2504 | 2523 |
2505 | 2524 |
2506 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { | 2525 LInstruction* LChunkBuilder::DoLoadFieldByIndex(HLoadFieldByIndex* instr) { |
2507 LOperand* object = UseRegister(instr->object()); | 2526 LOperand* object = UseRegister(instr->object()); |
2508 LOperand* index = UseRegister(instr->index()); | 2527 LOperand* index = UseRegister(instr->index()); |
2509 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); | 2528 return DefineAsRegister(new(zone()) LLoadFieldByIndex(object, index)); |
2510 } | 2529 } |
2511 | 2530 |
2512 | 2531 |
2513 } } // namespace v8::internal | 2532 } } // namespace v8::internal |
OLD | NEW |