On Wed, Jun 24, 2026 at 2:41 AM <[email protected]> wrote:
>
> From: Pan Li <[email protected]>
>
> This patch would like to try to match the the unsigned
> SAT_MUL form 14, aka below
>
>   #define DEF_SAT_U_MUL_FMT_14(NT, WT)             \
>   NT __attribute__((noinline))                     \
>   sat_u_mul_##NT##_from_##WT##_fmt_14 (NT a, NT b) \
>   {                                                \
>     WT x = (WT)a * (WT)b;                          \
>     NT hi = x >> (sizeof(NT) * 8);                 \
>     NT lo = (NT)x;                                 \
>     return hi == 0 ? lo : -1;                      \
>   }
>
> while WT is uint128_t, uint64_t, uint32_t and uint16_t, and
> NT is uint64_t, uint32_t, uint16_t or uint8_t.

OK.

Thanks,
Richard.

> gcc/ChangeLog:
>
>         * match-sat-alu.pd: Add pattern for unsigned scalar
>         SAT_MUL form 14.
>
> Signed-off-by: Pan Li <[email protected]>
> ---
>  gcc/match-sat-alu.pd | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>
> diff --git a/gcc/match-sat-alu.pd b/gcc/match-sat-alu.pd
> index 6e6fd2afda7..ede87138d49 100644
> --- a/gcc/match-sat-alu.pd
> +++ b/gcc/match-sat-alu.pd
> @@ -569,6 +569,30 @@ along with GCC; see the file COPYING3.  If not see
>        bool c2_is_type_precision_p = tree_to_uhwi (@2) == prec;
>       }
>       (if (c2_is_type_precision_p)))))
> +  (match (unsigned_integer_sat_mul @0 @1)
> +   /* SAT_U_MUL (X, Y) = {
> +       WT x = (WT)a * (WT)b;
> +       NT hi = x >> (sizeof(NT) * 8);
> +       NT lo = (NT)x;
> +       NT lo = (NT)x;
> +       return hi == 0 ? lo : -1;
> +      } while WT is uint128_t, uint64_t, uint32_t, uint16_t,
> +       and T is uint64_t, uint32_t, uint16_t, uint8_t.  */
> +   (convert (cond^ (eq (convert (rshift (mult:c@3 (convert @0) (convert @1))
> +                                       INTEGER_CST@2))
> +                       integer_zerop)
> +                  @3 INTEGER_CST@4))
> +   (if (types_match (type, @0, @1) && tree_fits_uhwi_p (@2))
> +    (with
> +     {
> +      unsigned prec = TYPE_PRECISION (type);
> +      unsigned widen_prec = TYPE_PRECISION (TREE_TYPE (@3));
> +      wide_int max = wi::mask (prec, false, widen_prec);
> +
> +      bool c2_is_type_prec_p = tree_to_uhwi (@2) == prec;
> +      bool c4_is_max_p = wi::eq_p (wi::to_wide (@4), max);
> +     }
> +     (if (c2_is_type_prec_p && c4_is_max_p)))))
>    (match (unsigned_integer_sat_mul @0 @1)
>     /* SAT_U_MUL (X, Y) = {
>         WT x = (WT)a * (WT)b;
> --
> 2.43.0
>

Reply via email to