On Mon, Jul 20, 2026 at 3:27 AM Kael Andrew Franco
<[email protected]> wrote:
>
> From bc21c0d454e944e2e9be3a464adb8f3219ed0257 Mon Sep 17 00:00:00 2001
> From: Kael Andrew Alonzo Franco <[email protected]>
> Date: Sun, 19 Jul 2026 18:47:54 -0400
> Subject: [PATCH] match: Combine two patterns into for neeq (ne eq) and fix 
> typo. [PR64992]
>
> This simplify r13-2048 and fix typo on C being zero_one_valued_p to
> X being zero_one_valued_p.
>
> Bootstrapped and regtested on x86_64-pc-linux-gnu.
>
> PR tree-optimization/64992
>
> gcc/ChangeLog:
>
> * match.pd: Combine two patterns into for neeq (ne eq) and fix typo.
>
> Signed-off-by: Kael Andrew Franco <[email protected]>
> ---
>  gcc/match.pd | 28 +++++++++++-----------------
>  1 file changed, 11 insertions(+), 17 deletions(-)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index b3738fdde1d..8b156212c1c 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -2680,25 +2680,19 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>        && (TYPE_UNSIGNED (type) || TYPE_PRECISION (type) > 1))
>    (mult (convert @1) (convert @2))))
>
> -/* (X << C) != 0 can be simplified to X, when C is zero_one_valued_p.
> +/* (X << C) != 0 can be simplified to X, when X is zero_one_valued_p.
> +   (X << C) == 0 can be simplified to X == 0, when X is zero_one_valued_p.
>     Check that the shift is well-defined (C is less than TYPE_PRECISION)
>     as some targets (such as x86's SSE) may return zero for larger C.  */
> -(simplify
> -  (ne (lshift zero_one_valued_p@0 INTEGER_CST@1) integer_zerop@2)
> -  (if (tree_fits_shwi_p (@1)
> -       && tree_to_shwi (@1) > 0
> -       && tree_to_shwi (@1) < TYPE_PRECISION (TREE_TYPE (@0)))
> -    (convert @0)))
> -
> -/* (X << C) == 0 can be simplified to X == 0, when C is zero_one_valued_p.
> -   Check that the shift is well-defined (C is less than TYPE_PRECISION)
> -   as some targets (such as x86's SSE) may return zero for larger C.  */
> -(simplify
> -  (eq (lshift zero_one_valued_p@0 INTEGER_CST@1) integer_zerop@2)
> -  (if (tree_fits_shwi_p (@1)
> -       && tree_to_shwi (@1) > 0
> -       && tree_to_shwi (@1) < TYPE_PRECISION (TREE_TYPE (@0)))
> -    (eq @0 @2)))
> +(for neeq (ne eq)
> +  (simplify
> +    (neeq (lshift zero_one_valued_p@0 INTEGER_CST@1) integer_zerop@2)
> +    (if (tree_fits_shwi_p (@1)
> +         && tree_to_shwi (@1) > 0
> +         && tree_to_shwi (@1) < TYPE_PRECISION (TREE_TYPE (@0)))

This could be simplified into:
tree_fits_uhwi_p (@1)
&& tree_to_uhwi (@1) < TYPE_PRECISION (TREE_TYPE (@0))

But otherwise ok.

> +      (if (neeq == NE_EXPR)
> +        (convert @0)
> +          (eq @0 @2)))))
>
>  /* PR110010: (A >> C) != (B >> C) -> (A ^ B) >= (1 << C)
>     and likewise (A >> C) == (B >> C) -> (A ^ B) < (1 << C).
> --
> 2.55.0
>
>

Reply via email to