f426a5a778
For SignedSmall binary ops, we know that the output has to fit in a Smi. So, emit a Smi check eagerly after these operations, so that future Smi untagging knows that it doesn't need to do a check. Bug: v8:7700 Change-Id: I117c55caa5e2ebe870fd964908564d74df726546 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4020434 Reviewed-by: Toon Verwaest <verwaest@chromium.org> Commit-Queue: Leszek Swirski <leszeks@chromium.org> Auto-Submit: Leszek Swirski <leszeks@chromium.org> Commit-Queue: Toon Verwaest <verwaest@chromium.org> Cr-Commit-Position: refs/heads/main@{#84223}
83 lines
2.4 KiB
JavaScript
83 lines
2.4 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
|
|
|
|
// This examples creates a simple exception handler block where the trampoline
|
|
// has an int32 value and needs to convert to a tagged value.
|
|
function foo_int32() {
|
|
let x = 1;
|
|
try {
|
|
x = x + x;
|
|
throw "Error";
|
|
} catch {
|
|
return x;
|
|
}
|
|
}
|
|
%PrepareFunctionForOptimization(foo_int32);
|
|
assertEquals(foo_int32(), 2);
|
|
%OptimizeMaglevOnNextCall(foo_int32);
|
|
assertEquals(foo_int32(), 2);
|
|
|
|
// TODO(leszeks): There is currently no way for this to happen, because all
|
|
// Int32 ops are eagerly checked for Smi overflow.
|
|
//
|
|
// // This examples creates a simple exception handler block where the trampoline
|
|
// // has an int32 value that overflows and it needs to create a HeapNumber.
|
|
// function foo_int32_overflow(x) {
|
|
// try {
|
|
// x = x + x;
|
|
// throw "Error";
|
|
// } catch {
|
|
// return x;
|
|
// }
|
|
// }
|
|
// %PrepareFunctionForOptimization(foo_int32_overflow);
|
|
// assertEquals(foo_int32_overflow(1), 2);
|
|
// %OptimizeMaglevOnNextCall(foo_int32_overflow);
|
|
// assertEquals(foo_int32_overflow(0x3FFFFFFF), 0x7FFFFFFE);
|
|
// assertTrue(%ActiveTierIsMaglev(foo_int32_overflow));
|
|
// // If we call it with a HeapNumber, we deopt before the exception:
|
|
// assertEquals(foo_int32_overflow(1.1), 2.2);
|
|
// assertTrue(%ActiveTierIsMaglev(foo_int32_overflow));
|
|
|
|
// This examples creates a simple exception handler block where the trampoline
|
|
// has an float64 value and needs to convert to a tagged value.
|
|
function foo_float64() {
|
|
let x = 1.1;
|
|
try {
|
|
x = x + x;
|
|
throw "Error";
|
|
} catch {
|
|
return x;
|
|
}
|
|
}
|
|
%PrepareFunctionForOptimization(foo_float64);
|
|
assertEquals(foo_float64(), 2.2);
|
|
%OptimizeMaglevOnNextCall(foo_float64);
|
|
assertEquals(foo_float64(), 2.2);
|
|
|
|
// Combination of previous examples with a big number of registers.
|
|
// This creates a _quite_ large trampoline.
|
|
function foo() {
|
|
let x = 1;
|
|
let y = 1.1;
|
|
let a, b, c, d, e, f, g, h;
|
|
a = b = c = d = e = f = g = h = 0;
|
|
let p, q, r, s, t;
|
|
try {
|
|
x = x + x;
|
|
y = y + y;
|
|
p = q = r = s = t = x;
|
|
throw "Error";
|
|
} catch {
|
|
return x + y + a + b + c + d + e + f + g + h
|
|
+ p + q + r + s + t;
|
|
}
|
|
}
|
|
%PrepareFunctionForOptimization(foo);
|
|
assertEquals(foo(), 14.2);
|
|
%OptimizeMaglevOnNextCall(foo);
|
|
assertEquals(foo(), 14.2);
|