public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v3] Match: Extract ternary_integer_types_match_p helper func [NFC]
@ 2024-05-21  1:13 pan2.li
  2024-05-21  3:19 ` Tamar Christina
  0 siblings, 1 reply; 3+ messages in thread
From: pan2.li @ 2024-05-21  1:13 UTC (permalink / raw)
  To: gcc-patches
  Cc: juzhe.zhong, kito.cheng, tamar.christina, richard.guenther, Pan Li

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

There are sorts of match pattern for SAT related cases,  there will be
some duplicated code to check the dest, op_0, op_1 are same tree types.
Aka ternary tree type matches.  Thus, extract one helper function to
do this and avoid match code duplication.

The below test suites are passed for this patch:
* The rv64gcv fully regression test.
* The x86 bootstrap test.
* The x86 regression test.

gcc/ChangeLog:

	* match.pd: Leverage helper func for SAT_ADD match.
	* tree.cc (ternary_integer_types_match_p): New func impl to
	check if ternary tree types are all integer.
	* tree.h (ternary_integer_types_match_p): New func decl.

Signed-off-by: Pan Li <pan2.li@intel.com>
---
 gcc/match.pd | 28 +++++++---------------------
 gcc/tree.cc  | 16 ++++++++++++++++
 gcc/tree.h   |  5 +++++
 3 files changed, 28 insertions(+), 21 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index 0f9c34fa897..cff67c84498 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -39,7 +39,8 @@ along with GCC; see the file COPYING3.  If not see
    HONOR_NANS
    uniform_vector_p
    expand_vec_cmp_expr_p
-   bitmask_inv_cst_vector_p)
+   bitmask_inv_cst_vector_p
+   ternary_integer_types_match_p)
 
 /* Operator lists.  */
 (define_operator_list tcc_comparison
@@ -3046,38 +3047,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* Unsigned Saturation Add */
 (match (usadd_left_part_1 @0 @1)
  (plus:c @0 @1)
- (if (INTEGRAL_TYPE_P (type)
-      && TYPE_UNSIGNED (TREE_TYPE (@0))
-      && types_match (type, TREE_TYPE (@0))
-      && types_match (type, TREE_TYPE (@1)))))
+ (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED (type))))
 
 (match (usadd_left_part_2 @0 @1)
  (realpart (IFN_ADD_OVERFLOW:c @0 @1))
- (if (INTEGRAL_TYPE_P (type)
-      && TYPE_UNSIGNED (TREE_TYPE (@0))
-      && types_match (type, TREE_TYPE (@0))
-      && types_match (type, TREE_TYPE (@1)))))
+ (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED (type))))
 
 (match (usadd_right_part_1 @0 @1)
  (negate (convert (lt (plus:c @0 @1) @0)))
- (if (INTEGRAL_TYPE_P (type)
-      && TYPE_UNSIGNED (TREE_TYPE (@0))
-      && types_match (type, TREE_TYPE (@0))
-      && types_match (type, TREE_TYPE (@1)))))
+ (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED (type))))
 
 (match (usadd_right_part_1 @0 @1)
  (negate (convert (gt @0 (plus:c @0 @1))))
- (if (INTEGRAL_TYPE_P (type)
-      && TYPE_UNSIGNED (TREE_TYPE (@0))
-      && types_match (type, TREE_TYPE (@0))
-      && types_match (type, TREE_TYPE (@1)))))
+ (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED (type))))
 
 (match (usadd_right_part_2 @0 @1)
  (negate (convert (ne (imagpart (IFN_ADD_OVERFLOW:c @0 @1)) integer_zerop)))
- (if (INTEGRAL_TYPE_P (type)
-      && TYPE_UNSIGNED (TREE_TYPE (@0))
-      && types_match (type, TREE_TYPE (@0))
-      && types_match (type, TREE_TYPE (@1)))))
+ (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED (type))))
 
 /* We cannot merge or overload usadd_left_part_1 and usadd_left_part_2
    because the sub part of left_part_2 cannot work with right_part_1.
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 6564b002dc1..b59d42c3e47 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -10622,6 +10622,22 @@ uniform_integer_cst_p (tree t)
   return NULL_TREE;
 }
 
+/* Check if the types T1,  T2 and T3 are effectively the same integer type.
+   If T1,  T2 or T3 is not a type, the test applies to their TREE_TYPE.  */
+
+bool
+ternary_integer_types_match_p (tree t1, tree t2, tree t3)
+{
+  t1 = TYPE_P (t1) ? t1 : TREE_TYPE (t1);
+  t2 = TYPE_P (t2) ? t2 : TREE_TYPE (t2);
+  t3 = TYPE_P (t3) ? t3 : TREE_TYPE (t3);
+
+  if (!INTEGRAL_TYPE_P (t1) || !INTEGRAL_TYPE_P (t2) || !INTEGRAL_TYPE_P (t3))
+    return false;
+
+  return types_compatible_p (t1, t2) && types_compatible_p (t2, t3);
+}
+
 /* Checks to see if T is a constant or a constant vector and if each element E
    adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE.  */
 
diff --git a/gcc/tree.h b/gcc/tree.h
index ee2aae332a4..4ac59ac55cb 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -5212,6 +5212,11 @@ extern bool integer_pow2p (const_tree);
 
 extern tree bitmask_inv_cst_vector_p (tree);
 
+/* Check if the types T1,  T2 and T3 are effectively the same integer type.
+   If T1,  T2 or T3 is not a type, the test applies to their TREE_TYPE.  */
+
+extern bool ternary_integer_types_match_p (tree, tree, tree);
+
 /* integer_nonzerop (tree x) is nonzero if X is an integer constant
    with a nonzero value.  */
 
-- 
2.34.1


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

* RE: [PATCH v3] Match: Extract ternary_integer_types_match_p helper func [NFC]
  2024-05-21  1:13 [PATCH v3] Match: Extract ternary_integer_types_match_p helper func [NFC] pan2.li
@ 2024-05-21  3:19 ` Tamar Christina
  2024-05-21 10:47   ` Li, Pan2
  0 siblings, 1 reply; 3+ messages in thread
From: Tamar Christina @ 2024-05-21  3:19 UTC (permalink / raw)
  To: pan2.li, gcc-patches; +Cc: juzhe.zhong, kito.cheng, richard.guenther



> -----Original Message-----
> From: pan2.li@intel.com <pan2.li@intel.com>
> Sent: Tuesday, May 21, 2024 2:13 AM
> To: gcc-patches@gcc.gnu.org
> Cc: juzhe.zhong@rivai.ai; kito.cheng@gmail.com; Tamar Christina
> <Tamar.Christina@arm.com>; richard.guenther@gmail.com; Pan Li
> <pan2.li@intel.com>
> Subject: [PATCH v3] Match: Extract ternary_integer_types_match_p helper func
> [NFC]
> 
> From: Pan Li <pan2.li@intel.com>
> 
> There are sorts of match pattern for SAT related cases,  there will be
> some duplicated code to check the dest, op_0, op_1 are same tree types.
> Aka ternary tree type matches.  Thus, extract one helper function to
> do this and avoid match code duplication.
> 
> The below test suites are passed for this patch:
> * The rv64gcv fully regression test.
> * The x86 bootstrap test.
> * The x86 regression test.
> 
> gcc/ChangeLog:
> 
> 	* match.pd: Leverage helper func for SAT_ADD match.
> 	* tree.cc (ternary_integer_types_match_p): New func impl to
> 	check if ternary tree types are all integer.
> 	* tree.h (ternary_integer_types_match_p): New func decl.
> 

Thanks, looks good to me! You still need approval from a maintainer..

Cheers,
Tamar

> Signed-off-by: Pan Li <pan2.li@intel.com>
> ---
>  gcc/match.pd | 28 +++++++---------------------
>  gcc/tree.cc  | 16 ++++++++++++++++
>  gcc/tree.h   |  5 +++++
>  3 files changed, 28 insertions(+), 21 deletions(-)
> 
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 0f9c34fa897..cff67c84498 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -39,7 +39,8 @@ along with GCC; see the file COPYING3.  If not see
>     HONOR_NANS
>     uniform_vector_p
>     expand_vec_cmp_expr_p
> -   bitmask_inv_cst_vector_p)
> +   bitmask_inv_cst_vector_p
> +   ternary_integer_types_match_p)
> 
>  /* Operator lists.  */
>  (define_operator_list tcc_comparison
> @@ -3046,38 +3047,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>  /* Unsigned Saturation Add */
>  (match (usadd_left_part_1 @0 @1)
>   (plus:c @0 @1)
> - (if (INTEGRAL_TYPE_P (type)
> -      && TYPE_UNSIGNED (TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@1)))))
> + (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED
> (type))))
> 
>  (match (usadd_left_part_2 @0 @1)
>   (realpart (IFN_ADD_OVERFLOW:c @0 @1))
> - (if (INTEGRAL_TYPE_P (type)
> -      && TYPE_UNSIGNED (TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@1)))))
> + (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED
> (type))))
> 
>  (match (usadd_right_part_1 @0 @1)
>   (negate (convert (lt (plus:c @0 @1) @0)))
> - (if (INTEGRAL_TYPE_P (type)
> -      && TYPE_UNSIGNED (TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@1)))))
> + (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED
> (type))))
> 
>  (match (usadd_right_part_1 @0 @1)
>   (negate (convert (gt @0 (plus:c @0 @1))))
> - (if (INTEGRAL_TYPE_P (type)
> -      && TYPE_UNSIGNED (TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@1)))))
> + (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED
> (type))))
> 
>  (match (usadd_right_part_2 @0 @1)
>   (negate (convert (ne (imagpart (IFN_ADD_OVERFLOW:c @0 @1))
> integer_zerop)))
> - (if (INTEGRAL_TYPE_P (type)
> -      && TYPE_UNSIGNED (TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@1)))))
> + (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED
> (type))))
> 
>  /* We cannot merge or overload usadd_left_part_1 and usadd_left_part_2
>     because the sub part of left_part_2 cannot work with right_part_1.
> diff --git a/gcc/tree.cc b/gcc/tree.cc
> index 6564b002dc1..b59d42c3e47 100644
> --- a/gcc/tree.cc
> +++ b/gcc/tree.cc
> @@ -10622,6 +10622,22 @@ uniform_integer_cst_p (tree t)
>    return NULL_TREE;
>  }
> 
> +/* Check if the types T1,  T2 and T3 are effectively the same integer type.
> +   If T1,  T2 or T3 is not a type, the test applies to their TREE_TYPE.  */
> +
> +bool
> +ternary_integer_types_match_p (tree t1, tree t2, tree t3)
> +{
> +  t1 = TYPE_P (t1) ? t1 : TREE_TYPE (t1);
> +  t2 = TYPE_P (t2) ? t2 : TREE_TYPE (t2);
> +  t3 = TYPE_P (t3) ? t3 : TREE_TYPE (t3);
> +
> +  if (!INTEGRAL_TYPE_P (t1) || !INTEGRAL_TYPE_P (t2) || !INTEGRAL_TYPE_P
> (t3))
> +    return false;
> +
> +  return types_compatible_p (t1, t2) && types_compatible_p (t2, t3);
> +}
> +
>  /* Checks to see if T is a constant or a constant vector and if each element E
>     adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE.  */
> 
> diff --git a/gcc/tree.h b/gcc/tree.h
> index ee2aae332a4..4ac59ac55cb 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -5212,6 +5212,11 @@ extern bool integer_pow2p (const_tree);
> 
>  extern tree bitmask_inv_cst_vector_p (tree);
> 
> +/* Check if the types T1,  T2 and T3 are effectively the same integer type.
> +   If T1,  T2 or T3 is not a type, the test applies to their TREE_TYPE.  */
> +
> +extern bool ternary_integer_types_match_p (tree, tree, tree);
> +
>  /* integer_nonzerop (tree x) is nonzero if X is an integer constant
>     with a nonzero value.  */
> 
> --
> 2.34.1


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

* RE: [PATCH v3] Match: Extract ternary_integer_types_match_p helper func [NFC]
  2024-05-21  3:19 ` Tamar Christina
