https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94787
Bug ID: 94787
Summary: Failure to detect single bit popcount pattern
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: gabravier at gmail dot com
Target Milestone: ---
bool f(unsigned v)
{
return v && !(v & (v - 1));
}
Depending on the supported architecture, we may want to optimize this to
`__builtin_popcount(v) == 1;` (when a fast hardware instruction is available).
For example, on x86, this should make programs faster when `popcnt` is
available. LLVM already does this.
Comparison with x86 `-mpopcnt` here : https://godbolt.org/z/M6f28d