Revision: 19877
Author:   [email protected]
Date:     Thu Mar 13 07:58:58 2014 UTC
Log: Remove uses of RangeCanInclude() in flooring division by power of 2.

Drive-By-Fix: Improve ARM code generation for flooring division by
power of 2.

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

Review URL: https://codereview.chromium.org/196653009
http://code.google.com/p/v8/source/detail?r=19877

Modified:
 /branches/bleeding_edge/src/a64/lithium-a64.cc
 /branches/bleeding_edge/src/a64/lithium-codegen-a64.cc
 /branches/bleeding_edge/src/arm/lithium-arm.cc
 /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc
 /branches/bleeding_edge/src/hydrogen-instructions.cc
 /branches/bleeding_edge/src/hydrogen-instructions.h
 /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
 /branches/bleeding_edge/src/ia32/lithium-ia32.cc
 /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
 /branches/bleeding_edge/src/x64/lithium-x64.cc

=======================================
--- /branches/bleeding_edge/src/a64/lithium-a64.cc Thu Mar 13 06:11:52 2014 UTC +++ /branches/bleeding_edge/src/a64/lithium-a64.cc Thu Mar 13 07:58:58 2014 UTC
@@ -1749,12 +1749,13 @@
   ASSERT(instr->right()->representation().Equals(instr->representation()));
   LOperand* dividend = UseRegisterAtStart(instr->left());
   int32_t divisor = instr->right()->GetInteger32Constant();
-  LInstruction* result =
- DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor));
-  bool can_deopt =
-      (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
-      (instr->left()->RangeCanInclude(kMinInt) && divisor == -1);
-  return can_deopt ? AssignEnvironment(result) : result;
+ LInstruction* result = DefineAsRegister(new(zone()) LFlooringDivByPowerOf2I(
+          dividend, divisor));
+  if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
+      (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
+    result = AssignEnvironment(result);
+  }
+  return result;
 }


=======================================
--- /branches/bleeding_edge/src/a64/lithium-codegen-a64.cc Thu Mar 13 06:11:52 2014 UTC +++ /branches/bleeding_edge/src/a64/lithium-codegen-a64.cc Thu Mar 13 07:58:58 2014 UTC
@@ -3839,37 +3839,37 @@

 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) {
   Register dividend = ToRegister32(instr->dividend());
+  Register result = ToRegister32(instr->result());
   int32_t divisor = instr->divisor();
-  ASSERT(dividend.is(ToRegister32(instr->result())));

// If the divisor is positive, things are easy: There can be no deopts and we
   // can simply do an arithmetic right shift.
   if (divisor == 1) return;
   int32_t shift = WhichPowerOf2Abs(divisor);
   if (divisor > 1) {
-    __ Mov(dividend, Operand(dividend, ASR, shift));
+    __ Mov(result, Operand(dividend, ASR, shift));
     return;
   }

   // If the divisor is negative, we have to negate and handle edge cases.
   Label not_kmin_int, done;
-  __ Negs(dividend, dividend);
+  __ Negs(result, dividend);
   if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
     DeoptimizeIf(eq, instr->environment());
   }
-  if (instr->hydrogen()->left()->RangeCanInclude(kMinInt)) {
+  if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
// Note that we could emit branch-free code, but that would need one more
     // register.
-    __ B(vc, &not_kmin_int);
     if (divisor == -1) {
-      Deoptimize(instr->environment());
+      DeoptimizeIf(vs, instr->environment());
     } else {
-      __ Mov(dividend, kMinInt / divisor);
+      __ B(vc, &not_kmin_int);
+      __ Mov(result, kMinInt / divisor);
       __ B(&done);
     }
   }
   __ bind(&not_kmin_int);
-  __ Mov(dividend, Operand(dividend, ASR, shift));
+  __ Mov(result, Operand(dividend, ASR, shift));
   __ bind(&done);
 }

=======================================
--- /branches/bleeding_edge/src/arm/lithium-arm.cc Thu Mar 13 06:11:52 2014 UTC +++ /branches/bleeding_edge/src/arm/lithium-arm.cc Thu Mar 13 07:58:58 2014 UTC
@@ -1316,13 +1316,13 @@
LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
   LOperand* dividend = UseRegisterAtStart(instr->left());
   int32_t divisor = instr->right()->GetInteger32Constant();
