Commit 5c4267d5 authored by Qifan Pan's avatar Qifan Pan Committed by V8 LUCI CQ

[turbofan] Lower BigInt multiply with truncation information

Bug: v8:9407
Change-Id: Id4ca4682d3fe4b2222a656c80dff95e5c099d5ed
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3822671Reviewed-by: 's avatarNico Hartmann <nicohartmann@chromium.org>
Commit-Queue: Qifan Pan <panq@google.com>
Cr-Commit-Position: refs/heads/main@{#82524}
parent 6ec7be21
...@@ -3225,11 +3225,20 @@ class RepresentationSelector { ...@@ -3225,11 +3225,20 @@ class RepresentationSelector {
return; return;
} }
case IrOpcode::kSpeculativeBigIntMultiply: { case IrOpcode::kSpeculativeBigIntMultiply: {
VisitBinop<T>(node, if (truncation.IsUsedAsWord64()) {
UseInfo::CheckedBigIntAsTaggedPointer(FeedbackSource{}), VisitBinop<T>(
MachineRepresentation::kTaggedPointer); node, UseInfo::CheckedBigIntTruncatingWord64(FeedbackSource{}),
if (lower<T>()) { MachineRepresentation::kWord64);
ChangeOp(node, lowering->simplified()->BigIntMultiply()); if (lower<T>()) {
ChangeToPureOp(node, lowering->machine()->Int64Mul());
}
} else {
VisitBinop<T>(node,
UseInfo::CheckedBigIntAsTaggedPointer(FeedbackSource{}),
MachineRepresentation::kTaggedPointer);
if (lower<T>()) {
ChangeOp(node, lowering->simplified()->BigIntMultiply());
}
} }
return; return;
} }
......
// 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 TestMultiplyAndTruncate(a, b) {
return BigInt.asIntN(3, a * b);
}
function OptimizeAndTest(fn) {
let bi = 2n ** (2n ** 29n);
// Before optimization, a BigIntTooBig exception is expected
assertThrows(() => fn(bi + 3n, bi + 4n), RangeError);
if (%Is64Bit()) {
%PrepareFunctionForOptimization(fn);
assertEquals(-4n, fn(3n, 4n));
assertEquals(-2n, fn(5n, 6n));
%OptimizeFunctionOnNextCall(fn);
// After optimization, operands are truncated to Word64
// before being multiplied. No exceptions should be thrown
// and the correct result is expected.
assertEquals(-4n, fn(bi + 3n, bi + 4n));
assertOptimized(fn);
}
}
OptimizeAndTest(TestMultiplyAndTruncate);
...@@ -10,12 +10,12 @@ function TestMultiply(a, b) { ...@@ -10,12 +10,12 @@ function TestMultiply(a, b) {
function OptimizeAndTest(fn) { function OptimizeAndTest(fn) {
%PrepareFunctionForOptimization(fn); %PrepareFunctionForOptimization(fn);
assertEquals(fn(3n, 4n), 12n); assertEquals(12n, fn(3n, 4n));
assertEquals(fn(5n, 6n), 30n); assertEquals(30n, fn(5n, 6n));
%OptimizeFunctionOnNextCall(fn); %OptimizeFunctionOnNextCall(fn);
assertEquals(fn(7n, 8n), 56n); assertEquals(56n, fn(7n, 8n));
assertOptimized(fn); assertOptimized(fn);
assertEquals(fn(7, 8), 56); assertEquals(56, fn(7, 8));
assertUnoptimized(fn); assertUnoptimized(fn);
} }
......
...@@ -1361,7 +1361,10 @@ ...@@ -1361,7 +1361,10 @@
# which in turn can lead to different deopt behavior. # which in turn can lead to different deopt behavior.
'compiler/number-abs': [SKIP], 'compiler/number-abs': [SKIP],
'compiler/number-toboolean': [SKIP], 'compiler/number-toboolean': [SKIP],
'wasm/bigint-opt': [SKIP], # Type assertions block the propagation of word64 truncation useinfo,
# leading to differences in representation selection.
'compiler/bigint-multiply-truncate': [SKIP],
'wasm/bigint-opt': [SKIP]
}], # variant == assert_types }], # variant == assert_types
############################################################################## ##############################################################################
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment