https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126466
Bug ID: 126466
Summary: [17 Regression] popcount recognition doesn't validate
one of the masks
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: ktkachov at gcc dot gnu.org
Target Milestone: ---
const unsigned m1 = 0x55555555UL;
const unsigned m2 = 0x33333333UL;
const unsigned m3 = 0x0F0F0F0FUL;
const unsigned m4 = 0x0000FFFFUL;
__attribute__((noipa)) unsigned
popc (unsigned x)
{
x = x - ((x >> 1) & m1);
x = x - 3 * ((x >> 2) & m2);
x = (x + (x >> 4)) & m3;
x = x + (x >> 8);
x = x + (x >> 16);
return x & m4;
}
int
main (void)
{
/* The low half holds a population count of 13, the high half one of 9. */
if (popc (0x12345678u) != 0x090du)
__builtin_abort ();
return 0;
}
aborts at -O2, passes with GCC 16