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

Reply via email to