On Mon, Jul 20, 2026 at 06:26:21AM -0400, Kael Andrew Franco 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)))
> + (if (neeq == NE_EXPR)
> + (convert @0)
> + (eq @0 @2)))))
The formatting looks wrong.
1) I believe the indentation in match.pd is 1 space rather than 2.
2) more importantly, the last if should have both (convert @0)
and (eq @0 @2) at the same indentation level, otherwise it confuses
the reader that the else case isn't handled there at all.
Jakub