https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90693
--- Comment #2 from Wilco <wilco at gcc dot gnu.org> --- (In reply to Dávid Bolvanský from comment #1) > >> __builtin_popcount (x) == 1 into x == (x & -x) > > > This will not work for x = 0. > > Should work: > x && x == (x & -x) > x && (x & x-1) == 0 Good point, though that's not needed for (x & (x-1)) != 0 given you can only have 2 or more bits set if x was non-zero to start with. It's worth finding a branchless sequence, otherwise it may not be faster. Maybe (x << clz (x)) == INT_MIN or (x-1) <u (x & -x) work better.