@ 2024-05-21 10:47   ` Li, Pan2
  0 siblings, 0 replies; 3+ messages in thread
From: Li, Pan2 @ 2024-05-21 10:47 UTC (permalink / raw)
  To: Tamar Christina, gcc-patches; +Cc: juzhe.zhong, kito.cheng, richard.guenther

> Thanks, looks good to me! You still need approval from a maintainer..

Thanks Tamar, let's wait for a while, 😊!

Pan

-----Original Message-----
From: Tamar Christina <Tamar.Christina@arm.com> 
Sent: Tuesday, May 21, 2024 11:19 AM
To: Li, Pan2 <pan2.li@intel.com>; gcc-patches@gcc.gnu.org
Cc: juzhe.zhong@rivai.ai; kito.cheng@gmail.com; richard.guenther@gmail.com
Subject: RE: [PATCH v3] Match: Extract ternary_integer_types_match_p helper func [NFC]



> -----Original Message-----
> From: pan2.li@intel.com <pan2.li@intel.com>
> Sent: Tuesday, May 21, 2024 2:13 AM
> To: gcc-patches@gcc.gnu.org
> Cc: juzhe.zhong@rivai.ai; kito.cheng@gmail.com; Tamar Christina
> <Tamar.Christina@arm.com>; richard.guenther@gmail.com; Pan Li
> <pan2.li@intel.com>
> Subject: [PATCH v3] Match: Extract ternary_integer_types_match_p helper func
> [NFC]
> 
> From: Pan Li <pan2.li@intel.com>
> 
> There are sorts of match pattern for SAT related cases,  there will be
> some duplicated code to check the dest, op_0, op_1 are same tree types.
> Aka ternary tree type matches.  Thus, extract one helper function to
> do this and avoid match code duplication.
> 
> The below test suites are passed for this patch:
> * The rv64gcv fully regression test.
> * The x86 bootstrap test.
> * The x86 regression test.
> 
> gcc/ChangeLog:
> 
> 	* match.pd: Leverage helper func for SAT_ADD match.
> 	* tree.cc (ternary_integer_types_match_p): New func impl to
> 	check if ternary tree types are all integer.
> 	* tree.h (ternary_integer_types_match_p): New func decl.
> 

Thanks, looks good to me! You still need approval from a maintainer..

Cheers,
Tamar

> Signed-off-by: Pan Li <pan2.li@intel.com>
> ---
>  gcc/match.pd | 28 +++++++---------------------
>  gcc/tree.cc  | 16 ++++++++++++++++
>  gcc/tree.h   |  5 +++++
>  3 files changed, 28 insertions(+), 21 deletions(-)
> 
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 0f9c34fa897..cff67c84498 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -39,7 +39,8 @@ along with GCC; see the file COPYING3.  If not see
>     HONOR_NANS
>     uniform_vector_p
>     expand_vec_cmp_expr_p
> -   bitmask_inv_cst_vector_p)
> +   bitmask_inv_cst_vector_p
> +   ternary_integer_types_match_p)
> 
>  /* Operator lists.  */
>  (define_operator_list tcc_comparison
> @@ -3046,38 +3047,23 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
>  /* Unsigned Saturation Add */
>  (match (usadd_left_part_1 @0 @1)
>   (plus:c @0 @1)
> - (if (INTEGRAL_TYPE_P (type)
> -      && TYPE_UNSIGNED (TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@1)))))
> + (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED
> (type))))
> 
>  (match (usadd_left_part_2 @0 @1)
>   (realpart (IFN_ADD_OVERFLOW:c @0 @1))
> - (if (INTEGRAL_TYPE_P (type)
> -      && TYPE_UNSIGNED (TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@1)))))
> + (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED
> (type))))
> 
>  (match (usadd_right_part_1 @0 @1)
>   (negate (convert (lt (plus:c @0 @1) @0)))
> - (if (INTEGRAL_TYPE_P (type)
> -      && TYPE_UNSIGNED (TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@1)))))
> + (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED
> (type))))
> 
>  (match (usadd_right_part_1 @0 @1)
>   (negate (convert (gt @0 (plus:c @0 @1))))
> - (if (INTEGRAL_TYPE_P (type)
> -      && TYPE_UNSIGNED (TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@1)))))
> + (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED
> (type))))
> 
>  (match (usadd_right_part_2 @0 @1)
>   (negate (convert (ne (imagpart (IFN_ADD_OVERFLOW:c @0 @1))
> integer_zerop)))
> - (if (INTEGRAL_TYPE_P (type)
> -      && TYPE_UNSIGNED (TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@0))
> -      && types_match (type, TREE_TYPE (@1)))))
> + (if (ternary_integer_types_match_p (type, @0, @1) && TYPE_UNSIGNED
> (type))))
> 
>  /* We cannot merge or overload usadd_left_part_1 and usadd_left_part_2
>     because the sub part of left_part_2 cannot work with right_part_1.
> diff --git a/gcc/tree.cc b/gcc/tree.cc
> index 6564b002dc1..b59d42c3e47 100644
> --- a/gcc/tree.cc
> +++ b/gcc/tree.cc
> @@ -10622,6 +10622,22 @@ uniform_integer_cst_p (tree t)
>    return NULL_TREE;
>  }
> 
> +/* Check if the types T1,  T2 and T3 are effectively the same integer type.
> +   If T1,  T2 or T3 is not a type, the test applies to their TREE_TYPE.  */
> +
> +bool
> +ternary_integer_types_match_p (tree t1, tree t2, tree t3)
> +{
> +  t1 = TYPE_P (t1) ? t1 : TREE_TYPE (t1);
> +  t2 = TYPE_P (t2) ? t2 : TREE_TYPE (t2);
> +  t3 = TYPE_P (t3) ? t3 : TREE_TYPE (t3);
> +
> +  if (!INTEGRAL_TYPE_P (t1) || !INTEGRAL_TYPE_P (t2) || !INTEGRAL_TYPE_P
> (t3))
> +    return false;
> +
> +  return types_compatible_p (t1, t2) && types_compatible_p (t2, t3);
> +}
> +
>  /* Checks to see if T is a constant or a constant vector and if each element E
>     adheres to ~E + 1 == pow2 then return ~E otherwise NULL_TREE.  */
> 
> diff --git a/gcc/tree.h b/gcc/tree.h
> index ee2aae332a4..4ac59ac55cb 100644
> --- a/gcc/tree.h
> +++ b/gcc/tree.h
> @@ -5212,6 +5212,11 @@ extern bool integer_pow2p (const_tree);
> 
>  extern tree bitmask_inv_cst_vector_p (tree);
> 
> +/* Check if the types T1,  T2 and T3 are effectively the same integer type.
> +   If T1,  T2 or T3 is not a type, the test applies to their TREE_TYPE.  */
> +
> +extern bool ternary_integer_types_match_p (tree, tree, tree);
> +
>  /* integer_nonzerop (tree x) is nonzero if X is an integer constant
>     with a nonzero value.  */
> 
> --
> 2.34.1


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

end of thread, other threads:[~2024-05-21 10:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-21  1:13 [PATCH v3] Match: Extract ternary_integer_types_match_p helper func [NFC] pan2.li
2024-05-21  3:19 ` Tamar Christina
2024-05-21 10:47   ` 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).