Commit bb389dc7 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[turbofan] Add Word64 support to NumberMin and NumberMax.

For NumberMin and NumberMax we don't need to go to Float64 when the
inputs are known to be in SafeInteger range, instead we can go to
Word64 on 64-bit architectures. This is preliminary work for the
huge DataView support, since we'll utilize NumberMax in that case
to clamp the limit for the bounds check.

Bug: v8:8178, v8:8383
Change-Id: I414114229c5c86b92749d30d645cedc641541ae4
Reviewed-on: https://chromium-review.googlesource.com/c/1304535Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57090}
parent cc70a6b0
......@@ -2234,6 +2234,14 @@ class RepresentationSelector {
lowering->DoMax(node, lowering->machine()->Int32LessThan(),
MachineRepresentation::kWord32);
}
} else if (jsgraph_->machine()->Is64() &&
lhs_type.Is(type_cache_.kSafeInteger) &&
rhs_type.Is(type_cache_.kSafeInteger)) {
VisitInt64Binop(node);
if (lower()) {
lowering->DoMax(node, lowering->machine()->Int64LessThan(),
MachineRepresentation::kWord64);
}
} else {
VisitBinop(node,
UseInfo::TruncatingFloat64(truncation.identify_zeros()),
......@@ -2280,6 +2288,14 @@ class RepresentationSelector {
lowering->DoMin(node, lowering->machine()->Int32LessThan(),
MachineRepresentation::kWord32);
}
} else if (jsgraph_->machine()->Is64() &&
lhs_type.Is(type_cache_.kSafeInteger) &&
rhs_type.Is(type_cache_.kSafeInteger)) {
VisitInt64Binop(node);
if (lower()) {
lowering->DoMin(node, lowering->machine()->Int64LessThan(),
MachineRepresentation::kWord64);
}
} else {
VisitBinop(node,
UseInfo::TruncatingFloat64(truncation.identify_zeros()),
......
......@@ -21,3 +21,17 @@
assertEquals(0, foo(0));
assertOptimized(foo);
})();
// Test that NumberMax properly handles 64-bit comparisons.
(function() {
function foo(x) {
x = x|0;
return Math.max(x - 1, x + 1);
}
assertEquals(-Math.pow(2, 31) + 1, foo(-Math.pow(2, 31)));
assertEquals(Math.pow(2, 31), foo(Math.pow(2, 31) - 1));
%OptimizeFunctionOnNextCall(foo);
assertEquals(-Math.pow(2, 31) + 1, foo(-Math.pow(2, 31)));
assertEquals(Math.pow(2, 31), foo(Math.pow(2, 31) - 1));
})();
......@@ -21,3 +21,17 @@
assertEquals(1, foo(0));
assertOptimized(foo);
})();
// Test that NumberMin properly handles 64-bit comparisons.
(function() {
function foo(x) {
x = x|0;
return Math.min(x - 1, x + 1);
}
assertEquals(-Math.pow(2, 31) - 1, foo(-Math.pow(2, 31)));
assertEquals(Math.pow(2, 31) - 2, foo(Math.pow(2, 31) - 1));
%OptimizeFunctionOnNextCall(foo);
assertEquals(-Math.pow(2, 31) - 1, foo(-Math.pow(2, 31)));
assertEquals(Math.pow(2, 31) - 2, foo(Math.pow(2, 31) - 1));
})();
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