Commit 25d2268e authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[crankshaft] Fix constant folding of HDiv instruction.

R=jarin@chromium.org
TEST=mjsunit/regress/regress-crbug-662367
BUG=chromium:662367

Review-Url: https://codereview.chromium.org/2486923004
Cr-Commit-Position: refs/heads/master@{#40897}
parent 5c03cb79
...@@ -3572,7 +3572,10 @@ HInstruction* HDiv::New(Isolate* isolate, Zone* zone, HValue* context, ...@@ -3572,7 +3572,10 @@ HInstruction* HDiv::New(Isolate* isolate, Zone* zone, HValue* context,
HConstant* c_left = HConstant::cast(left); HConstant* c_left = HConstant::cast(left);
HConstant* c_right = HConstant::cast(right); HConstant* c_right = HConstant::cast(right);
if ((c_left->HasNumberValue() && c_right->HasNumberValue())) { if ((c_left->HasNumberValue() && c_right->HasNumberValue())) {
if (c_right->DoubleValue() != 0) { if (std::isnan(c_left->DoubleValue()) ||
std::isnan(c_right->DoubleValue())) {
return H_CONSTANT_DOUBLE(std::numeric_limits<double>::quiet_NaN());
} else if (c_right->DoubleValue() != 0) {
double double_res = c_left->DoubleValue() / c_right->DoubleValue(); double double_res = c_left->DoubleValue() / c_right->DoubleValue();
if (IsInt32Double(double_res)) { if (IsInt32Double(double_res)) {
return H_CONSTANT_INT(double_res); return H_CONSTANT_INT(double_res);
......
...@@ -6,18 +6,32 @@ ...@@ -6,18 +6,32 @@
var zero = 0; var zero = 0;
function f() { (function ConstantFoldZeroDivZero() {
return 0 / zero; function f() {
} return 0 / zero;
assertTrue(isNaN(f())); }
assertTrue(isNaN(f())); assertTrue(isNaN(f()));
%OptimizeFunctionOnNextCall(f); assertTrue(isNaN(f()));
assertTrue(isNaN(f())); %OptimizeFunctionOnNextCall(f);
assertTrue(isNaN(f()));
})();
function g() { (function ConstantFoldMinusZeroDivZero() {
return -0 / zero; function f() {
} return -0 / zero;
assertTrue(isNaN(g())); }
assertTrue(isNaN(g())); assertTrue(isNaN(f()));
%OptimizeFunctionOnNextCall(g); assertTrue(isNaN(f()));
assertTrue(isNaN(g())); %OptimizeFunctionOnNextCall(f);
assertTrue(isNaN(f()));
})();
(function ConstantFoldNaNDivZero() {
function f() {
return NaN / 0;
}
assertTrue(isNaN(f()));
assertTrue(isNaN(f()));
%OptimizeFunctionOnNextCall(f);
assertTrue(isNaN(f()));
})();
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