https://gcc.gnu.org/g:6e37a5ac736f4ee2ebed9f20187c43d172d1e7cb

commit r16-4230-g6e37a5ac736f4ee2ebed9f20187c43d172d1e7cb
Author: Pan Li <[email protected]>
Date:   Thu Sep 25 12:59:07 2025 +0800

    Match: Refactor unsigned SAT_MUL form 1 mul and widen-mul by for [NFC]
    
    Inspired by the previous patch, the form 1 of unsigned SAT_MUL
    can be mul or widen-mul based.  So we can leverage the keyword
    for to group it, and avoid the pattern duplication.
    
    The below test suites are passed for this patch:
    1. The rv64gcv fully regression tests.
    2. The x86 bootstrap tests.
    3. The x86 fully regression tests.
    
    gcc/ChangeLog:
    
            * match.pd: Refactor the form 1 of SAT_MUL by keyword for.
    
    Signed-off-by: Pan Li <[email protected]>

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

diff --git a/gcc/match.pd b/gcc/match.pd
index 6f896aa7961c..60bdd3338c20 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3620,6 +3620,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 
 /* Saturation mult for unsigned integer.  */
 (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type))
+ (for mult_op (mult widen_mult)
   (match (unsigned_integer_sat_mul @0 @1)
    /* SAT_U_MUL (X, Y) = {
        WT x = (WT)a * (WT)b;
@@ -3630,9 +3631,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
          return (T)x;
       }
       while WT is uint128_t, T is uint8_t, uint16_t, uint32_t or uint64_t.  */
-   (convert (min (widen_mult:c@3 (convert@4 @0)
-                                (convert@5 @1))
-                  INTEGER_CST@2))
+   (convert (min (mult_op:c@3 (convert@4 @0) (convert@5 @1)) INTEGER_CST@2))
    (if (types_match (type, @0, @1))
     (with
      {
@@ -3640,24 +3639,16 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
       unsigned widen_prec = TYPE_PRECISION (TREE_TYPE (@3));
       unsigned cvt4_prec = TYPE_PRECISION (TREE_TYPE (@4));
       unsigned cvt5_prec = TYPE_PRECISION (TREE_TYPE (@5));
-      wide_int c2 = wi::to_wide (@2);
-      wide_int max = wi::mask (prec, false, widen_prec);
-      bool c2_is_max_p = wi::eq_p (c2, max);
-      bool widen_mult_p = cvt4_prec == cvt5_prec && widen_prec == cvt5_prec * 
2;
-     }
-     (if (widen_prec > prec && c2_is_max_p && widen_mult_p)))))
-  (match (unsigned_integer_sat_mul @0 @1)
-   (convert (min (mult:c@3 (convert @0) (convert @1)) INTEGER_CST@2))
-   (if (types_match (type, @0, @1))
-    (with
-     {
-      unsigned prec = TYPE_PRECISION (type);
-      unsigned widen_prec = TYPE_PRECISION (TREE_TYPE (@3));
-      wide_int c2 = wi::to_wide (@2);
+
       wide_int max = wi::mask (prec, false, widen_prec);
-      bool c2_is_max_p = wi::eq_p (c2, max);
+      bool c2_is_max_p = wi::eq_p (wi::to_wide (@2), max);
+
+      bool widen_mult_p = mult_op == WIDEN_MULT_EXPR && cvt4_prec == cvt5_prec
+       && widen_prec == cvt5_prec * 2 && widen_prec > prec;
+      bool mult_p = mult_op == MULT_EXPR && cvt4_prec == cvt5_prec
+       && cvt4_prec == widen_prec && widen_prec > prec;
      }
-     (if (widen_prec > prec && c2_is_max_p)))))
+     (if (c2_is_max_p && (widen_mult_p || mult_p)))))))
   (match (unsigned_integer_sat_mul @0 @1)
    /* SAT_U_MUL (X, Y) = {
        T result;

Reply via email to