https://gcc.gnu.org/bugzilla/show_bug.cgi?id=126634
Bug ID: 126634
Summary: hwint.h pow2_or_zerop/pow2p_hwi could use popcount_hwi
if supported.
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: middle-end
Assignee: unassigned at gcc dot gnu.org
Reporter: kaelfandrew at gmail dot com
Target Milestone: ---
pow2_or_zerop/pow2p_hwi could be:
```
inline bool
pow2_or_zerop (unsigned HOST_WIDE_INT x)
{
#if GCC_VERSION >= 3004
return popcount_hwi (x) < 2;
#else
return least_bit_hwi (x) == x;
#endif
}
inline bool
pow2p_hwi (unsigned HOST_WIDE_INT x)
{
#if GCC_VERSION >= 3004
return popcount_hwi (x) == 1;
#else
return x && pow2_or_zerop (x);
#endif
}
```
Noticed from LLVM optimizer and tree.cc integer_pow2p.