Index: src/ia32/lithium-codegen-ia32.cc |
=================================================================== |
--- src/ia32/lithium-codegen-ia32.cc (revision 13175) |
+++ src/ia32/lithium-codegen-ia32.cc (working copy) |
@@ -1201,6 +1201,43 @@ |
void LCodeGen::DoDivI(LDivI* instr) { |
+ if (instr->hydrogen()->HasPowerOf2Divisor()) { |
+ Register dividend = ToRegister(instr->left()); |
+ int32_t divisor = |
+ HConstant::cast(instr->hydrogen()->right())->Integer32Value(); |
+ int32_t test_value = 0; |
+ int32_t power = 0; |
+ |
+ if (divisor > 0) { |
+ test_value = divisor - 1; |
+ power = WhichPowerOf2(divisor); |
+ } else { |
+ // Check for (0 / -x) that will produce negative zero. |
+ if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) { |
+ __ test(dividend, Operand(dividend)); |
+ DeoptimizeIf(zero, instr->environment()); |
+ } |
+ // Check for (kMinInt / -1). |
+ if (divisor == -1 && instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
+ __ cmp(dividend, kMinInt); |
+ DeoptimizeIf(zero, instr->environment()); |
+ } |
+ test_value = - divisor - 1; |
+ power = WhichPowerOf2(-divisor); |
+ } |
+ |
+ if (test_value != 0) { |
Yang
2012/12/10 09:47:28
this if-block seems also unnecessary if divisor is
|
+ // Deoptimize if remainder is not 0. |
+ __ test(dividend, Immediate(test_value)); |
+ DeoptimizeIf(not_zero, instr->environment()); |
+ __ sar(dividend, power); |
+ } |
+ |
+ if (divisor < 0) __ neg(dividend); |
+ |
+ return; |
+ } |
+ |
LOperand* right = instr->right(); |
ASSERT(ToRegister(instr->result()).is(eax)); |
ASSERT(ToRegister(instr->left()).is(eax)); |
@@ -1226,7 +1263,7 @@ |
__ bind(&left_not_zero); |
} |
- // Check for (-kMinInt / -1). |
+ // Check for (kMinInt / -1). |
if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) { |
Label left_not_min_int; |
__ cmp(left_reg, kMinInt); |