From 531f7ab1d2ae78fba35cbfac94cae98cf306f8ac Mon Sep 17 00:00:00 2001 From: dtc-v8 Date: Mon, 26 Jan 2015 06:11:25 -0800 Subject: [PATCH] [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} --- AUTHORS | 1 + src/compiler/typer.cc | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/AUTHORS b/AUTHORS index af57f20..c22d2e1 100644 --- a/AUTHORS +++ b/AUTHORS @@ -46,6 +46,7 @@ Craig Schlenter Christopher A. Taylor Daniel Andersson Daniel James +Douglas Crosher Erich Ocean Fedor Indutny Felix Geisendörfer diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc index 976a1b6..2f0cbf1 100644 --- a/src/compiler/typer.cc +++ b/src/compiler/typer.cc @@ -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(max) >> static_cast(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(min) >> static_cast(rhs->Min()); + } } if (rhs->Min() > 0 && rhs->Max() <= 31) { // Right-shifting by a positive value yields a small integer value. -- 2.7.4