Fix a bug in Div when all uses are truncating

Refine the related test cases to cover truncating cases

BUG=
R=jkummerow@chromium.org

Review URL: https://codereview.chromium.org/22964004

Patch from Weiliang Lin <weiliang.lin2@gmail.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16249 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 02fdc411
......@@ -1398,6 +1398,7 @@ void LCodeGen::DoDivI(LDivI* instr) {
__ rsb(dividend, dividend, Operand(0), LeaveCC, lt);
__ mov(dividend, Operand(dividend, ASR, power));
if (divisor > 0) __ rsb(dividend, dividend, Operand(0), LeaveCC, lt);
if (divisor < 0) __ rsb(dividend, dividend, Operand(0), LeaveCC, gt);
return; // Don't fall through to "__ rsb" below.
} else {
// Deoptimize if remainder is not 0.
......
......@@ -1462,6 +1462,7 @@ void LCodeGen::DoDivI(LDivI* instr) {
__ cmp(dividend, 0);
__ j(less, &negative, Label::kNear);
__ sar(dividend, power);
if (divisor < 0) __ neg(dividend);
__ jmp(&done, Label::kNear);
__ bind(&negative);
......
......@@ -1216,6 +1216,7 @@ void LCodeGen::DoDivI(LDivI* instr) {
__ cmpl(dividend, Immediate(0));
__ j(less, &negative, Label::kNear);
__ sarl(dividend, Immediate(power));
if (divisor < 0) __ negl(dividend);
__ jmp(&done, Label::kNear);
__ bind(&negative);
......
......@@ -25,35 +25,63 @@
// (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 divp4(x) {
return x / 4;
}
for (var i = 0; i < 10000; i+=4) {
assertEquals(i >> 2, divp4(i));
}
divp4(8);
divp4(8);
%OptimizeFunctionOnNextCall(divp4);
assertEquals(2, divp4(8));
assertEquals(0.5, divp4(2));
function divn4(x) {
return x / (-4);
}
for (var i = 0; i < 10000; i+=4) {
assertEquals(-(i >> 2), divn4(i));
}
divn4(8);
divn4(8);
%OptimizeFunctionOnNextCall(divn4);
assertEquals(-2, divn4(8));
// Check for (0 / -x)
assertEquals(-0, divn4(0));
// Check for (kMinInt / -1)
function divn1(x) {
return x / (-1);
}
for (var i = 0; i < 10000; i++) {
assertEquals(-i, divn1(i));
var two_31 = 1 << 31;
divn1(2);
divn1(2);
%OptimizeFunctionOnNextCall(divn1);
assertEquals(-2, divn1(2));
assertEquals(two_31, divn1(-two_31));
//Check for truncating to int32 case
function divp4t(x) {
return (x / 4) | 0;
}
var min_int = -(0x7FFFFFFF)-1;
assertEquals(-min_int, divn1(min_int));
divp4t(8);
divp4t(8);
%OptimizeFunctionOnNextCall(divp4t);
assertEquals(-1, divp4t(-5));
assertEquals(1, divp4t(5));
assertOptimized(divp4t);
function divn4t(x) {
return (x / -4) | 0;
}
divn4t(8);
divn4t(8);
%OptimizeFunctionOnNextCall(divn4t);
assertEquals(1, divn4t(-5));
assertEquals(-1, divn4t(5));
assertOptimized(divn4t);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment