[Bug tree-optimization/126808] New: Let popcount (X & -X) look through a widening conversion

"ktkachov at gcc dot gnu.org via Gcc-bugs" <[email protected]>
Newsgroups gmane.comp.gcc.bugs
Message-ID <[email protected]/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126808

            Bug ID: 126808
           Summary: Let popcount (X & -X) look through a  widening
                    conversion
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ktkachov at gcc dot gnu.org
  Target Milestone: ---

typedef unsigned _BitInt(37) u37;
  int f (u37 x) { return __builtin_popcountg (x & -x); }

For aarch64 GCC -O2 generates:
f:
        and     x1, x0, 137438953471
        neg     x0, x1
        and     x0, x0, x1
        fmov    d31, x0
        cnt     v31.8b, v31.8b
        addv    b31, v31.8b
        fmov    w0, s31
        ret

Clang can do:
f:
        tst     x0, #0x1fffffffff
        cset    w0, ne
        ret
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.