Commit 531f7ab1 authored by dtc-v8's avatar dtc-v8 Committed by Commit bot

[turbofan] Better narrow the derived type for the right shift operation.

Currently the derived type of a right shift does not narrow the input
type based on the actual shift amount - well it does some narrowing
but more can be down. For patterns such as u32[i>>2], which is very
common is asm.js code, this limits the ability to later prove that an
index bounds check is unnecessary which can have a significant
performance impact.

Review URL: https://codereview.chromium.org/873143002

Cr-Commit-Position: refs/heads/master@{#26270}
parent 379dcd5b
......@@ -46,6 +46,7 @@ Craig Schlenter <craig.schlenter@gmail.com>
Christopher A. Taylor <chris@gameclosure.com>
Daniel Andersson <kodandersson@gmail.com>
Daniel James <dnljms@gmail.com>
Douglas Crosher <dtc-v8@scieneer.com>
Erich Ocean <erich.ocean@me.com>
Fedor Indutny <fedor@indutny.com>
Felix Geisendörfer <haimuiba@gmail.com>
......
......@@ -916,11 +916,17 @@ Type* Typer::Visitor::JSShiftRightTyper(Type* lhs, Type* rhs, Typer* t) {
// Right-shifting a non-negative value cannot make it negative, nor larger.
min = std::max(min, 0.0);
max = std::min(max, lhs->Max());
if (rhs->Min() > 0 && rhs->Max() <= 31) {
max = static_cast<int>(max) >> static_cast<int>(rhs->Min());
}
}
if (lhs->Max() < 0) {
// Right-shifting a negative value cannot make it non-negative, nor smaller.
min = std::max(min, lhs->Min());
max = std::min(max, -1.0);
if (rhs->Min() > 0 && rhs->Max() <= 31) {
min = static_cast<int>(min) >> static_cast<int>(rhs->Min());
}
}
if (rhs->Min() > 0 && rhs->Max() <= 31) {
// Right-shifting by a positive value yields a small integer value.
......
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