Revision: 13241
Author: [email protected]
Date: Wed Dec 19 04:01:22 2012
Log: Deopt on overflow in integer mod.
[email protected]
BUG=166379
Review URL: https://chromiumcodereview.appspot.com/11618017
http://code.google.com/p/v8/source/detail?r=13241
Added:
/branches/bleeding_edge/test/mjsunit/regress/regress-166379.js
Modified:
/branches/bleeding_edge/src/hydrogen-instructions.cc
/branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc
/branches/bleeding_edge/src/x64/lithium-codegen-x64.cc
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/regress/regress-166379.js Wed Dec
19 04:01:22 2012
@@ -0,0 +1,39 @@
+// Copyright 2012 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above
+// copyright notice, this list of conditions and the following
+// disclaimer in the documentation and/or other materials provided
+// with the distribution.
+// * Neither the name of Google Inc. nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+// Flags: --allow-natives-syntax
+
+function mod(a, b) { return a % b; }
+
+// Feed integer type info and optimize.
+assertEquals(0, mod(4, 2));
+assertEquals(1, mod(3, 2));
+%OptimizeFunctionOnNextCall(mod);
+
+// Surprise mod with overflow.
+assertEquals(-Infinity, 1/mod(-2147483648, -1));
+
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Tue Dec 11
15:27:15 2012
+++ /branches/bleeding_edge/src/hydrogen-instructions.cc Wed Dec 19
04:01:22 2012
@@ -1342,6 +1342,11 @@
if (a->CanBeMinusZero() || a->CanBeNegative()) {
result->set_can_be_minus_zero(true);
}
+
+ if (right()->range()->Includes(-1) &&
left()->range()->Includes(kMinInt)) {
+ SetFlag(HValue::kCanOverflow);
+ }
+
if (!right()->range()->CanBeZero()) {
ClearFlag(HValue::kCanBeDivByZero);
}
=======================================
--- /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Tue Dec 18
08:25:45 2012
+++ /branches/bleeding_edge/src/ia32/lithium-codegen-ia32.cc Wed Dec 19
04:01:22 2012
@@ -1168,6 +1168,17 @@
// Slow case, using idiv instruction.
__ bind(&slow);
+
+ // Check for (kMinInt % -1).
+ if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
+ Label left_not_min_int;
+ __ cmp(left_reg, kMinInt);
+ __ j(not_zero, &left_not_min_int, Label::kNear);
+ __ cmp(right_reg, -1);
+ DeoptimizeIf(zero, instr->environment());
+ __ bind(&left_not_min_int);
+ }
+
// Sign extend to edx.
__ cdq();
=======================================
--- /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Tue Dec 18
08:25:45 2012
+++ /branches/bleeding_edge/src/x64/lithium-codegen-x64.cc Wed Dec 19
04:01:22 2012
@@ -1016,6 +1016,17 @@
// Slow case, using idiv instruction.
__ bind(&slow);
+
+ // Check for (kMinInt % -1).
+ if (instr->hydrogen()->CheckFlag(HValue::kCanOverflow)) {
+ Label left_not_min_int;
+ __ cmpl(left_reg, Immediate(kMinInt));
+ __ j(not_zero, &left_not_min_int, Label::kNear);
+ __ cmpl(right_reg, Immediate(-1));
+ DeoptimizeIf(zero, instr->environment());
+ __ bind(&left_not_min_int);
+ }
+
// Sign extend eax to edx.
// (We are using only the low 32 bits of the values.)
__ cdq();
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev