Index: src/ia32/lithium-ia32.cc |
diff --git a/src/ia32/lithium-ia32.cc b/src/ia32/lithium-ia32.cc |
index 4ff765b87bb83cca9cd703fe3f6d60731c2c2621..3153584553c250fb1d4e7f9f0732a99e610c547d 100644 |
--- a/src/ia32/lithium-ia32.cc |
+++ b/src/ia32/lithium-ia32.cc |
@@ -1340,6 +1340,26 @@ LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) { |
} |
+LInstruction* LChunkBuilder::DoDivByConstI(HDiv* instr) { |
+ ASSERT(instr->representation().IsInteger32()); |
+ ASSERT(instr->left()->representation().Equals(instr->representation())); |
+ ASSERT(instr->right()->representation().Equals(instr->representation())); |
+ LOperand* dividend = UseRegister(instr->left()); |
+ int32_t divisor = instr->right()->GetInteger32Constant(); |
+ LOperand* temp1 = FixedTemp(eax); |
+ LOperand* temp2 = FixedTemp(edx); |
+ LInstruction* result = |
+ DefineFixed( |
+ new(zone()) LDivByConstI(dividend, divisor, temp1, temp2), edx); |
+ bool can_deopt = |
+ divisor == 0 || |
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
+ instr->left()->RangeCanInclude(0) && divisor < 0) || |
+ !instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32); |
+ return can_deopt ? AssignEnvironment(result) : result; |
+} |
+ |
+ |
LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { |
ASSERT(instr->representation().IsSmiOrInteger32()); |
ASSERT(instr->left()->representation().Equals(instr->representation())); |
@@ -1347,14 +1367,21 @@ LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { |
LOperand* dividend = UseFixed(instr->left(), eax); |
LOperand* divisor = UseRegister(instr->right()); |
LOperand* temp = FixedTemp(edx); |
- LDivI* result = new(zone()) LDivI(dividend, divisor, temp); |
- return AssignEnvironment(DefineFixed(result, eax)); |
+ LInstruction* result = |
+ DefineFixed(new(zone()) LDivI(dividend, divisor, temp), eax); |
+ return AssignEnvironment(result); |
} |
LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
if (instr->representation().IsSmiOrInteger32()) { |
- return instr->RightIsPowerOf2() ? DoDivByPowerOf2I(instr) : DoDivI(instr); |
+ if (instr->RightIsPowerOf2()) { |
+ return DoDivByPowerOf2I(instr); |
+ } else if (instr->right()->IsConstant()) { |
+ return DoDivByConstI(instr); |
+ } else { |
+ return DoDivI(instr); |
+ } |
} else if (instr->representation().IsDouble()) { |
return DoArithmeticD(Token::DIV, instr); |
} else { |
@@ -1376,13 +1403,23 @@ LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { |
LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* instr) { |
- LOperand* dividend = UseFixed(instr->left(), eax); |
+ ASSERT(instr->representation().IsInteger32()); |
+ ASSERT(instr->left()->representation().Equals(instr->representation())); |
+ ASSERT(instr->right()->representation().Equals(instr->representation())); |
+ LOperand* dividend = UseRegister(instr->left()); |
int32_t divisor = instr->right()->GetInteger32Constant(); |
- LOperand* temp = TempRegister(); |
+ LOperand* temp1 = FixedTemp(eax); |
+ LOperand* temp2 = FixedTemp(edx); |
LInstruction* result = |
- DefineFixed( |
- new(zone()) LFlooringDivByConstI(dividend, divisor, temp), edx); |
- bool can_deopt = divisor <= 0; |
+ DefineFixed(new(zone()) LFlooringDivByConstI(dividend, |
+ divisor, |
+ temp1, |
+ temp2), |
+ edx); |
+ bool can_deopt = |
+ divisor == 0 || |
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
+ instr->left()->RangeCanInclude(0) && divisor < 0); |
return can_deopt ? AssignEnvironment(result) : result; |
} |
@@ -1413,6 +1450,25 @@ LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) { |
} |
+LInstruction* LChunkBuilder::DoModByConstI(HMod* instr) { |
+ ASSERT(instr->representation().IsSmiOrInteger32()); |
+ ASSERT(instr->left()->representation().Equals(instr->representation())); |
+ ASSERT(instr->right()->representation().Equals(instr->representation())); |
+ LOperand* dividend = UseRegister(instr->left()); |
+ int32_t divisor = instr->right()->GetInteger32Constant(); |
+ LOperand* temp1 = FixedTemp(eax); |
+ LOperand* temp2 = FixedTemp(edx); |
+ LInstruction* result = |
+ DefineFixed( |
+ new(zone()) LModByConstI(dividend, divisor, temp1, temp2), eax); |
+ bool can_deopt = |
+ divisor == 0 || |
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
+ instr->left()->CanBeNegative()); |
+ return can_deopt ? AssignEnvironment(result) : result; |
+} |
+ |
+ |
LInstruction* LChunkBuilder::DoModI(HMod* instr) { |
ASSERT(instr->representation().IsSmiOrInteger32()); |
ASSERT(instr->left()->representation().Equals(instr->representation())); |
@@ -1435,7 +1491,13 @@ LInstruction* LChunkBuilder::DoModI(HMod* instr) { |
LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
if (instr->representation().IsSmiOrInteger32()) { |
- return instr->RightIsPowerOf2() ? DoModByPowerOf2I(instr) : DoModI(instr); |
+ if (instr->RightIsPowerOf2()) { |
+ return DoModByPowerOf2I(instr); |
+ } else if (instr->right()->IsConstant()) { |
+ return DoModByConstI(instr); |
+ } else { |
+ return DoModI(instr); |
+ } |
} else if (instr->representation().IsDouble()) { |
return DoArithmeticD(Token::MOD, instr); |
} else { |