2f2e8c4024
With smi feedback, we use int32 operations for arithmetics. When negating 0, we have to fallback to float as we can't represent -0 in int32. We can simply deopt in that case without causing a deopt loop, as a non-smi result will change the feedback to kSignedSmallInputs (from kSignedSmall). Bug: chromium:1403102 Change-Id: Ic27c267349a1de6904639e91b1cade2c4f7d1fe2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4122829 Reviewed-by: Victor Gomes <victorgomes@chromium.org> Commit-Queue: Patrick Thier <pthier@chromium.org> Auto-Submit: Patrick Thier <pthier@chromium.org> Cr-Commit-Position: refs/heads/main@{#84998}
68 lines
1.9 KiB
JavaScript
68 lines
1.9 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 --maglev
|
|
|
|
function negate(val) {
|
|
return -val;
|
|
}
|
|
|
|
function test_negate_int32(value, expected) {
|
|
// Warmup.
|
|
%PrepareFunctionForOptimization(negate);
|
|
%ClearFunctionFeedback(negate);
|
|
negate(1, -1);
|
|
%OptimizeMaglevOnNextCall(negate);
|
|
assertEquals(expected, negate(value));
|
|
assertTrue(isMaglevved(negate));
|
|
|
|
%DeoptimizeFunction(negate);
|
|
assertEquals(expected, negate(value));
|
|
}
|
|
|
|
test_negate_int32(1, -1);
|
|
test_negate_int32(-1, 1);
|
|
test_negate_int32(42, -42);
|
|
test_negate_int32(-42, 42);
|
|
|
|
function test_negate_float(value, expected) {
|
|
// Warmup.
|
|
%PrepareFunctionForOptimization(negate);
|
|
%ClearFunctionFeedback(negate);
|
|
negate(1.1, -1.1);
|
|
%OptimizeMaglevOnNextCall(negate);
|
|
assertEquals(expected, negate(value));
|
|
assertTrue(isMaglevved(negate));
|
|
|
|
%DeoptimizeFunction(negate);
|
|
assertEquals(expected, negate(value));
|
|
}
|
|
|
|
test_negate_float(1.23, -1.23);
|
|
test_negate_float(-1.001, 1.001);
|
|
test_negate_float(42.42, -42.42);
|
|
test_negate_float(-42.42, 42.42);
|
|
|
|
const int32_max = Math.pow(2,30)-1;
|
|
const int32_min = -Math.pow(2,31);
|
|
test_negate_float(int32_max, -int32_max);
|
|
test_negate_float(int32_min, -int32_min);
|
|
|
|
function test_negate_int32_expect_deopt(value, expected) {
|
|
// Warmup.
|
|
%PrepareFunctionForOptimization(negate);
|
|
%ClearFunctionFeedback(negate);
|
|
negate(12, -12);
|
|
%OptimizeMaglevOnNextCall(negate);
|
|
assertEquals(expected, negate(value));
|
|
assertFalse(isMaglevved(negate));
|
|
}
|
|
|
|
test_negate_int32_expect_deopt(0, -0);
|
|
test_negate_int32_expect_deopt(-0, 0);
|
|
test_negate_int32_expect_deopt(int32_min, -int32_min);
|
|
test_negate_int32_expect_deopt(-int32_min, int32_min);
|
|
test_negate_int32_expect_deopt(int32_max, -int32_max);
|
|
test_negate_int32_expect_deopt(-int32_max, int32_max);
|