[turbofan] Better narrow the derived type for the right shift operation.
authordtc-v8 <dtc-v8@scieneer.com>
Mon, 26 Jan 2015 14:11:25 +0000 (06:11 -0800)
committerCommit bot <commit-bot@chromium.org>
Mon, 26 Jan 2015 14:11:36 +0000 (14:11 +0000)
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}

AUTHORS
src/compiler/typer.cc

diff --git a/AUTHORS b/AUTHORS
index af57f20..c22d2e1 100644 (file)
--- a/AUTHORS
+++ b/AUTHORS
@@ -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>
index 976a1b6..2f0cbf1 100644 (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.