In the case of shift amounts with two constants and if their sum is equal 32,...

In the case of shift amounts with two constants and if their sum is equal 32, then shift can also be replaced with bit rotate.

R=svenpanne@chromium.org

Review URL: https://codereview.chromium.org/24095002

Patch from Bangfu Tao <bangfu.tao@samsung.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16735 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 0daf224c
......@@ -7633,9 +7633,16 @@ HInstruction* HOptimizedGraphBuilder::BuildStringCharCodeAt(
}
// Checks if the given shift amounts have form: (sa) and (32 - sa).
// Checks if the given shift amounts have following forms:
// (N1) and (N2) with N1 + N2 = 32; (sa) and (32 - sa).
static bool ShiftAmountsAllowReplaceByRotate(HValue* sa,
HValue* const32_minus_sa) {
if (sa->IsConstant() && const32_minus_sa->IsConstant()) {
const HConstant* c1 = HConstant::cast(sa);
const HConstant* c2 = HConstant::cast(const32_minus_sa);
return c1->HasInteger32Value() && c2->HasInteger32Value() &&
(c1->Integer32Value() + c2->Integer32Value() == 32);
}
if (!const32_minus_sa->IsSub()) return false;
HSub* sub = HSub::cast(const32_minus_sa);
if (sa != sub->right()) return false;
......
......@@ -222,3 +222,89 @@ for (var i = 0; i <= 100; i++) {
assertEquals(1 << ((i % 32)), ROR4(1, i));
}
//---------------------------------------------------------
// add test cases for constant operand
//---------------------------------------------------------
// constant operand: 20
function ROR1_sa20(x) {
return (x >>> 20) | (x << 12);
}
function ROR2_sa20(x) {
return (x >>> 12) | (x << 20);
}
function ROR3_sa20(x, sa) {
return (x << 12) | (x >>> 20);
}
function ROR4_sa20(x) {
return (x << 20) | (x >>> 12);
}
// constant operand: 40
function ROR1_sa40(x) {
return (x >>> 40) | (x << -8);
}
function ROR2_sa40(x) {
return (x >>> -8) | (x << 40);
}
function ROR3_sa40(x, sa) {
return (x << -8) | (x >>> 40);
}
function ROR4_sa40(x) {
return (x << 40) | (x >>> -8);
}
// ROR1_sa20
assertEquals(ROR1(0x0000FFFF, 20), ROR1_sa20(0x0000FFFF));
assertEquals(ROR1(0x0000FFFF, 20), ROR1_sa20(0x0000FFFF));
%OptimizeFunctionOnNextCall(ROR1_sa20);
assertEquals(ROR1(0x0000FFFF, 20), ROR1_sa20(0x0000FFFF));
// ROR1_sa40
assertEquals(ROR1(0x0000FFFF, 40), ROR1_sa40(0x0000FFFF));
assertEquals(ROR1(0x0000FFFF, 40), ROR1_sa40(0x0000FFFF));
%OptimizeFunctionOnNextCall(ROR1_sa40);
assertEquals(ROR1(0x0000FFFF, 40), ROR1_sa40(0x0000FFFF));
// ROR2_sa20
assertEquals(ROR2(0xFFFFFFFF, 20), ROR2_sa20(0xFFFFFFFF));
assertEquals(ROR2(0xFFFFFFFF, 20), ROR2_sa20(0xFFFFFFFF));
%OptimizeFunctionOnNextCall(ROR2_sa20);
assertEquals(ROR2(0xFFFFFFFF, 20), ROR2_sa20(0xFFFFFFFF));
// ROR2_sa40
assertEquals(ROR2(0x0000FFFF, 40), ROR2_sa40(0x0000FFFF));
assertEquals(ROR2(0x0000FFFF, 40), ROR2_sa40(0x0000FFFF));
%OptimizeFunctionOnNextCall(ROR2_sa40);
assertEquals(ROR2(0x0000FFFF, 40), ROR2_sa40(0x0000FFFF));
// ROR3_sa20
assertEquals(ROR3(0x0000FFFF, 20), ROR3_sa20(0x0000FFFF));
assertEquals(ROR3(0x0000FFFF, 20), ROR3_sa20(0x0000FFFF));
%OptimizeFunctionOnNextCall(ROR3_sa20);
assertEquals(ROR3(0x0000FFFF, 20), ROR3_sa20(0x0000FFFF));
// ROR3_sa40
assertEquals(ROR3(0x0000FFFF, 40), ROR3_sa40(0x0000FFFF));
assertEquals(ROR3(0x0000FFFF, 40), ROR3_sa40(0x0000FFFF));
%OptimizeFunctionOnNextCall(ROR3_sa40);
assertEquals(ROR3(0x0000FFFF, 40), ROR3_sa40(0x0000FFFF));
// ROR4_sa20
assertEquals(ROR4(0x0000FFFF, 20), ROR4_sa20(0x0000FFFF));
assertEquals(ROR4(0x0000FFFF, 20), ROR4_sa20(0x0000FFFF));
%OptimizeFunctionOnNextCall(ROR4_sa20);
assertEquals(ROR4(0x0000FFFF, 20), ROR4_sa20(0x0000FFFF));
// ROR4_sa40
assertEquals(ROR4(0xFFFFFFFF, 40), ROR4_sa40(0xFFFFFFFF));
assertEquals(ROR4(0xFFFFFFFF, 40), ROR4_sa40(0xFFFFFFFF));
%OptimizeFunctionOnNextCall(ROR4_sa40);
assertEquals(ROR4(0xFFFFFFFF, 40), ROR4_sa40(0xFFFFFFFF));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment