[compiler] Silence NaNs in Float64Mod and Float64Atan2

Looks like these may have been missed; all other related operators
silence NaNs.

Bug: v8:7519
Change-Id: If6ee8d6e02d304ccbb4821c21386f93eab225434
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2637853
Commit-Queue: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72277}
This commit is contained in:
Jakob Gruber 2021-01-25 07:57:37 +01:00 committed by Commit Bot
parent 4777f17053
commit 107629d1c7
2 changed files with 10 additions and 9 deletions

View File

@ -615,10 +615,10 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
return ReplaceFloat64(std::numeric_limits<double>::quiet_NaN());
}
if (m.right().IsNaN()) { // x % NaN => NaN
return Replace(m.right().node());
return ReplaceFloat64(SilenceNaN(m.right().ResolvedValue()));
}
if (m.left().IsNaN()) { // NaN % x => NaN
return Replace(m.left().node());
return ReplaceFloat64(SilenceNaN(m.left().ResolvedValue()));
}
if (m.IsFoldable()) { // K % K => K (K stands for arbitrary constants)
return ReplaceFloat64(
@ -665,10 +665,10 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
case IrOpcode::kFloat64Atan2: {
Float64BinopMatcher m(node);
if (m.right().IsNaN()) {
return Replace(m.right().node());
return ReplaceFloat64(SilenceNaN(m.right().ResolvedValue()));
}
if (m.left().IsNaN()) {
return Replace(m.left().node());
return ReplaceFloat64(SilenceNaN(m.left().ResolvedValue()));
}
if (m.IsFoldable()) {
return ReplaceFloat64(base::ieee754::atan2(m.left().ResolvedValue(),

View File

@ -2427,18 +2427,19 @@ TEST_F(MachineOperatorReducerTest, Float64Atan2WithConstant) {
TEST_F(MachineOperatorReducerTest, Float64Atan2WithNaN) {
Node* const p0 = Parameter(0);
Node* const nan = Float64Constant(std::numeric_limits<double>::quiet_NaN());
const double nan = std::numeric_limits<double>::quiet_NaN();
Node* const nan_node = Float64Constant(nan);
{
Reduction const r =
Reduce(graph()->NewNode(machine()->Float64Atan2(), p0, nan));
Reduce(graph()->NewNode(machine()->Float64Atan2(), p0, nan_node));
ASSERT_TRUE(r.Changed());
EXPECT_EQ(nan, r.replacement());
EXPECT_THAT(r.replacement(), IsFloat64Constant(NanSensitiveDoubleEq(nan)));
}
{
Reduction const r =
Reduce(graph()->NewNode(machine()->Float64Atan2(), nan, p0));
Reduce(graph()->NewNode(machine()->Float64Atan2(), nan_node, p0));
ASSERT_TRUE(r.Changed());
EXPECT_EQ(nan, r.replacement());
EXPECT_THAT(r.replacement(), IsFloat64Constant(NanSensitiveDoubleEq(nan)));
}
}