Thanks Richard, will commit the series if no comments for the second test only patch in next 24 hours.
Pan -----Original Message----- From: Richard Biener <richard.guent...@gmail.com> Sent: Tuesday, August 19, 2025 2:56 PM To: Li, Pan2 <pan2...@intel.com> Cc: gcc-patches@gcc.gnu.org; juzhe.zh...@rivai.ai; kito.ch...@gmail.com; jeffreya...@gmail.com; rdapp....@gmail.com; Chen, Ken <ken.c...@intel.com>; Liu, Hongtao <hongtao....@intel.com> Subject: Re: [PATCH v2 1/2] Match: Add form 3 for unsigned SAT_MUL On Thu, Aug 14, 2025 at 12:08 AM <pan2...@intel.com> wrote: > > From: Pan Li <pan2...@intel.com> > > This patch would like to try to match the the unsigned > SAT_MUL form 3, aka below: > > #define DEF_SAT_U_MUL_FMT_3(NT, WT) \ > NT __attribute__((noinline)) \ > sat_u_mul_##NT##_from_##WT##_fmt_3 (NT a, NT b) \ > { \ > WT x = (WT)a * (WT)b; \ > if ((x >> sizeof(a) * 8) == 0) \ > return (NT)x; \ > else \ > return (NT)-1; \ > } > > While WT is T is uint16_t, uint32_t, uint64_t and uint128_t, > and NT is is uint8_t, uint16_t, uint32_t and uint64_t. OK. Thanks, Richard. > gcc/ChangeLog: > > * match.pd: Add form 3 for unsigned SAT_MUL. > > Signed-off-by: Pan Li <pan2...@intel.com> > --- > gcc/match.pd | 27 ++++++++++++++++++++++++++- > 1 file changed, 26 insertions(+), 1 deletion(-) > > diff --git a/gcc/match.pd b/gcc/match.pd > index 66e8a787449..b1d7a3a1b73 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -3629,12 +3629,37 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > if (__builtin_mul_overflow (X, Y, &result)) > return -1; > else > - return -(T)overflow_p | result; > + return result; > } > while T can be uint8_t, uint16_t, uint32_t and uint64_t. */ > (cond^ (ne (imagpart (IFN_MUL_OVERFLOW:c@2 @0 @1)) integer_zerop) > integer_minus_onep (realpart @2)) > (if (types_match (type, @0, @1)))) > + (match (unsigned_integer_sat_mul @0 @1) > + /* SAT_U_MUL (X, Y) = { > + WT x = (WT)a * (WT)b; > + if ((x >> sizeof(a) * 8) == 0) > + return (T)x; > + else > + return (T)-1; > + } > + while WT is uint128_t, T is uint8_t, uint16_t, uint32_t or uint64_t. > */ > + (convert (cond^ (eq (rshift (mult:c@3 (convert @0) (convert @1)) > + INTEGER_CST@2) > + integer_zerop) > + @3 INTEGER_CST@4)) > + (if (types_match (type, @0, @1)) > + (with > + { > + unsigned prec = TYPE_PRECISION (type); > + unsigned widen_prec = TYPE_PRECISION (TREE_TYPE (@3)); > + wide_int c4 = wi::to_wide (@4); > + wide_int max = wi::mask (prec, false, widen_prec); > + bool c4_is_max_p = wi::eq_p (c4, max); > + unsigned c2 = tree_to_uhwi (@2); > + bool c2_is_type_precision_p = c2 == prec; > + } > + (if (widen_prec > prec && c2_is_type_precision_p && c4_is_max_p))))) > ) > > /* The boundary condition for case 10: IMM = 1: > -- > 2.43.0 >