[Bug tree-optimization/102486] __builtin_popcount(y&-y) is not optimized to y!=0
daniel.barboza at oss dot qualcomm.com
gcc-bugzilla@gcc.gnu.org
Mon Jan 5 21:49:15 GMT 2026
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102486
--- Comment #6 from Daniel Henrique Barboza <daniel.barboza at oss dot qualcomm.com> ---
I just made tests with what Andrew suggested in the thread mentioned above,
i.e:
popcount (y & -y) -> (conversion_type)y != 0
And I did with Roger's suggestion as well, removing the TYPE_UNSIGNED
constraint:
popcount (y & -y) -> (conversion_type)-y != 0
They're both equal as far as 'optimized' output goes and in a native x86
bootstrap test they both look the same (no regressions).
I think Roger made good points w.r.t keeping any potential traps/UBs by doing
the comparison with "-y", delegating to other match.pd rules whether "-y != 0"
can become "y != 0". I'll go with his idea for the next version. And this time
I believe a more detailed commit msg is in order to explain why we're rocking a
comparison with "-y".
More information about the Gcc-bugs
mailing list