Commit 1d2a8e96 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[turbofan] Unify number rounding operators.

This is a follow-up cleanup to treat NumberRound like the other rounding
operations (NumberFloor, NumberCeil and NumberTrunc).

Bug: v8:8015
Change-Id: I2b2fbc7f0319497d16ccb7472595eeb68be1f51d
Reviewed-on: https://chromium-review.googlesource.com/c/1260403Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56371}
parent 7cd2cacf
......@@ -2292,17 +2292,20 @@ class RepresentationSelector {
}
case IrOpcode::kNumberCeil:
case IrOpcode::kNumberFloor:
case IrOpcode::kNumberRound:
case IrOpcode::kNumberTrunc: {
// For NumberCeil, NumberFloor and NumberTrunc we propagate the
// zero identification part of the truncation, and we turn them
// into no-ops if we figure out (late) that their input is
// already an integer, NaN or -0.
// For NumberCeil, NumberFloor, NumberRound and NumberTrunc we propagate
// the zero identification part of the truncation, and we turn them into
// no-ops if we figure out (late) that their input is already an
// integer, NaN or -0.
Type const input_type = TypeOf(node->InputAt(0));
VisitUnop(node, UseInfo::TruncatingFloat64(truncation.identify_zeros()),
MachineRepresentation::kFloat64);
if (lower()) {
if (input_type.Is(type_cache_.kIntegerOrMinusZeroOrNaN)) {
DeferReplacement(node, node->InputAt(0));
} else if (node->opcode() == IrOpcode::kNumberRound) {
DeferReplacement(node, lowering->Float64Round(node));
} else {
NodeProperties::ChangeOp(node, Float64Op(node));
}
......@@ -2333,12 +2336,6 @@ class RepresentationSelector {
if (lower()) NodeProperties::ChangeOp(node, Float64Op(node));
return;
}
case IrOpcode::kNumberRound: {
VisitUnop(node, UseInfo::TruncatingFloat64(),
MachineRepresentation::kFloat64);
if (lower()) DeferReplacement(node, lowering->Float64Round(node));
return;
}
case IrOpcode::kNumberSign: {
if (InputIs(node, Type::Signed32())) {
VisitUnop(node, UseInfo::TruncatingWord32(),
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --opt
// Test that NumberRound propagates kIdentifyZeros truncations.
(function() {
function foo(x) {
return Math.abs(Math.round(x * -2));
}
assertEquals(2, foo(1));
assertEquals(4, foo(2));
%OptimizeFunctionOnNextCall(foo);
assertEquals(2, foo(1));
assertEquals(4, foo(2));
assertOptimized(foo);
// Now `foo` should stay optimized even if `x * -2` would produce `-0`.
assertEquals(0, foo(0));
assertOptimized(foo);
})();
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