2022-10-17 12:21:27 +00:00
|
|
|
// 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 OptimizeAndTestDivZero() {
|
|
|
|
function f(x, y) {
|
|
|
|
return x / y;
|
|
|
|
}
|
|
|
|
%PrepareFunctionForOptimization(f);
|
|
|
|
assertEquals(0n, f(0n, 1n));
|
|
|
|
assertEquals(-3n, f(-32n, 9n));
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
assertEquals(2n, f(14n, 5n));
|
|
|
|
assertOptimized(f);
|
2022-10-21 15:44:29 +00:00
|
|
|
// Re-prepare the function before the first deopt to ensure type feedback is
|
2022-11-07 15:45:10 +00:00
|
|
|
// not cleared by an untimely gc.
|
2022-10-21 15:44:29 +00:00
|
|
|
%PrepareFunctionForOptimization(f);
|
|
|
|
assertOptimized(f);
|
2022-11-07 15:45:10 +00:00
|
|
|
// CheckedInt64Div will trigger deopt due to divide-by-zero.
|
2022-10-17 12:21:27 +00:00
|
|
|
assertThrows(() => f(42n, 0n), RangeError);
|
|
|
|
if (%Is64Bit()) {
|
|
|
|
assertUnoptimized(f);
|
|
|
|
|
|
|
|
assertEquals(0n, f(0n, 1n));
|
|
|
|
assertEquals(-3n, f(-32n, 9n));
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
assertEquals(2n, f(14n, 5n));
|
|
|
|
assertOptimized(f);
|
|
|
|
// Ensure there is no deopt loop.
|
|
|
|
assertThrows(() => f(42n, 0n), RangeError);
|
|
|
|
assertOptimized(f);
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
(function OptimizeAndTestOverflow() {
|
|
|
|
function f(x, y) {
|
2022-11-07 15:45:10 +00:00
|
|
|
return x / y;
|
2022-10-17 12:21:27 +00:00
|
|
|
}
|
|
|
|
%PrepareFunctionForOptimization(f);
|
2022-11-07 15:45:10 +00:00
|
|
|
assertEquals(0n, f(0n, 1n));
|
2022-10-17 12:21:27 +00:00
|
|
|
assertEquals(-3n, f(-32n, 9n));
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
2022-11-07 15:45:10 +00:00
|
|
|
assertEquals(2n, f(14n, 5n));
|
2022-10-17 12:21:27 +00:00
|
|
|
assertOptimized(f);
|
2022-11-07 15:45:10 +00:00
|
|
|
assertEquals(-(2n ** 63n), f(-(2n ** 63n), 1n));
|
2022-10-17 12:21:27 +00:00
|
|
|
assertOptimized(f);
|
2022-10-21 15:44:29 +00:00
|
|
|
// Re-prepare the function before the first deopt to ensure type feedback is
|
|
|
|
// not cleared by an umtimely gc.
|
|
|
|
%PrepareFunctionForOptimization(f);
|
|
|
|
assertOptimized(f);
|
2022-11-07 15:45:10 +00:00
|
|
|
// CheckedInt64Div will trigger deopt due to overflow.
|
|
|
|
assertEquals(2n ** 63n, f(-(2n ** 63n), -1n));
|
2022-10-17 12:21:27 +00:00
|
|
|
if (%Is64Bit()) {
|
|
|
|
assertUnoptimized(f);
|
|
|
|
|
2022-11-07 15:45:10 +00:00
|
|
|
assertEquals(0n, f(0n, 1n));
|
|
|
|
assertEquals(-3n, f(-32n, 9n));
|
|
|
|
%OptimizeFunctionOnNextCall(f);
|
|
|
|
assertEquals(2n, f(14n, 5n));
|
2022-10-17 12:21:27 +00:00
|
|
|
assertOptimized(f);
|
|
|
|
// Ensure there is no deopt loop.
|
2022-11-07 15:45:10 +00:00
|
|
|
assertEquals(2n ** 63n, f(-(2n ** 63n), -1n));
|
2022-10-17 12:21:27 +00:00
|
|
|
assertOptimized(f);
|
|
|
|
}
|
|
|
|
})();
|