From bc1aa93449fda5ea24c2e95ea1079a5f5145608a Mon Sep 17 00:00:00 2001 From: "erik.corry@gmail.com" Date: Wed, 17 Jun 2009 19:26:01 +0000 Subject: [PATCH] Don't strength reduce divisions by 1 or 2 as they can often be handled by an optimistic inline idiv. Review URL: http://codereview.chromium.org/125258 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@2212 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/parser.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/parser.cc b/src/parser.cc index a9a5e32..c2ec499 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -2653,10 +2653,15 @@ Expression* Parser::ParseBinaryExpression(int prec, bool accept_IN, bool* ok) { double y_val = y->AsLiteral()->handle()->Number(); int64_t y_int = static_cast(y_val); // There are rounding issues with this optimization, but they don't - // apply if the number to be divided with has a reciprocal that can - // be precisely represented as a floating point number. This is - // the case if the number is an integer power of 2. - if (static_cast(y_int) == y_val && IsPowerOf2(y_int)) { + // apply if the number to be divided with has a reciprocal that can be + // precisely represented as a floating point number. This is the case + // if the number is an integer power of 2. Negative integer powers of + // 2 work too, but for -2, -1, 1 and 2 we don't do the strength + // reduction because the inlined optimistic idiv has a reasonable + // chance of succeeding by producing a Smi answer with no remainder. + if (static_cast(y_int) == y_val && + (IsPowerOf2(y_int) || IsPowerOf2(-y_int)) && + (y_int > 2 || y_int < -2)) { y = NewNumberLiteral(1 / y_val); op = Token::MUL; } -- 2.7.4