v8/test/mjsunit/compiler/bigint64-add-no-deopt-loop.js
Qifan Pan 7eb43bf494 [turbofan] Decompose CheckBigInt64 and make it precise
This CL solves two problems:

- Eliminating redundant CheckBigInt/CheckBigInt64 by decomposing
  CheckBigInt64 to CheckBigInt and CheckedBigIntToBigInt64.
- Having precise checks for SignedBigInt64 to make the range of BigInt64
  consistent in CheckedBigInt64Ops and CheckedBigIntToBigInt64.
  Otherwise, there would be semantic difference between the subgraphs
  where we keep CheckBigInt64 inbetween two CheckedBigInt64Ops (e.g.,
  the variant assert_types) and the subgraphs where we eliminate the
  checks.

Bug: v8:9407
Change-Id: I79a5c99e12eb3f3ffc7b5cbfc51191e6792f634b
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3960333
Commit-Queue: Qifan Pan <panq@google.com>
Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#83899}
2022-10-25 08:57:30 +00:00

98 lines
3.0 KiB
JavaScript

// Copyright 2022 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 --turbofan --no-always-turbofan
(function OptimizeAndTestNegativeLimit() {
function f(x, y) {
return x + y;
}
%PrepareFunctionForOptimization(f);
assertEquals(1n, f(0n, 1n));
assertEquals(5n, f(2n, 3n));
%OptimizeFunctionOnNextCall(f);
assertEquals(-(2n ** 63n), f(-(2n ** 63n), 0n));
assertOptimized(f);
// Re-prepare the function before the first deopt to ensure type feedback is
// not cleared by an umtimely gc.
%PrepareFunctionForOptimization(f);
assertOptimized(f);
// CheckBigInt64 should trigger deopt on INT_MIN - 1.
assertEquals(-(2n ** 63n) - 1n, f(-(2n ** 63n) - 1n, 0n));
if (%Is64Bit()) {
assertUnoptimized(f);
assertEquals(1n, f(0n, 1n));
assertEquals(5n, f(2n, 3n));
%OptimizeFunctionOnNextCall(f);
assertEquals(-(2n ** 63n), f(-(2n ** 63n), 0n));
assertOptimized(f);
// Ensure there is no deopt loop.
assertEquals(-(2n ** 63n) - 1n, f(-(2n ** 63n) - 1n, 0n));
assertOptimized(f);
}
})();
(function OptimizeAndTestPositiveLimit() {
function f(x, y) {
return x + y;
}
%PrepareFunctionForOptimization(f);
assertEquals(1n, f(0n, 1n));
assertEquals(5n, f(2n, 3n));
%OptimizeFunctionOnNextCall(f);
assertEquals(2n ** 63n - 1n, f(2n ** 63n - 1n, 0n));
assertOptimized(f);
// Re-prepare the function before the first deopt to ensure type feedback is
// not cleared by an umtimely gc.
%PrepareFunctionForOptimization(f);
assertOptimized(f);
// CheckBigInt64 should trigger deopt on INT_MAX + 1.
assertEquals(2n ** 63n, f(2n ** 63n, 0n));
if (%Is64Bit()) {
assertUnoptimized(f);
assertEquals(1n, f(0n, 1n));
assertEquals(5n, f(2n, 3n));
%OptimizeFunctionOnNextCall(f);
assertEquals(2n ** 63n - 1n, f(2n ** 63n - 1n, 0n));
assertOptimized(f);
// Ensure there is no deopt loop.
assertEquals(2n ** 63n, f(2n ** 63n, 0n));
assertOptimized(f);
}
})();
(function OptimizeAndTestOverflow() {
function f(x, y) {
return x + y;
}
%PrepareFunctionForOptimization(f);
assertEquals(1n, f(0n, 1n));
assertEquals(5n, f(2n, 3n));
%OptimizeFunctionOnNextCall(f);
assertEquals(9n, f(4n, 5n));
assertOptimized(f);
assertEquals(-(2n ** 63n), f(-(2n ** 62n), -(2n ** 62n)));
assertOptimized(f);
// Re-prepare the function before the first deopt to ensure type feedback is
// not cleared by an umtimely gc.
%PrepareFunctionForOptimization(f);
assertOptimized(f);
// CheckedBigInt64Add will trigger deopt due to overflow.
assertEquals(-(2n ** 63n) - 1n, f(-(2n ** 62n + 1n), -(2n ** 62n)));
if (%Is64Bit()) {
assertUnoptimized(f);
assertEquals(1n, f(0n, 1n));
assertEquals(5n, f(2n, 3n));
%OptimizeFunctionOnNextCall(f);
assertEquals(9n, f(4n, 5n));
assertOptimized(f);
// Ensure there is no deopt loop.
assertEquals(-(2n ** 63n) - 1n, f(-(2n ** 62n + 1n), -(2n ** 62n)));
assertOptimized(f);
}
})();