https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115857
--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- unsigned hammWeight(unsigned char a) { a = ((a & 0xAA) >> 1) + (a & 0x55); a = ((a & 0xCC) >> 2) + (a & 0x33); a = ((a & 0xF0) >> 4) + (a & 0x0F); return a; } Could be optimized to just POPCOUNT(a) if you have popcountqi2 optab. Maybe even just popcount((unsigned int)a) if you have a popcountsi2 optab. And then could optimize: popcount(a&0xff) + popcount((a>>8)&0xff) into popcount (a&0xffff) etc.