[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}
This commit is contained in:
dtc-v8 2015-01-26 06:11:25 -08:00 committed by Commit bot
parent 379dcd5bd4
commit 531f7ab1d2
2 changed files with 7 additions and 0 deletions

View File

@ -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>

View File

@ -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.