http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55177
Bug #: 55177
Summary: Missed optimisation: bswap, mask with constant, bswap
back again.
Classification: Unclassified
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
AssignedTo: [email protected]
ReportedBy: [email protected]
extern int x;
void foo(void)
{
int a = __builtin_bswap32(x);
a &= 0x5a5b5c5d;
x = __builtin_bswap32(a);
}
With GCC 4.7.2 (x86_64 Fedora) this compiles to:
foo:
.LFB0:
.cfi_startproc
movl x(%rip), %eax
bswap %eax
andl $-1515936861, %eax
bswap %eax
movl %eax, x(%rip)
ret
.cfi_endproc
Surely the actual swap should be optimised out, and the 0x5a5b5c5d constant
mask should be swapped instead so we just load, mask with 0x5d5c5b5a and store
without any runtime swapping?
(See also PR42586 which may be related)