Reviewers: Sven Panne,

Message:
Patch from Hirofumi Mako. Please take a look.

Description:
Fix pattern detection for replacing shifts by rotation.

BUG=2499
[email protected]


Please review this at https://chromiumcodereview.appspot.com/12047015/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/hydrogen.cc
  A + test/mjsunit/regress/regress-2499.js


Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 335a40c65ef21cac7328c5fcff4606d1532cba00..eb72a3d5c10421ea09eee9427344ff29d21d3622 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -8464,6 +8464,7 @@ static bool ShiftAmountsAllowReplaceByRotate(HValue* sa,
                                              HValue* const32_minus_sa) {
   if (!const32_minus_sa->IsSub()) return false;
   HSub* sub = HSub::cast(const32_minus_sa);
+  if (sa != sub->right()) return false;
   HValue* const32 = sub->left();
   if (!const32->IsConstant() ||
       HConstant::cast(const32)->Integer32Value() != 32) {
@@ -8492,6 +8493,7 @@ bool HOptimizedGraphBuilder::MatchRotateRight(HValue* left,
   } else {
     return false;
   }
+  if (shl->left() != shr->left()) return false;

   if (!ShiftAmountsAllowReplaceByRotate(shl->right(), shr->right()) &&
       !ShiftAmountsAllowReplaceByRotate(shr->right(), shl->right())) {
Index: test/mjsunit/regress/regress-2499.js
diff --git a/test/mjsunit/regress/regress-110509.js b/test/mjsunit/regress/regress-2499.js
similarity index 85%
copy from test/mjsunit/regress/regress-110509.js
copy to test/mjsunit/regress/regress-2499.js
index 132bd233bee32f6c84061049224ea43901dae06a..52aad874db6fcdc89f5ee1ae4db45304e64b0e77 100644
--- a/test/mjsunit/regress/regress-110509.js
+++ b/test/mjsunit/regress/regress-2499.js
@@ -1,4 +1,4 @@
-// Copyright 2012 the V8 project authors. All rights reserved.
+// Copyright 2013 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:
@@ -27,15 +27,14 @@

 // Flags: --allow-natives-syntax

-// Verify that LRandom preserves rsi correctly.
-
-function foo() {
-  Math.random();
-  new Function("");
+function foo(word, nBits) {
+  return (word[1] >>> nBits) | (word[0] << (32 - nBits));
 }

-foo();
-foo();
-foo();
+word = [0x1001, 0];
+
+var expected = foo(word, 1);
+foo(word, 1);
 %OptimizeFunctionOnNextCall(foo);
-foo();
+var optimized = foo(word, 1);
+assertEquals(expected, optimized)


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to