middle-end: also optimized `popcount(a) <= 1` [PR90693]
This expands on optimizing `popcount(a) == 1` to also handle
`popcount(a) <= 1`. `<= 1` can be expanded as `(a & -a) == 0`
like what is done for `== 1` if we know that a was nonzero.
We have to do the optimization in 2 places due to if we have
an optab entry for popcount or not.
Built and tested for aarch64-linux-gnu.
PR middle-end/90693
gcc/ChangeLog:
* internal-fn.cc (expand_POPCOUNT): Handle the second argument
being `-1` for `<= 1`.
* tree-ssa-math-opts.cc (match_single_bit_test): Handle LE/GT
cases.
(math_opts_dom_walker::after_dom_children): Call match_single_bit_test
for LE_EXPR/GT_EXPR also.
gcc/testsuite/ChangeLog:
* gcc.target/aarch64/popcnt-le-1.c: New test.
* gcc.target/aarch64/popcnt-le-2.c: New test.
* gcc.target/aarch64/popcnt-le-3.c: New test.
Signed-off-by:
Andrew Pinski <quic_apinski@quicinc.com>
Showing
- gcc/internal-fn.cc 19 additions, 1 deletiongcc/internal-fn.cc
- gcc/testsuite/gcc.target/aarch64/popcnt-le-1.c 29 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/popcnt-le-1.c
- gcc/testsuite/gcc.target/aarch64/popcnt-le-2.c 31 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/popcnt-le-2.c
- gcc/testsuite/gcc.target/aarch64/popcnt-le-3.c 31 additions, 0 deletionsgcc/testsuite/gcc.target/aarch64/popcnt-le-3.c
- gcc/tree-ssa-math-opts.cc 19 additions, 6 deletionsgcc/tree-ssa-math-opts.cc
Loading
Please register or sign in to comment