Revision: 21769
Author:   [email protected]
Date:     Wed Jun 11 13:29:25 2014 UTC
Log:      Fixed flooring division by a power of 2, once again...

Avoid right shifts by zero bits: On ARM it actually means shifting by
32 bits (correctness issue) and on other platforms they are useless
(performance issue). This is fix for the fix in r20544.

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

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

Modified:
 /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc
 /branches/bleeding_edge/src/arm64/lithium-codegen-arm64.cc
 /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
 /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
 /branches/bleeding_edge/test/mjsunit/mjsunit.status

=======================================
--- /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Wed Jun 11 09:09:15 2014 UTC +++ /branches/bleeding_edge/src/arm/lithium-codegen-arm.cc Wed Jun 11 13:29:25 2014 UTC
@@ -1469,20 +1469,22 @@
     DeoptimizeIf(eq, instr->environment());
   }

-  // If the negation could not overflow, simply shifting is OK.
-  if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
-    __ mov(result, Operand(dividend, ASR, shift));
+  // Dividing by -1 is basically negation, unless we overflow.
+  if (divisor == -1) {
+    if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+      DeoptimizeIf(vs, instr->environment());
+    }
     return;
   }

-  // Dividing by -1 is basically negation, unless we overflow.
-  if (divisor == -1) {
-    DeoptimizeIf(vs, instr->environment());
+  // If the negation could not overflow, simply shifting is OK.
+  if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+    __ mov(result, Operand(result, ASR, shift));
     return;
   }

   __ mov(result, Operand(kMinInt / divisor), LeaveCC, vs);
-  __ mov(result, Operand(dividend, ASR, shift), LeaveCC, vc);
+  __ mov(result, Operand(result, ASR, shift), LeaveCC, vc);
 }


=======================================
--- /branches/bleeding_edge/src/arm64/lithium-codegen-arm64.cc Wed Jun 11 09:09:15 2014 UTC +++ /branches/bleeding_edge/src/arm64/lithium-codegen-arm64.cc Wed Jun 11 13:29:25 2014 UTC
@@ -3933,19 +3933,21 @@
     DeoptimizeIf(eq, instr->environment());
   }

-  // If the negation could not overflow, simply shifting is OK.
-  if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
-    __ Mov(result, Operand(dividend, ASR, shift));
+  // Dividing by -1 is basically negation, unless we overflow.
+  if (divisor == -1) {
+    if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+      DeoptimizeIf(vs, instr->environment());
+    }
     return;
   }

-  // Dividing by -1 is basically negation, unless we overflow.
-  if (divisor == -1) {
-    DeoptimizeIf(vs, instr->environment());
+  // If the negation could not overflow, simply shifting is OK.
+  if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+    __ Mov(result, Operand(dividend, ASR, shift));
     return;
   }

-  __ Asr(result, dividend, shift);
+  __ Asr(result, result, shift);
   __ Csel(result, result, kMinInt / divisor, vc);
 }

=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Wed Jun 11 09:09:15 2014 UTC +++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Wed Jun 11 13:29:25 2014 UTC
@@ -1353,14 +1353,17 @@
     DeoptimizeIf(zero, instr->environment());
   }

-  if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
-    __ sar(dividend, shift);
+  // Dividing by -1 is basically negation, unless we overflow.
+  if (divisor == -1) {
+    if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+      DeoptimizeIf(overflow, instr->environment());
+    }
     return;
   }

-  // Dividing by -1 is basically negation, unless we overflow.
-  if (divisor == -1) {
-    DeoptimizeIf(overflow, instr->environment());
+  // If the negation could not overflow, simply shifting is OK.
+  if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+    __ sar(dividend, shift);
     return;
   }

=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Wed Jun 11 09:09:15 2014 UTC +++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Wed Jun 11 13:29:25 2014 UTC
@@ -1133,19 +1133,20 @@
   if (instr->hydrogen()->CheckFlag(HValue::kBailoutOnMinusZero)) {
     DeoptimizeIf(zero, instr->environment());
   }
+
+  // Dividing by -1 is basically negation, unless we overflow.
+  if (divisor == -1) {
+    if (instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
+      DeoptimizeIf(overflow, instr->environment());
+    }
+    return;
+  }

   // If the negation could not overflow, simply shifting is OK.
   if (!instr->hydrogen()->CheckFlag(HValue::kLeftCanBeMinInt)) {
     __ sarl(dividend, Immediate(shift));
     return;
   }
-
-  // Note that we could emit branch-free code, but that would need one more
-  // register.
-  if (divisor == -1) {
-    DeoptimizeIf(overflow, instr->environment());
-    return;
-  }

   Label not_kmin_int, done;
   __ j(no_overflow, &not_kmin_int, Label::kNear);
=======================================
--- /branches/bleeding_edge/test/mjsunit/mjsunit.status Thu Jun 5 12:53:36 2014 UTC +++ /branches/bleeding_edge/test/mjsunit/mjsunit.status Wed Jun 11 13:29:25 2014 UTC
@@ -308,10 +308,6 @@
   # Currently always deopt on minus zero
   'math-floor-of-div-minus-zero': [SKIP],

-  # Issue 3259.
-  'math-floor-of-div-nosudiv': [PASS, FAIL],
-  'math-floor-of-div': [PASS, FAIL],
-
############################################################################
   # Slow tests.
   'regress/regress-2185-2': [PASS, SLOW],

--
--
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