public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v1] Match: Support form 11 for the unsigned scalar .SAT_SUB
@ 2024-06-17  7:07 pan2.li
  2024-06-18 11:08 ` Richard Biener
  0 siblings, 1 reply; 3+ messages in thread
From: pan2.li @ 2024-06-17  7:07 UTC (permalink / raw)
  To: gcc-patches
  Cc: juzhe.zhong, kito.cheng, richard.guenther, jeffreyalaw,
	rdapp.gcc, Pan Li

From: Pan Li <pan2.li@intel.com>

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.

gcc/ChangeLog:

	* match.pd: Add form 11 match pattern for .SAT_SUB.

Signed-off-by: Pan Li <pan2.li@intel.com>
---
 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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v1] Match: Support form 11 for the unsigned scalar .SAT_SUB
  2024-06-17  7:07 [PATCH v1] Match: Support form 11 for the unsigned scalar .SAT_SUB pan2.li
@ 2024-06-18 11:08 ` Richard Biener
  2024-06-18 13:42   ` Li, Pan2
  0 siblings, 1 reply; 3+ messages in thread
From: Richard Biener @ 2024-06-18 11:08 UTC (permalink / raw)
  To: pan2.li; +Cc: gcc-patches, juzhe.zhong, kito.cheng, jeffreyalaw, rdapp.gcc

On Mon, Jun 17, 2024 at 9:07 AM <pan2.li@intel.com> wrote:
>
> From: Pan Li <pan2.li@intel.com>
>
> 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 <pan2.li@intel.com>
> ---
>  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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH v1] Match: Support form 11 for the unsigned scalar .SAT_SUB
  2024-06-18 11:08 ` Richard Biener
@ 2024-06-18 13:42   ` Li, Pan2
  0 siblings, 0 replies; 3+ messages in thread
From: Li, Pan2 @ 2024-06-18 13:42 UTC (permalink / raw)
  To: Richard Biener
  Cc: gcc-patches, juzhe.zhong, kito.cheng, jeffreyalaw, rdapp.gcc

Thanks Richard, will commit this one and then have a try to reduce unnecessary pattern following your suggestion.

Pan

-----Original Message-----
From: Richard Biener <richard.guenther@gmail.com> 
Sent: Tuesday, June 18, 2024 7:08 PM
To: Li, Pan2 <pan2.li@intel.com>
Cc: gcc-patches@gcc.gnu.org; juzhe.zhong@rivai.ai; kito.cheng@gmail.com; jeffreyalaw@gmail.com; rdapp.gcc@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 <pan2.li@intel.com> wrote:
>
> From: Pan Li <pan2.li@intel.com>
>
> 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 <pan2.li@intel.com>
> ---
>  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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-06-18 13:42 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-17  7:07 [PATCH v1] Match: Support form 11 for the unsigned scalar .SAT_SUB pan2.li
2024-06-18 11:08 ` Richard Biener
2024-06-18 13:42   ` Li, Pan2

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).