]> git.ipfire.org Git - thirdparty/gcc.git/commit
Optimize x ? bswap(x) : 0 in tree-ssa-phiopt
authorRoger Sayle <roger@nextmovesoftware.com>
Mon, 2 Aug 2021 12:27:53 +0000 (13:27 +0100)
committerRoger Sayle <roger@nextmovesoftware.com>
Mon, 2 Aug 2021 12:30:38 +0000 (13:30 +0100)
commitf9fcf754825a1e01033336f84c18690aaa971a6f
tree6bd92cdbb1929c2e76186091c7aaada8ff503754
parent6f0c43e97825ee54e3779afbedcd0def12443001
Optimize x ? bswap(x) : 0 in tree-ssa-phiopt

Many thanks again to Jakub Jelinek for a speedy fix for PR 101642.
Interestingly, that test case "bswap16(x) ? : x" also reveals a
missed optimization opportunity.  The resulting "x ? bswap(x) : 0"
can be further simplified to just bswap(x).

Conveniently, tree-ssa-phiopt.c already recognizes/optimizes the
related "x ? popcount(x) : 0", so this patch simply makes that
transformation make general, additionally handling bswap, parity,
ffs and clrsb.  All of the required infrastructure is already
present thanks to Jakub previously adding support for clz/ctz.
To reflect this generalization, the name of the function is changed
from cond_removal_in_popcount_clz_ctz_pattern to the hopefully
equally descriptive cond_removal_in_builtin_zero_pattern.

2021-08-02  Roger Sayle  <roger@nextmovesoftware.com>

gcc/ChangeLog
* tree-ssa-phiopt.c (cond_removal_in_builtin_zero_pattern):
Renamed from cond_removal_in_popcount_clz_ctz_pattern.
Add support for BSWAP, FFS, PARITY and CLRSB builtins.
(tree_ssa_phiop_worker): Update call to function above.

gcc/testsuite/ChangeLog
* gcc.dg/tree-ssa/phi-opt-25.c: New test case.
gcc/testsuite/gcc.dg/tree-ssa/phi-opt-25.c [new file with mode: 0644]
gcc/tree-ssa-phiopt.c