On Fri, Sep 25, 2026 at 6:11 AM Richard Biener <[email protected]> wrote:
>
> The following complements the existing (xor (and A B) B) to (and (not A) B)
> transform.  I've seen this candidate when analyzing PR127606.
>
> Bootstrapped and tested on x86_64-unknown-linux-gnu.
>
> OK?

I think this makes sense since nand (bic on aarch64/arm) is a very
common instruction.
Also we have done this on the gimple/generic level for a long time.
The match pattern was done in r6-1883-g5b00d9211625c1 but we have done
in fold-const since r0-69890-g9d24eb542cfde8 (I didn't even realize it
was my change until I looked it up).

So yes this is ok.

I suspect we have many patterns that were added to fold-const (and
match) that never made it to simplify-rtx.cc but that is for another
day.

Thanks,
Andrea


>
> Thanks,
> Richard.
>
>         * simplify-rtx.cc (simplify_context::simplify_binary_operation_1):
>         Also simplify (xor (ior A B) B) to (and (not B) A).
> ---
>  gcc/simplify-rtx.cc | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
>
> diff --git a/gcc/simplify-rtx.cc b/gcc/simplify-rtx.cc
> index 38c8abfe3e7..e74f241c7cd 100644
> --- a/gcc/simplify-rtx.cc
> +++ b/gcc/simplify-rtx.cc
> @@ -4119,6 +4119,22 @@ simplify_context::simplify_binary_operation_1 
> (rtx_code code,
>                                                         XEXP (op0, 1), mode),
>                                     op1);
>
> +      /* Similarly, convert (xor (ior A B) B) to (and (not B) A).  */
> +      else if (GET_CODE (op0) == IOR
> +              && rtx_equal_p (XEXP (op0, 1), op1)
> +              && ! side_effects_p (op1))
> +       return simplify_gen_binary (AND, mode,
> +                                   simplify_gen_unary (NOT, mode,
> +                                                       op1, mode),
> +                                   XEXP (op0, 0));
> +      else if (GET_CODE (op0) == IOR
> +              && rtx_equal_p (XEXP (op0, 0), op1)
> +              && ! side_effects_p (op1))
> +       return simplify_gen_binary (AND, mode,
> +                                   simplify_gen_unary (NOT, mode,
> +                                                       op1, mode),
> +                                   XEXP (op0, 1));
> +
>        /* Given (xor (ior (xor A B) C) D), where B, C and D are
>          constants, simplify to (xor (ior A C) (B&~C)^D), canceling
>          out bits inverted twice and not set by C.  Similarly, given
> --
> 2.51.0

Reply via email to