Thanks Richard, will commit this one and then have a try to reduce unnecessary
pattern following your suggestion.
Pan
-Original Message-
From: Richard Biener
Sent: Tuesday, June 18, 2024 7:08 PM
To: Li, Pan2
Cc: gcc-patches@gcc.gnu.org; juzhe.zh...@rivai.ai; kito.ch...@gmail.com;
jeffreya...@gmail.com; rdapp@gmail.com
Subject: Re: [PATCH v1] Match: Support form 11 for the unsigned scalar .SAT_SUB
On Mon, Jun 17, 2024 at 9:07 AM wrote:
>
> From: Pan Li
>
> We missed one match pattern for the unsigned scalar .SAT_SUB, aka
> form 11.
>
> Form 11:
> #define SAT_SUB_U_11(T) \
> T sat_sub_u_11_##T (T x, T y) \
> { \
> T ret; \
> bool overflow = __builtin_sub_overflow (x, y, &ret); \
> return overflow ? 0 : ret; \
> }
>
> Thus, add above form 11 to the match pattern gimple_unsigned_integer_sat_sub.
>
> The below test suites are passed for this patch:
> 1. The rv64gcv fully regression test with newlib.
> 2. The rv64gcv build with glibc.
> 3. The x86 bootstrap test.
> 4. The x86 fully regression test.
OK, but see my other mail. Eventually sth like
(for cmp (tcc_comparison)
icmp (inverted_tcc_comparison)
ncmp (inverted_tcc_comparison_with_nans)
(simplify
(cond (cmp @0 @1) @2 @3)
(if (tree_swap_operands_p (@2, @3))
(with { enum tree_code ic = invert_tree_comparison (cmp, HONOR_NANS (@0)); }
(if (ic == icmp)
(cond (icmp @0 @1) @3 @2)
(if (ic == ncmp)
(cond (ncmp @0 @1) @3 @2))
helps here. Of course with matching PHIs the above isn't going to help.
> gcc/ChangeLog:
>
> * match.pd: Add form 11 match pattern for .SAT_SUB.
>
> Signed-off-by: Pan Li
> ---
> gcc/match.pd | 9 -
> 1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 99968d316ed..5c330a43ed0 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -3186,13 +3186,20 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
> (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
>&& types_match (type, @0, @1
>
> -/* Unsigned saturation sub, case 7 (branch with .SUB_OVERFLOW). */
> +/* Unsigned saturation sub, case 7 (branch eq with .SUB_OVERFLOW). */
> (match (unsigned_integer_sat_sub @0 @1)
> (cond^ (eq (imagpart (IFN_SUB_OVERFLOW@2 @0 @1)) integer_zerop)
>(realpart @2) integer_zerop)
> (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
>&& types_match (type, @0, @1
>
> +/* Unsigned saturation sub, case 8 (branch ne with .SUB_OVERFLOW). */
> +(match (unsigned_integer_sat_sub @0 @1)
> + (cond^ (ne (imagpart (IFN_SUB_OVERFLOW@2 @0 @1)) integer_zerop)
> + integer_zerop (realpart @2))
> + (if (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> + && types_match (type, @0, @1
> +
> /* x > y && x != XXX_MIN --> x > y
> x > y && x == XXX_MIN --> false . */
> (for eqne (eq ne)
> --
> 2.34.1
>