Index: src/a64/lithium-a64.cc |
diff --git a/src/a64/lithium-a64.cc b/src/a64/lithium-a64.cc |
index 12812bbf2e4f8b74928d0f56b4ad41b8981b670c..dff700324ff74c9661a97aa71dbfbdd101a9de0a 100644 |
--- a/src/a64/lithium-a64.cc |
+++ b/src/a64/lithium-a64.cc |
@@ -1369,7 +1369,7 @@ LInstruction* LChunkBuilder::DoDeoptimize(HDeoptimize* instr) { |
LInstruction* LChunkBuilder::DoDivByPowerOf2I(HDiv* instr) { |
- ASSERT(instr->representation().IsSmiOrInteger32()); |
+ ASSERT(instr->representation().IsInteger32()); |
ASSERT(instr->left()->representation().Equals(instr->representation())); |
ASSERT(instr->right()->representation().Equals(instr->representation())); |
LOperand* dividend = UseRegister(instr->left()); |
@@ -1387,6 +1387,25 @@ 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(); |
+ bool truncating = instr->CheckFlag(HInstruction::kAllUsesTruncatingToInt32); |
+ LOperand* temp = truncating ? NULL : TempRegister(); |
+ LInstruction* result = |
+ DefineAsRegister(new(zone()) LDivByConstI(dividend, divisor, temp)); |
+ bool can_deopt = |
+ divisor == 0 || |
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
+ instr->left()->RangeCanInclude(0) && divisor < 0) || |
+ !truncating; |
+ return can_deopt ? AssignEnvironment(result) : result; |
+} |
+ |
+ |
LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { |
ASSERT(instr->representation().IsSmiOrInteger32()); |
ASSERT(instr->left()->representation().Equals(instr->representation())); |
@@ -1402,10 +1421,13 @@ LInstruction* LChunkBuilder::DoDivI(HBinaryOperation* instr) { |
LInstruction* LChunkBuilder::DoDiv(HDiv* instr) { |
if (instr->representation().IsSmiOrInteger32()) { |
- // TODO(all): Add Smi support to DoDivI and turn this into a ternary. |
- if (instr->RightIsPowerOf2()) return DoDivByPowerOf2I(instr); |
- if (instr->representation().IsInteger32()) return DoDivI(instr); |
- return DoArithmeticT(Token::DIV, 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 { |
@@ -1714,6 +1736,9 @@ LInstruction* LChunkBuilder::DoMapEnumLength(HMapEnumLength* instr) { |
LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { |
+ ASSERT(instr->representation().IsInteger32()); |
+ ASSERT(instr->left()->representation().Equals(instr->representation())); |
+ ASSERT(instr->right()->representation().Equals(instr->representation())); |
LOperand* dividend = UseRegisterAtStart(instr->left()); |
int32_t divisor = instr->right()->GetInteger32Constant(); |
LInstruction* result = |
@@ -1725,6 +1750,22 @@ LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) { |
} |
+LInstruction* LChunkBuilder::DoFlooringDivByConstI(HMathFloorOfDiv* 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(); |
+ LInstruction* result = |
+ DefineAsRegister(new(zone()) LFlooringDivByConstI(dividend, divisor)); |
+ bool can_deopt = |
+ divisor == 0 || |
+ (instr->CheckFlag(HValue::kBailoutOnMinusZero) && |
+ instr->left()->RangeCanInclude(0) && divisor < 0); |
+ return can_deopt ? AssignEnvironment(result) : result; |
+} |
+ |
+ |
LInstruction* LChunkBuilder::DoFlooringDivI(HMathFloorOfDiv* instr) { |
LOperand* dividend = UseRegister(instr->left()); |
LOperand* divisor = UseRegister(instr->right()); |
@@ -1739,8 +1780,7 @@ LInstruction* LChunkBuilder::DoMathFloorOfDiv(HMathFloorOfDiv* instr) { |
if (instr->RightIsPowerOf2()) { |
return DoFlooringDivByPowerOf2I(instr); |
} else if (instr->right()->IsConstant()) { |
- // TODO(svenpanne) Do something more efficient in this case. |
- return DoFlooringDivI(instr); |
+ return DoFlooringDivByConstI(instr); |
} else { |
return DoFlooringDivI(instr); |
} |
@@ -1767,7 +1807,7 @@ LInstruction* LChunkBuilder::DoMathMinMax(HMathMinMax* instr) { |
LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) { |
- ASSERT(instr->representation().IsSmiOrInteger32()); |
+ ASSERT(instr->representation().IsInteger32()); |
ASSERT(instr->left()->representation().Equals(instr->representation())); |
ASSERT(instr->right()->representation().Equals(instr->representation())); |
LOperand* dividend = UseRegisterAtStart(instr->left()); |
@@ -1781,6 +1821,23 @@ LInstruction* LChunkBuilder::DoModByPowerOf2I(HMod* instr) { |
} |
+LInstruction* LChunkBuilder::DoModByConstI(HMod* 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* temp = TempRegister(); |
+ LInstruction* result = |
+ DefineAsRegister(new(zone()) LModByConstI(dividend, divisor, temp)); |
+ 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())); |
@@ -1798,10 +1855,13 @@ LInstruction* LChunkBuilder::DoModI(HMod* instr) { |
LInstruction* LChunkBuilder::DoMod(HMod* instr) { |
if (instr->representation().IsSmiOrInteger32()) { |
- // TODO(all): Add Smi support to DoDivI and turn this into a ternary. |
- if (instr->RightIsPowerOf2()) return DoModByPowerOf2I(instr); |
- if (instr->representation().IsInteger32()) return DoModI(instr); |
- return DoArithmeticT(Token::MOD, 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 { |