> the types_match (type, @4) looks redundant. Yeah, make sense.
15 | <bb 2> [local count: 1073741824]: 16 | _1 = (long unsigned int) a_4(D); 17 | _2 = (long unsigned int) b_5(D); 18 | x_6 = _1 * _2; 19 | _7 = MIN_EXPR <x_6, 4294967295>; 20 | _3 = (uint32_t) _7; 21 | return _3; Initially I would like to make sure the convert of line 20 is to the same type of op_1 and op_2, but in fact types_match (type, @0, @1) ensure this already. Same for the previous pattern, and I will send v2 if no surprise from test. Pan -----Original Message----- From: Richard Biener <richard.guent...@gmail.com> Sent: Monday, July 28, 2025 9:41 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 v1 1/2] Match: Introduce mul based pattern for unsigned SAT_MUL On Sat, Jul 26, 2025 at 3:13 PM <pan2...@intel.com> wrote: > > From: Pan Li <pan2...@intel.com> > > Like widen_mul based pattern, we would like introduce the mul based > pattern as well. The pattern is quite simple compares to the > widen_mul, thus add new instead of the for loop in match.pd. > > gcc/ChangeLog: > > * match.pd: Add mul based unsigned SAT_MUL. > > Signed-off-by: Pan Li <pan2...@intel.com> > --- > gcc/match.pd | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/gcc/match.pd b/gcc/match.pd > index 4903552c82a..f8d74fd52ad 100644 > --- a/gcc/match.pd > +++ b/gcc/match.pd > @@ -3611,6 +3611,18 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) > bool widen_mult_p = cvt5_prec == cvt6_prec && widen_prec == cvt6_prec > * 2; > } > (if (widen_prec > prec && c2_is_max_p && widen_mult_p))))) > + (match (unsigned_integer_sat_mul @0 @1) > + (convert@4 (min (mult:c@3 (convert @0) (convert @1)) INTEGER_CST@2)) > + (if (types_match (type, @0, @1) && types_match (type, @4)) the types_match (type, @4) looks redundant. Do you want to restrict this outer conversion to a sign-conversion? In that case use (nop_convert ...) > + (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); > + } > + (if (widen_prec > prec && c2_is_max_p))))) > ) > > /* The boundary condition for case 10: IMM = 1: > -- > 2.43.0 >