https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108938
--- Comment #5 from Hongtao.liu <crazylht at gmail dot com> ---
(In reply to Jakub Jelinek from comment #4)
> And perhaps next to rotate it could try some left or right (logical) shift
> too.
Yes, we have bit mask in bswap detection, left or right (logical) shift can be
reprensented as special bit mask + rotate.
I'm cooking a patch, for shift cases, it looks like gimple doesn't simplify bit
mask + rotate to shift. .i.e.
unsigned
foo (unsigned int a)
{
unsigned int b = a & 0x00FFFFFF;
unsigned int c = ((b & 0x000000FF) << 8
| (b & 0x0000FF00) << 8
| (b & 0x00FF0000) << 8
| (b & 0xFF000000) >> 24);
return c;
}
gcc generates
foo:
mov eax, edi
and eax, 16777215
rol eax, 8
ret
But it can be optimized as below
foo: # @foo
mov eax, edi
shl eax, 8
ret