https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109038
Bug ID: 109038
Summary: Miss optimization to simplify bit_and + rotate to
shift
Product: gcc
Version: 13.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: crazylht at gmail dot com
Target Milestone: ---
Target: x86_64-*-* i?86-*-*
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