Commit 1b116567 authored by ahaas's avatar ahaas Committed by Commit bot

[wasm] Remove -0 -x = -x folding because of signalling NaNs.

R=titzer@chromium.org

Review-Url: https://codereview.chromium.org/2662363003
Cr-Commit-Position: refs/heads/master@{#42902}
parent 96608486
......@@ -331,7 +331,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
if (m.IsFoldable()) { // L - R => (L - R)
return ReplaceFloat32(m.left().Value() - m.right().Value());
}
if (m.left().IsMinusZero()) {
if (allow_signalling_nan_ && m.left().IsMinusZero()) {
// -0.0 - round_down(-0.0 - R) => round_up(R)
if (machine()->Float32RoundUp().IsSupported() &&
m.right().IsFloat32RoundDown()) {
......@@ -378,7 +378,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
if (m.IsFoldable()) { // L - R => (L - R)
return ReplaceFloat64(m.left().Value() - m.right().Value());
}
if (m.left().IsMinusZero()) {
if (allow_signalling_nan_ && m.left().IsMinusZero()) {
// -0.0 - round_down(-0.0 - R) => round_up(R)
if (machine()->Float64RoundUp().IsSupported() &&
m.right().IsFloat64RoundDown()) {
......@@ -437,7 +437,7 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
if (m.IsFoldable()) { // K / K => K
return ReplaceFloat64(m.left().Value() / m.right().Value());
}
if (m.right().Is(-1)) { // x / -1.0 => -x
if (allow_signalling_nan_ && m.right().Is(-1)) { // x / -1.0 => -x
node->RemoveInput(1);
NodeProperties::ChangeOp(node, machine()->Float64Neg());
return Changed(node);
......
......@@ -24,6 +24,23 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(0x7fe00000, module.exports.F32Sub0(0x7fa00000));
})();
(function() {
print("F32: -0 sNaN = qNaN");
var builder = new WasmModuleBuilder();
builder.addFunction("F32Sub0", kSig_i_i)
.addBody([
kExprF32Const, 0x00, 0x00, 0x00, 0x80, // 0.0
kExprGetLocal, 0,
kExprF32ReinterpretI32,
kExprF32Sub,
kExprI32ReinterpretF32,
])
.exportFunc();
var module = builder.instantiate();
// F32Sub0(signalling_NaN)
assertEquals(0x7fe00000, module.exports.F32Sub0(0x7fa00000));
})();
(function() {
print("F32: sNaN - X = qNaN");
var builder = new WasmModuleBuilder();
......@@ -91,6 +108,25 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(0x7ffa0000, module.exports.F64Sub0());
})();
(function() {
print("F64: -0 - sNaN = qNaN");
var builder = new WasmModuleBuilder();
builder.addFunction("F64Sub0", kSig_i_i)
.addBody([
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, // 0.0
kExprI64Const, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf9, 0xff, 0x00,
kExprF64ReinterpretI64,
kExprF64Sub,
kExprI64ReinterpretF64,
kExprI64Const, 32,
kExprI64ShrU,
kExprI32ConvertI64,
])
.exportFunc();
var module = builder.instantiate();
assertEquals(0x7ffa0000, module.exports.F64Sub0());
})();
(function() {
print("F64: sNaN - X = qNaN");
var builder = new WasmModuleBuilder();
......@@ -183,6 +219,25 @@ load("test/mjsunit/wasm/wasm-module-builder.js");
assertEquals(0x7ffa0000, module.exports.F64Div1());
})();
(function() {
print("F64: sNaN / -1 = qNaN");
var builder = new WasmModuleBuilder();
builder.addFunction("F64Div1", kSig_i_i)
.addBody([
kExprI64Const, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xf9, 0xff, 0x00,
kExprF64ReinterpretI64,
kExprF64Const, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xbf,
kExprF64Div,
kExprI64ReinterpretF64,
kExprI64Const, 32,
kExprI64ShrU,
kExprI32ConvertI64,
])
.exportFunc();
var module = builder.instantiate();
assertEquals(0x7ffa0000, module.exports.F64Div1());
})();
(function() {
print("F64: X / sNaN = qNaN");
var builder = new WasmModuleBuilder();
......
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