https://gcc.gnu.org/g:58c8c3e3bd04e59fc2de82708c5e12e7b5db4f43

commit r17-2574-g58c8c3e3bd04e59fc2de82708c5e12e7b5db4f43
Author: Kael Andrew Alonzo Franco <[email protected]>
Date:   Mon Jul 20 16:36:19 2026 -0400

    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]>

Diff:
---
 gcc/match.pd | 27 ++++++++++-----------------
 1 file changed, 10 insertions(+), 17 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index cfb43202e762..017b1362b7e4 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -2680,25 +2680,18 @@ 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_uhwi_p (@1)
+         && tree_to_uhwi (@1) < TYPE_PRECISION (TREE_TYPE (@0)))
+      (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).

Reply via email to