On 12/10/25 8:11 AM, Kishan Parmar wrote:
Hello,

The expression (A ^ B) & C ^ B is the canonical GIMPLE form because it
optimizes for instruction count on generic targets. However, for
targets that support ANDN (like PowerPC andc), the equivalent
(A & C) | (B & ~C) form is preferable because it reduces register
dependency chain.

Currently, GCC generates the XOR form which creates a serial chain with
two dependencies:
        xor 4,3,4
        and 4,4,5
        xor 3,4,3

With this patch, using IFN_BIT_ANDN, we generate the IOR form. This
allows the two bitwise operations to execute independently, reducing
the path to a single dependency for the final instruction:
        andc 3,3,5
        and 2,4,5
        or 3,2,3

This patch fixes PR90323 and PR122431. Tested on powerpc64le-linux-gnu
with no regressions.

Thanks,
Kishan

2025-12-10  Kishan Parmar  <[email protected]>

gcc/ChangeLog:
        PR tree-optimization/122431 target/90323
        * config/rs6000/rs6000.md (andn<mode>3): New define_expand andn for
        scalar types.
        * match.pd: Add late simplification to convert to (A & C) | (B & ~C)
        form if target support ANDN optab.
FWIW, this ought to help RISC-V as well once we fix the port to use the proper name.

Once Andrew is happy, this is OK.

jeff


Reply via email to