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

--- Comment #3 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:50cd76914e6e87d22c3b4d97a7b94c4300b7fa4c

commit r17-6710-g50cd76914e6e87d22c3b4d97a7b94c4300b7fa4c
Author: Jeff Law <[email protected]>
Date:   Wed Nov 25 21:31:40 2026 -0700

    [PR rtl-optimization/128767] Improve RTL sequences for various boolean
logicals

    So yet another LLM discovered issue in x264.

    RISC-V has what I'd call a minimalist set of sCC style instructions and
    requires the compiler to sometimes flip the tense of one sCC to derive
another.
    Naturally those quirks don't show up until after gimple->rtl expansion, so
    something may look good in gimple, but the final code generation looks
poor.

    When we need to invert an scc insn we often use seq (set-equal), but xor
with 1
    also works and it's the latter form we often see in RTL.

    So a problematical sequence might look like this by the time we've
generated
    code.

    slt  t0...
    slt  t1...
    seq  t0, t0
    seq  t1, t1
    or  dest, t0, t1
    beq

    The trick, much like the earlier patch in this space is to realize that
(xor X
    1) is just inversion when only one bit matters.  So we can turn that
sequence
    above using demorgan into:

    slt  t0...
    slt  t1...
    and  dest, t0, t1
    bne

    This saves another 130m dynamic instructions.

    Bootstrapped and regression tested on x86_64 and aarch64 as well as the
usual
    crosses.  An earlier version bootstrapped on my K3, K1 and C920.

    Waiting on Sashiko before pushing.

            PR rtl-optimization/128767
    gcc/
            * simplify-rtx.cc (simplify_context::simpify_binary_operation_1):
            Use demorgan's law to rewrite (ior (xor A 1) (B 1)) into
            (xor (and A B) 1) when A and B are known to be 0/1 values.

    gcc/testsuite/
            * gcc.target/riscv/xor1-demorgan-1.c: New test.
            * gcc.target/riscv/xor1-demorgan-2.c: New test.

Reply via email to