v8/test/mjsunit/maglev/add-number.js
Victor Gomes 4837f37279 [maglev] Float64 box/unbox elision
- Supports Float64 Add for SmiAdd bytecode
- Adds a Float64Constant and ChangeInt32ToFloat64 nodes
- Converts floats to tagged in Phi node inputs
- Fixes spill double representation
- Fixes materialisation during a deopt of a double in the stack

Bug: v8:7700
Change-Id: I9217a64313b4bd5d0015f935c23771ecf9a2c7ca
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3610426
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#80255}
2022-04-28 13:17:48 +00:00

89 lines
2.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 --maglev --no-stress-opt
(function() {
function add(x, y) {
return x + y;
}
%PrepareFunctionForOptimization(add);
assertEquals(4.2, add(2.1, 2.1));
%OptimizeMaglevOnNextCall(add);
assertEquals(4.2, add(2.1, 2.1));
assertTrue(isMaglevved(add));
// We don't deopt if we use smis.
assertEquals(42, add(22, 20));
assertTrue(isMaglevved(add));
// We deopt if not a number.
assertEquals("42", add("4", "2"));
assertFalse(isMaglevved(add));
})();
// Deopt in the second Float64Unbox when the first argument is a Smi.
(function() {
function add(x, y) {
return x + y;
}
%PrepareFunctionForOptimization(add);
assertEquals(4.2, add(2.1, 2.1));
%OptimizeMaglevOnNextCall(add);
assertEquals(4.2, add(2.1, 2.1));
assertTrue(isMaglevved(add));
// We deopt if not a number.
assertEquals("42", add(4, "2"));
assertFalse(isMaglevved(add));
})();
// Deopt in the second Float64Unbox when the first argument is a double.
(function() {
function add(x, y) {
return x + y;
}
%PrepareFunctionForOptimization(add);
assertEquals(4.2, add(2.1, 2.1));
%OptimizeMaglevOnNextCall(add);
assertEquals(4.2, add(2.1, 2.1));
assertTrue(isMaglevved(add));
// We deopt if not a number.
assertEquals("4.2!", add(4.2, "!"));
assertFalse(isMaglevved(add));
})();
// Emit FloatAdd through SmiAdd bytecode.
(function() {
function inc(x) {
return x + 1
}
%PrepareFunctionForOptimization(inc);
assertEquals(4.2, inc(3.2));
%OptimizeMaglevOnNextCall(inc);
assertEquals(4.2, inc(3.2));
})();
// Force the input of FloatAdd to be int32.
(function() {
function add(x, y, z) {
return (x + y) + z;
}
%PrepareFunctionForOptimization(add);
assertEquals(4.2, add(1, 3, 0.2));
%OptimizeMaglevOnNextCall(add);
assertEquals(4.2, add(1, 3, 0.2));
})();