https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102486

Roger Sayle <roger at nextmovesoftware dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |roger at nextmovesoftware dot 
com
   Last reconfirmed|                            |2026-01-05
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #5 from Roger Sayle <roger at nextmovesoftware dot com> ---
To follow-up on Andrew's comment in
https://gcc.gnu.org/pipermail/gcc-patches/2026-January/704782.html
popcount(y&-y) != 0 shouldn't be optimized to y != 0 when y can overflow or
trap, such as with -ftrapv.  In the original example, the type is unsigned so
the transformation is valid.  My suggestion is that __popcount(y&-y) eq/ne 0
should be (initially) transformed to -y eq/ne 0, which preserves any
trapping/undefined behaviour, and then rely on match.pd to later simplify -y
eq/ne 0 into y eq/ne 0 when it's safe to do so.  This can then remove the
TYPE_UNSIGNED constraint.

I hope this helps.  Cool optimization.

Reply via email to