-  LInstruction* result =
-      DefineSameAsFirst(
-          new(zone()) LFlooringDivByPowerOf2I(dividend, divisor));
-  bool can_deopt =
-      (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
-      (instr->left()->RangeCanInclude(kMinInt) && divisor == -1);
-  return can_deopt ? AssignEnvironment(result) : result;
+ LInstruction* result = DefineAsRegister(new(zone()) LFlooringDivByPowerOf2I(
+          dividend, divisor));
+  if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
+      (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
+    result = AssignEnvironment(result);
+  }
+  return result;
 }


=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Thu Mar 13 06:11:52 2014 UTC +++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Thu Mar 13 07:58:58 2014 UTC
@@ -1458,38 +1458,36 @@

 void LCodeGen::DoFlooringDivByPowerOf2I(LFlooringDivByPowerOf2I* instr) {
   Register dividend = ToRegister(instr->dividend());
+  Register result = ToRegister(instr->result());
   int32_t divisor = instr->divisor();
-  ASSERT(dividend.is(ToRegister(instr->result())));

// If the divisor is positive, things are easy: There can be no deopts and we
   // can simply do an arithmetic right shift.
   if (divisor == 1) return;
   int32_t shift = WhichPowerOf2Abs(divisor);
   if (divisor > 1) {
-    __ mov(dividend, Operand(dividend, ASR, shift));
+    __ mov(result, Operand(dividend, ASR, shift));
     return;
   }

   // If the divisor is negative, we have to negate and handle edge cases.
-  Label not_kmin_int, done;
-  __ rsb(dividend, dividend, Operand::Zero(), SetCC);
+  __ rsb(result, dividend, Operand::Zero(), SetCC);
   if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
     DeoptimizeIf(eq, instr->environment());
   }
-  if (instr->hydrogen()->left()->RangeCanInclude(kMinInt)) {
+  if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
// Note that we could emit branch-free code, but that would need one more
     // register.
-    __ b(vc, &not_kmin_int);
     if (divisor == -1) {
-      DeoptimizeIf(al, instr->environment());
+      DeoptimizeIf(vs, instr->environment());
+      __ mov(result, Operand(dividend, ASR, shift));
     } else {
-      __ mov(dividend, Operand(kMinInt / divisor));
-      __ b(&done);
+      __ mov(result, Operand(kMinInt / divisor), LeaveCC, vs);
+      __ mov(result, Operand(dividend, ASR, shift), LeaveCC, vc);
     }
+  } else {
+    __ mov(result, Operand(dividend, ASR, shift));
   }
-  __ bind(&not_kmin_int);
-  __ mov(dividend, Operand(dividend, ASR, shift));
-  __ bind(&done);
 }


=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Thu Mar 13 06:11:52 2014 UTC +++ /branches/bleeding_edge/src/hydrogen-instructions.cc Thu Mar 13 07:58:58 2014 UTC
@@ -1799,7 +1799,7 @@
 }


