On 1/13/2026 10:39 AM, Andrew Pinski wrote:
This is a small reassociation for `a*bool & b` into `(a & b) * bool` checking if
`a & b` simplifies. Since it could be the case `b` is `~a` or `a` or something
else that might simplify when anding with `a`.

Note this fixes a regression for aarch64 where the cost of a multiply vs `&-` 
changed
in GCC 14 and can no longer optimize some cases at the RTL level.

Bootstrapped and tested on x86_64-linux-gnu.

        PR tree-optimization/119402
gcc/ChangeLog:

        * match.pd (`(a*zero_one_valued_p) & b`): New pattern.

gcc/testsuite/ChangeLog:

        * gcc.dg/tree-ssa/bitops-14.c: New test.
        * gcc.dg/tree-ssa/bitops-15.c: New test.
Last I looked we didn't have scalar support for a & ~b as a named pattern,  but it seems like that's another good reason (at some point) to trying and bring the logical terms together in general since multiple ISAs have a full complement (pun intended) of logical-with-complement style operations.

And more generally, there are guidelines (from an ancient HP paper) on reassociation and this would seem to generally fit.  An AND operation would largely be similar to PLUS and would have a different priority than MULT.  So when you rewrite in the way you're doing you'll generally tend to improve CSE, LICM and IVopts.  It's been eons since I studied that work, so don't ask for more details :-)

Anyway, OK for the trunk.  Thanks.

jeff


Reply via email to