https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123332
Bug ID: 123332
Summary: Missing optimization of loop to __builtin_popcount()
Product: gcc
Version: 16.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: antoshkka at gmail dot com
Target Milestone: ---
One of the AI research papers https://arxiv.org/html/2505.11480v2 noted that
the following code:
int f(unsigned long x) {
int res = 0;
while (x > 0) {
res += x & 1;
x >>= 1;
}
return res;
}
can be optimized to `popcnt`, but is not optimized by compilers.
Please, add the missing optimization