Revision: 19822
Author:   [email protected]
Date:     Tue Mar 11 19:04:14 2014 UTC
Log:      MIPS: Cleanup some of the range uses in ModI/DivI.

Port r19796 (2b8ff32)

BUG=v8:3204
LOG=y
[email protected]

Review URL: https://codereview.chromium.org/194863004

Patch from Balazs Kilvady <[email protected]>.
http://code.google.com/p/v8/source/detail?r=19822

Modified:
 /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc
 /branches/bleeding_edge/src/mips/lithium-mips.cc

=======================================
--- /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Tue Mar 11 14:39:08 2014 UTC +++ /branches/bleeding_edge/src/mips/lithium-codegen-mips.cc Tue Mar 11 19:04:14 2014 UTC
@@ -1095,8 +1095,6 @@

 void LCodeGen::DoModI(LModI* instr) {
   HMod* hmod = instr->hydrogen();
-  HValue* left = hmod->left();
-  HValue* right = hmod->right();
   const Register left_reg = ToRegister(instr->left());
   const Register right_reg = ToRegister(instr->right());
   const Register result_reg = ToRegister(instr->result());
@@ -1107,24 +1105,28 @@
   Label done;
// Check for x % 0, we have to deopt in this case because we can't return a
   // NaN.
-  if (right->CanBeZero()) {
+  if (hmod->CheckFlag(HValue::kCanBeDivByZero)) {
     DeoptimizeIf(eq, instr->environment(), right_reg, Operand(zero_reg));
   }

- // Check for kMinInt % -1, we have to deopt if we care about -0, because we
-  // can't return that.
-  if (left->RangeCanInclude(kMinInt) && right->RangeCanInclude(-1)) {
-    Label left_not_min_int;
-    __ Branch(&left_not_min_int, ne, left_reg, Operand(kMinInt));
-    // TODO(svenpanne) Don't deopt when we don't care about -0.
-    DeoptimizeIf(eq, instr->environment(), right_reg, Operand(-1));
-    __ bind(&left_not_min_int);
+  // Check for kMinInt % -1, div will return kMinInt, which is not what we
+ // want. We have to deopt if we care about -0, because we can't return that.
+  if (hmod->CheckFlag(HValue::kCanOverflow)) {
+    Label no_overflow_possible;
+    __ Branch(&no_overflow_possible, ne, left_reg, Operand(kMinInt));
+    if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
+      DeoptimizeIf(eq, instr->environment(), right_reg, Operand(-1));
+    } else {
+      __ Branch(&no_overflow_possible, ne, right_reg, Operand(-1));
+      __ Branch(USE_DELAY_SLOT, &done);
+      __ mov(result_reg, zero_reg);
+    }
+    __ bind(&no_overflow_possible);
   }

-  // TODO(svenpanne) Only emit the test/deopt if we have to.
+  // If we care about -0, test if the dividend is <0 and the result is 0.
   __ Branch(USE_DELAY_SLOT, &done, ge, left_reg, Operand(zero_reg));
   __ mfhi(result_reg);
-
   if (hmod->CheckFlag(HValue::kBailoutOnMinusZero)) {
     DeoptimizeIf(eq, instr->environment(), result_reg, Operand(zero_reg));
   }
@@ -1133,6 +1135,7 @@


 void LCodeGen::DoDivI(LDivI* instr) {
+  HBinaryOperation* hdiv = instr->hydrogen();
   const Register left = ToRegister(instr->left());
   const Register right = ToRegister(instr->right());
   const Register result = ToRegister(instr->result());
@@ -1142,12 +1145,12 @@
   __ div(left, right);

   // Check for x / 0.
-  if (instr->hydrogen()->CheckFlag(HValue::kCanBeDivByZero)) {
+  if (hdiv->CheckFlag(HValue::kCanBeDivByZero)) {
     DeoptimizeIf(eq, instr->environment(), right, Operand(zero_reg));
   }

   // Check for (0 / -x) that will produce negative zero.
-  if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
+  if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero)) {
     Label left_not_zero;
     __ Branch(&left_not_zero, ne, left, Operand(zero_reg));
     DeoptimizeIf(lt, instr->environment(), right, Operand(zero_reg));
@@ -1155,14 +1158,15 @@
   }

   // Check for (kMinInt / -1).
-  if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
+  if (hdiv->CheckFlag(HValue::kCanOverflow) &&
+      !hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
     Label left_not_min_int;
     __ Branch(&left_not_min_int, ne, left, Operand(kMinInt));
     DeoptimizeIf(eq, instr->environment(), right, Operand(-1));
     __ bind(&left_not_min_int);
   }

- if (!instr->hydrogen()->CheckFlag(HInstruction::kAllUsesTruncatingToInt32)) {
+  if (!hdiv->CheckFlag(HValue::kAllUsesTruncatingToInt32)) {
     __ mfhi(result);
     DeoptimizeIf(ne, instr->environment(), result, Operand(zero_reg));
   }
@@ -1233,8 +1237,7 @@

   // Check for (0 / -x) that will produce negative zero.
   HMathFloorOfDiv* hdiv = instr->hydrogen();
-  if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) &&
-      hdiv->left()->RangeCanInclude(0) && divisor < 0) {
+  if (hdiv->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) {
     DeoptimizeIf(eq, instr->environment(), dividend, Operand(zero_reg));
   }

=======================================
--- /branches/bleeding_edge/src/mips/lithium-mips.cc Mon Mar 10 19:50:36 2014 UTC +++ /branches/bleeding_edge/src/mips/lithium-mips.cc Tue Mar 11 19:04:14 2014 UTC
@@ -1289,8 +1289,7 @@
DefineAsRegister(new(zone()) LFlooringDivByConstI(dividend, divisor));
   bool can_deopt =
       divisor == 0 ||
-      (instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
-       instr->left()->RangeCanInclude(0) && divisor < 0);
+      (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0);
   return can_deopt ? AssignEnvironment(result) : result;
 }

@@ -1317,12 +1316,12 @@
   ASSERT(instr->right()->representation().Equals(instr->representation()));
   LOperand* dividend = UseRegisterAtStart(instr->left());
   int32_t divisor = instr->right()->GetInteger32Constant();
-  LInstruction* result =
-      DefineSameAsFirst(new(zone()) LModByPowerOf2I(dividend, divisor));
-  bool can_deopt =
-      instr->CheckFlag(HValue::kBailoutOnMinusZero) &&
-      instr->left()->CanBeNegative();
-  return can_deopt ? AssignEnvironment(result) : result;
+  LInstruction* result = DefineSameAsFirst(new(zone()) LModByPowerOf2I(
+          dividend, divisor));
+  if (instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
+    result = AssignEnvironment(result);
+  }
+  return result;
 }


@@ -1332,17 +1331,13 @@
   ASSERT(instr->right()->representation().Equals(instr->representation()));
   LOperand* dividend = UseRegister(instr->left());
   LOperand* divisor = UseRegister(instr->right());
-  LModI* mod = new(zone()) LModI(dividend,
-                                 divisor);
-  LInstruction* result = DefineAsRegister(mod);
-  bool can_deopt = (instr->right()->CanBeZero() ||
-                    (instr->left()->RangeCanInclude(kMinInt) &&
-                     instr->right()->RangeCanInclude(-1) &&
-                     instr->CheckFlag(HValue::kBailoutOnMinusZero)) ||
-                    (instr->left()->CanBeNegative() &&
-                     instr->CanBeZero() &&
-                     instr->CheckFlag(HValue::kBailoutOnMinusZero)));
-  return can_deopt ? AssignEnvironment(result) : result;
+  LInstruction* result = DefineAsRegister(new(zone()) LModI(
+      dividend, divisor));
+  if (instr->CheckFlag(HValue::kCanBeDivByZero) ||
+      instr->CheckFlag(HValue::kBailoutOnMinusZero)) {
+    result = AssignEnvironment(result);
+  }
+  return result;
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to