diff options
author | Roger Sayle <roger@nextmovesoftware.com> | 2021-07-08 11:46:14 +0100 |
---|---|---|
committer | Roger Sayle <roger@nextmovesoftware.com> | 2021-07-08 11:47:55 +0100 |
commit | 4c619132b3f14dc5e672a7f2f0e09cb784193559 (patch) | |
tree | 63d472f471b0c12d4140ad40b0fc3f53630ae5ec /gcc/ada/debug.adb | |
parent | 663a014e77709bfbd4145c605b178169eaf334fc (diff) | |
download | gcc-4c619132b3f14dc5e672a7f2f0e09cb784193559.zip gcc-4c619132b3f14dc5e672a7f2f0e09cb784193559.tar.gz gcc-4c619132b3f14dc5e672a7f2f0e09cb784193559.tar.bz2 |
PR tree-optimization/40210: Fold (bswap(X)>>C1)&C2 to (X>>C3)&C2 in match.pd
All of the optimizations/transformations mentioned in bugzilla for
PR tree-optimization/40210 are already implemented in mainline GCC,
with one exception. In comment #5, there's a suggestion that
(bswap64(x)>>56)&0xff can be implemented without the bswap as
(unsigned char)x, or equivalently x&0xff.
This patch implements the above optimization, and closely related
variants. For any single bit, (bswap(X)>>C1)&1 can be simplified
to (X>>C2)&1, where bit position C2 is the appropriate permutation
of C1. Similarly, the bswap can eliminated if the desired set of
bits all lie within the same byte, hence (bswap(x)>>8)&255 can
always be optimized, as can (bswap(x)>>8)&123.
Previously,
int foo(long long x) {
return (__builtin_bswap64(x) >> 56) & 0xff;
}
compiled with -O2 to
foo: movq %rdi, %rax
bswap %rax
shrq $56, %rax
ret
with this patch, it now compiles to
foo: movzbl %dil, %eax
ret
2021-07-08 Roger Sayle <roger@nextmovesoftware.com>
Richard Biener <rguenther@suse.de>
gcc/ChangeLog
PR tree-optimization/40210
* match.pd (bswap optimizations): Simplify (bswap(x)>>C1)&C2 as
(x>>C3)&C2 when possible. Simplify bswap(x)>>C1 as ((T)x)>>C2
when possible. Simplify bswap(x)&C1 as (x>>C2)&C1 when 0<=C1<=255.
gcc/testsuite/ChangeLog
PR tree-optimization/40210
* gcc.dg/builtin-bswap-13.c: New test.
* gcc.dg/builtin-bswap-14.c: New test.
Diffstat (limited to 'gcc/ada/debug.adb')
0 files changed, 0 insertions, 0 deletions