On 1/6/2026 5:21 PM, Andrew Pinski wrote:
On Mon, Jan 5, 2026 at 2:23 PM Daniel Barboza
<[email protected]> wrote:
The initial idea of this optimization was to reduce it to "X != 0",
checking for either X being an unsigned or a truncating conversion.
Then we discussed reducing it to "(X & -X) != 0" instead. This form
would avoid the potential trapping problems (like -ftrapv) that might
happen in case X is not an unsigned type.

Then, as suggested by Roger Sayle in bugzilla, we could reduce to just
"-X != 0". Keeping the negated value in the pattern preserves any trapping
or UBs to be handled by other match.pd patterns that are more able to do
the conversion to "X != 0" when applicable. This would also spare us from
a TYPE_UNSIGNED check.

         PR 102486
PR tree-optimization/102486
gcc/ChangeLog:

          * match.pd (`popcount (X & -X) -> -X != 0`): New pattern.

gcc/testsuite/ChangeLog:

         * gcc.dg/tree-ssa/pr102486.c: New test.
Ok. When I get some time I will push this change.
I pushed it after also fixing some spaces->tabs issues in the ChangeLog.

jeff

Reply via email to