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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <sa...@gcc.gnu.org>:

https://gcc.gnu.org/g:2738955004256c2e9753364d78a7be340323b74b

commit r14-1171-g2738955004256c2e9753364d78a7be340323b74b
Author: Roger Sayle <ro...@nextmovesoftware.com>
Date:   Wed May 24 17:32:20 2023 +0100

    PR middle-end/109840: Preserve popcount/parity type in match.pd.

    PR middle-end/109840 is a regression introduced by my recent patch to
    fold popcount(bswap(x)) as popcount(x).  When the bswap and the popcount
    have the same precision, everything works fine, but this optimization also
    allowed a zero-extension between the two.  The oversight is that we need
    to be strict with type conversions, both to avoid accidentally changing
    the argument type to popcount, and also to reflect the effects of
    argument/return-value promotion in the call to bswap, so this zero
extension
    needs to be preserved/explicit in the optimized form.

    Interestingly, match.pd should (in theory) be able to narrow calls to
    popcount and parity, removing a zero-extension from its argument, but
    that is an independent optimization, that needs to check IFN_ support.
    Many thanks to Andrew Pinski for his help/fixes with these transformations.

    2023-05-24  Roger Sayle  <ro...@nextmovesoftware.com>

    gcc/ChangeLog
            PR middle-end/109840
            * match.pd <popcount optimizations>: Preserve zero-extension when
            optimizing popcount((T)bswap(x)) and popcount((T)rotate(x,y)) as
            popcount((T)x), so the popcount's argument keeps the same type.
            <parity optimizations>:  Likewise preserve extensions when
            simplifying parity((T)bswap(x)) and parity((T)rotate(x,y)) as
            parity((T)x), so that the parity's argument type is the same.

    gcc/testsuite/ChangeLog
            PR middle-end/109840
            * gcc.dg/fold-parity-8.c: New test.
            * gcc.dg/fold-popcount-11.c: Likewise.

Reply via email to