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

--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jeff Law <[email protected]>:

https://gcc.gnu.org/g:aae842ede5d7b575bbdc86ac309b1adcb28fca0e

commit r17-6631-gaae842ede5d7b575bbdc86ac309b1adcb28fca0e
Author: Jeff Law <[email protected]>
Date:   Tue Nov 24 07:03:39 2026 -0700

    [PR rtl/optimization/128767] Simplify (and (xor ...)) sequence to (and (not
...)) form when possible

    This is one piece of the pr128767 puzzle.

    The core issue (as outlined in the PR) is RISC-V has a minimalist set of
scc
    insns, often forcing the port to invert the result of one form via seq/xor
#1
    to derive another.

    Naturally this is an RTL issue since the code looks peachy in gimple.

    In this case we have  (and (xor A 1) B) where we know that B is a 0/1
value.
    That means we don't really care about anything other than the least
significant
    bit of A and we're just inverting the lowest bit.  We can safely use andn
which
    allows us to squash out the seq/xor inversion step.

    So we recognize in simplify-rtx and generate the andn form.  If the target
    doesn't match that, then obviously combine will give up and we're no worse
than
    we were before.

    This saves about 160 million instructions in x264; it's general enough that
I
    could easily see it firing outside those aliasing check paths, so I won't
claim
    it's all improvements in the aliasing testing code.

    The one adjusted test for aarch64 just swaps the order of instructions.

    Bootstrapped and regression tested on x86_64 and aarch64.  Regression
tested on
    the cross targets as well.  The larger kit has been bootstrapped and
regression
    tested on the K1, K3 and C920 platforms as well.

    Pushing to the trunk.

            PR rtl-optimization/128767
    gcc
            * simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
            Simplify (and (xor A 1) B) to (and not (A) B) when B is a 0/1
value.

    gcc/testsuite

            * gcc.target/riscv/zbb-andn-xor1-1.c: New test.
            * gcc.target/riscv/zbb-andn-xor1-2.c: New test.
            * gcc.target/riscv/zbb-andn-xor1-3.c: New test.
            * gcc.target/riscv/zbb-andn-xor1-4.c: New test.
            * gcc.target/aarch64/bic-1.c: Adjust expected output.

Reply via email to