diff options
author | Pan Li <pan2.li@intel.com> | 2025-08-13 13:55:27 +0800 |
---|---|---|
committer | Pan Li <pan2.li@intel.com> | 2025-08-22 21:16:40 +0800 |
commit | f2794c206f112547907ed010b541146dc005d37e (patch) | |
tree | d34b8731e622e0d76bb17ded63b82edde189af17 | |
parent | e12208722dabdad25cc13bb580991b5bf511a104 (diff) | |
download | gcc-f2794c206f112547907ed010b541146dc005d37e.zip gcc-f2794c206f112547907ed010b541146dc005d37e.tar.gz gcc-f2794c206f112547907ed010b541146dc005d37e.tar.bz2 |
Match: Add form 3 for unsigned SAT_MUL
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.
gcc/ChangeLog:
* match.pd: Add form 3 for unsigned SAT_MUL.
Signed-off-by: Pan Li <pan2.li@intel.com>
-rw-r--r-- | gcc/match.pd | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/gcc/match.pd b/gcc/match.pd index 66e8a78..b1d7a3a 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: |