-Range* HBinaryOperation::InferRangeForDiv(Zone* zone) {
+Range* HDiv::InferRange(Zone* zone) {
   if (representation().IsInteger32()) {
     Range* a = left()->range();
     Range* b = right()->range();
@@ -1821,13 +1821,29 @@
 }


-Range* HDiv::InferRange(Zone* zone) {
-  return InferRangeForDiv(zone);
-}
+Range* HMathFloorOfDiv::InferRange(Zone* zone) {
+  if (representation().IsInteger32()) {
+    Range* a = left()->range();
+    Range* b = right()->range();
+    Range* result = new(zone) Range();
+    result->set_can_be_minus_zero(!CheckFlag(kAllUsesTruncatingToInt32) &&
+                                  (a->CanBeMinusZero() ||
+ (a->CanBeZero() && b->CanBeNegative())));
+    if (!a->Includes(kMinInt)) {
+      ClearFlag(kLeftCanBeMinInt);
+    }

+    if (!a->Includes(kMinInt) || !b->Includes(-1)) {
+      ClearFlag(kCanOverflow);
+    }

-Range* HMathFloorOfDiv::InferRange(Zone* zone) {
-  return InferRangeForDiv(zone);
+    if (!b->CanBeZero()) {
+      ClearFlag(kCanBeDivByZero);
+    }
+    return result;
+  } else {
+    return HValue::InferRange(zone);
+  }
 }


=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Thu Mar 13 06:11:52 2014 UTC +++ /branches/bleeding_edge/src/hydrogen-instructions.h Thu Mar 13 07:58:58 2014 UTC
@@ -622,6 +622,7 @@
     kCanOverflow,
     kBailoutOnMinusZero,
     kCanBeDivByZero,
+    kLeftCanBeMinInt,
     kAllowUndefinedAsNaN,
     kIsArguments,
     kTruncatingToInt32,
@@ -855,9 +856,6 @@
   // TODO(svenpanne) We should really use the null object pattern here.
   bool HasRange() const { return range_ != NULL; }
bool CanBeNegative() const { return !HasRange() || range()->CanBeNegative(); }
-  bool RangeCanInclude(int value) const {
-    return !HasRange() || range()->Includes(value);
-  }
   void AddNewRange(Range* r, Zone* zone);
   void RemoveLastAddedRange();
   void ComputeInitialRange(Zone* zone);
@@ -3765,9 +3763,6 @@

   DECLARE_ABSTRACT_INSTRUCTION(BinaryOperation)

- protected:
-  Range* InferRangeForDiv(Zone* zone);
-
  private:
   bool IgnoreObservedOutputRepresentation(Representation current_rep);

@@ -4109,6 +4104,7 @@
     SetFlag(kUseGVN);
     SetFlag(kCanOverflow);
     SetFlag(kCanBeDivByZero);
+    SetFlag(kLeftCanBeMinInt);
     SetFlag(kAllowUndefinedAsNaN);
   }

=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Thu Mar 13 06:11:52 2014 UTC +++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Thu Mar 13 07:58:58 2014 UTC
@@ -1637,13 +1637,13 @@
   if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
     DeoptimizeIf(zero, instr->environment());
   }
-  if (instr->hydrogen()->left()->RangeCanInclude(kMinInt)) {
+  if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
// Note that we could emit branch-free code, but that would need one more
     // register.
-    __ j(no_overflow, &not_kmin_int, Label::kNear);
     if (divisor == -1) {
-      DeoptimizeIf(no_condition, instr->environment());
+      DeoptimizeIf(overflow, instr->environment());
     } else {
+      __ j(no_overflow, &not_kmin_int, Label::kNear);
       __ mov(dividend, Immediate(kMinInt / divisor));
       __ jmp(&done, Label::kNear);
     }
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-ia32.cc Thu Mar 13 06:11:52 2014 UTC +++ /branches/bleeding_edge/src/ia32/lithium-ia32.cc Thu Mar 13 07:58:58 2014 UTC
@@ -1409,12 +1409,13 @@
LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
   LOperand* dividend = UseRegisterAtStart(instr->left());
   int32_t divisor = instr->right()->GetInteger32Constant();
-  LInstruction* result =
- DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor));
-  bool can_deopt =
-      (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
-      (instr->left()->RangeCanInclude(kMinInt) && divisor == -1);
-  return can_deopt ? AssignEnvironment(result) : result;
+ LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
+          dividend, divisor));
+  if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
+      (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
+    result = AssignEnvironment(result);
+  }
+  return result;
 }


=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Thu Mar 13 06:11:52 2014 UTC +++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Thu Mar 13 07:58:58 2014 UTC
@@ -1129,7 +1129,7 @@
   if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
     DeoptimizeIf(zero, instr->environment());
   }
-  if (instr->hydrogen()->left()->RangeCanInclude(kMinInt)) {
+  if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
// Note that we could emit branch-free code, but that would need one more
     // register.
     __ j(no_overflow, &not_kmin_int, Label::kNear);
=======================================
--- /branches/bleeding_edge/src/x64/lithium-x64.cc Thu Mar 13 06:11:52 2014 UTC +++ /branches/bleeding_edge/src/x64/lithium-x64.cc Thu Mar 13 07:58:58 2014 UTC
@@ -1330,12 +1330,13 @@
LInstruction* LChunkBuilder::DoFlooringDivByPowerOf2I(HMathFloorOfDiv* instr) {
   LOperand* dividend = UseRegisterAtStart(instr->left());
   int32_t divisor = instr->right()->GetInteger32Constant();
-  LInstruction* result =
- DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(dividend, divisor));
-  bool can_deopt =
-      (instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
-      (instr->left()->RangeCanInclude(kMinInt) && divisor == -1);
-  return can_deopt ? AssignEnvironment(result) : result;
+ LInstruction* result = DefineSameAsFirst(new(zone()) LFlooringDivByPowerOf2I(
+          dividend, divisor));
+  if ((instr->CheckFlag(HValue::kBailoutOnMinusZero) && divisor < 0) ||
+      (instr->CheckFlag(HValue::kLeftCanBeMinInt) && divisor == -1)) {
+    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