On Mon, Oct 21, 2024 at 4:22 PM Akram Ahmad <akram.ah...@arm.com> wrote:
>
> This patch adds a new case for unsigned scalar saturating subtraction
> using a branch with a greater-than-or-equal condition. For example,
>
>         X >= (X - Y) ? (X - Y) : 0
>
> is transformed into SAT_SUB (X, Y) when X and Y are unsigned scalars,
> which therefore correctly matches more cases of IFN SAT_SUB.
>
> This passes the aarch64-none-linux-gnu regression tests with no failures.

Can you also add a testcase that exercises this?  Otherwise looks good.

Thanks,
Richard.

> gcc/ChangeLog:
>
>         * match.pd: Add new match for SAT_SUB.
> ---
>  gcc/match.pd | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index ee53c25cef9..4fc5efa6247 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -3360,6 +3360,14 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>    }
>    (if (wi::eq_p (sum, wi::uhwi (0, precision)))))))
>
> +/* Unsigned saturation sub, case 11 (branch with ge):
> +  SAT_U_SUB = X >= (X - Y) ? (X - Y) : 0.  */
> +(match (unsigned_integer_sat_sub @0 @1)
> + (cond^ (ge @0 (minus @0 @1))
> +  (convert? (minus (convert1? @0) (convert1? @1))) integer_zerop)
> + (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && TYPE_UNSIGNED (TREE_TYPE (@0)) && types_match (@0, @1))))
> +
>  /* Signed saturation sub, case 1:
>     T minus = (T)((UT)X - (UT)Y);
>     SAT_S_SUB = (X ^ Y) & (X ^ minus) < 0 ? (-(T)(X < 0) ^ MAX) : minus;
> --
> 2.34.1
>

Reply via email to