Reviewers: Toon Verwaest,

Description:
Avoid FP exceptions when doing integer division.

BUG=v8:3039

Please review this at https://codereview.chromium.org/104003004/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+10, -22 lines):
  M src/hydrogen-instructions.cc
  M test/mjsunit/div-mul-minus-one.js
  A + test/mjsunit/regress/regress-3039.js


Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index 4f918b3c9cd190006b003ffc023a7ecceb154e2d..e7ad219964b3946b35e81dbd76011d7e8ff2133f 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -1776,10 +1776,7 @@ Range* HDiv::InferRange(Zone* zone) {
     result->set_can_be_minus_zero(!CheckFlag(kAllUsesTruncatingToInt32) &&
                                   (a->CanBeMinusZero() ||
(a->CanBeZero() && b->CanBeNegative())));
-    if (!a->Includes(kMinInt) ||
-        !b->Includes(-1) ||
-        CheckFlag(kAllUsesTruncatingToInt32)) {
-      // It is safe to clear kCanOverflow when kAllUsesTruncatingToInt32.
+    if (!a->Includes(kMinInt) || !b->Includes(-1)) {
       ClearFlag(HValue::kCanOverflow);
     }

Index: test/mjsunit/div-mul-minus-one.js
diff --git a/test/mjsunit/div-mul-minus-one.js b/test/mjsunit/div-mul-minus-one.js index f05bf0f54c68faf8f5e5cb5f35d7a8dcbc3fb02f..5ade61492da85077e7cdb29075e79a1f69c2930f 100644
--- a/test/mjsunit/div-mul-minus-one.js
+++ b/test/mjsunit/div-mul-minus-one.js
@@ -36,9 +36,7 @@ var expected_MinInt = div(kMinInt);
 var expected_minus_zero = div(0);
 %OptimizeFunctionOnNextCall(div);
 assertEquals(expected_MinInt, div(kMinInt));
-assertOptimized(div);
 assertEquals(expected_minus_zero , div(0));
-assertOptimized(div);

 function mul(g) {
   return (g * -1) ^ 1
Index: test/mjsunit/regress/regress-3039.js
diff --git a/test/mjsunit/regress/regress-2132.js b/test/mjsunit/regress/regress-3039.js
similarity index 84%
copy from test/mjsunit/regress/regress-2132.js
copy to test/mjsunit/regress/regress-3039.js
index 9eb2dc5b073e6e3c2ce46362903d07d727de3d27..3c7f62c16e65872c786c04e5af00cfdd5f27a8ed 100644
--- a/test/mjsunit/regress/regress-2132.js
+++ b/test/mjsunit/regress/regress-3039.js
@@ -27,22 +27,15 @@

 // Flags: --allow-natives-syntax

-function mul(x, y) {
-  return (x * y) | 0;
-}
-
-mul(0, 0);
-mul(0, 0);
-%OptimizeFunctionOnNextCall(mul);
-assertEquals(0, mul(0, -1));
-assertOptimized(mul);
-
-function div(x, y) {
+function do_div(x, y) {
   return (x / y) | 0;
 }

-div(4, 2);
-div(4, 2);
-%OptimizeFunctionOnNextCall(div);
-assertEquals(1, div(5, 3));
-assertOptimized(div);
+// Preparation.
+assertEquals(17, do_div(51, 3));
+assertEquals(13, do_div(65, 5));
+%OptimizeFunctionOnNextCall(do_div);
+assertEquals(11, do_div(77, 7));
+
+// The actual test. We should not trigger a floating point exception.
+assertEquals(-2147483648, do_div(-2147483648, -1));


--
--
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/groups/opt_out.

Reply via email to