On 11/17/23 07:01, Jakub Jelinek wrote:
Hi!

Per the earlier discussions on this PR, the following patch folds
popcount (x) == 1 (and != 1) into (x ^ (x - 1)) > x - 1 (or <=)
if the corresponding popcount optab isn't implemented (I think any
double-word popcount or call will be necessarily slower than the
above cheap 3 op check and even for -Os larger or same size).

I've noticed e.g. C++ aligned new starts with std::has_single_bit
which does popcount (x) == 1.

As a follow-up, I'm considering changing in this routine the popcount
call to IFN_POPCOUNT with 2 arguments and during expansion test costs.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2023-11-17  Jakub Jelinek  <ja...@redhat.com>

        PR tree-optimization/90693
        * tree-ssa-math-opts.cc (match_single_bit_test): New function.
        (math_opts_dom_walker::after_dom_children): Call it for EQ_EXPR
        and NE_EXPR assignments and GIMPLE_CONDs.

        * gcc.target/i386/pr90693.c: New test.
OK.

Jeff

Reply via email to