Deopt on overflow in integer mod.
R=ulan@chromium.org BUG=166379 Review URL: https://chromiumcodereview.appspot.com/11618017 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13241 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
b25c040c2c
commit
362218a037
@ -1342,6 +1342,11 @@ Range* HMod::InferRange(Zone* zone) {
|
||||
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);
|
||||
}
|
||||
|
@ -1168,6 +1168,17 @@ void LCodeGen::DoModI(LModI* instr) {
|
||||
|
||||
// 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();
|
||||
|
||||
|
@ -1016,6 +1016,17 @@ void LCodeGen::DoModI(LModI* instr) {
|
||||
|
||||
// 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();
|
||||
|
39
test/mjsunit/regress/regress-166379.js
Normal file
39
test/mjsunit/regress/regress-166379.js
Normal file
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user