public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH v4] Match: Add overloaded types_match to avoid code dup [NFC]
@ 2024-05-23  0:24 pan2.li
  2024-05-23 11:48 ` Richard Biener
  0 siblings, 1 reply; 4+ messages in thread
From: pan2.li @ 2024-05-23  0:24 UTC (permalink / raw)
  To: gcc-patches
  Cc: juzhe.zhong, kito.cheng, tamar.christina, richard.guenther,
	pinskia, 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,  add overloaded types_match func
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:

	* generic-match-head.cc (types_match): Add overloaded types_match
	for 3 types.
	* gimple-match-head.cc (types_match): Ditto.
	* match.pd: Leverage overloaded types_match.

Signed-off-by: Pan Li <pan2.li@intel.com>
---
 gcc/generic-match-head.cc | 14 ++++++++++++++
 gcc/gimple-match-head.cc  | 14 ++++++++++++++
 gcc/match.pd              | 30 ++++++++++--------------------
 3 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/gcc/generic-match-head.cc b/gcc/generic-match-head.cc
index 0d3f648fe8d..8d8ecfaeb1d 100644
--- a/gcc/generic-match-head.cc
+++ b/gcc/generic-match-head.cc
@@ -59,6 +59,20 @@ types_match (tree t1, tree t2)
   return TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2);
 }
 
+/* Routine to determine if the types T1, T2 and T3 are effectively
+   the same for GENERIC.  If T1, T2 or T2 is not a type, the test
+   applies to their TREE_TYPE.  */
+
+static inline bool
+types_match (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);
+
+  return types_match (t1, t2) && types_match (t2, t3);
+}
+
 /* Return if T has a single use.  For GENERIC, we assume this is
    always true.  */
 
diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc
index 5f8a1a1ad8e..2b7f746ab13 100644
--- a/gcc/gimple-match-head.cc
+++ b/gcc/gimple-match-head.cc
@@ -79,6 +79,20 @@ types_match (tree t1, tree t2)
   return types_compatible_p (t1, t2);
 }
 
+/* Routine to determine if the types T1, T2 and T3 are effectively
+   the same for GIMPLE.  If T1, T2 or T2 is not a type, the test
+   applies to their TREE_TYPE.  */
+
+static inline bool
+types_match (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);
+
+  return types_match (t1, t2) && types_match (t2, t3);
+}
+
 /* Return if T has a single use.  For GIMPLE, we also allow any
    non-SSA_NAME (ie constants) and zero uses to cope with uses
    that aren't linked up yet.  */
diff --git a/gcc/match.pd b/gcc/match.pd
index 35e3d82b131..7081d76d56a 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -3048,38 +3048,28 @@ 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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
+      && types_match (type, @0, @1))))
 
 (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
+      && types_match (type, @0, @1))))
 
 (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
+      && types_match (type, @0, @1))))
 
 (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
+      && types_match (type, @0, @1))))
 
 (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
+      && types_match (type, @0, @1))))
 
 /* 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.
-- 
2.34.1


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

* Re: [PATCH v4] Match: Add overloaded types_match to avoid code dup [NFC]
  2024-05-23  0:24 [PATCH v4] Match: Add overloaded types_match to avoid code dup [NFC] pan2.li
@ 2024-05-23 11:48 ` Richard Biener
  2024-05-23 12:05   ` Li, Pan2
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Biener @ 2024-05-23 11:48 UTC (permalink / raw)
  To: pan2.li; +Cc: gcc-patches, juzhe.zhong, kito.cheng, tamar.christina, pinskia

On Thu, May 23, 2024 at 2:24 AM <pan2.li@intel.com> wrote:
>
> 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,  add overloaded types_match func
> 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:
>
>         * generic-match-head.cc (types_match): Add overloaded types_match
>         for 3 types.
>         * gimple-match-head.cc (types_match): Ditto.
>         * match.pd: Leverage overloaded types_match.
>
> Signed-off-by: Pan Li <pan2.li@intel.com>
> ---
>  gcc/generic-match-head.cc | 14 ++++++++++++++
>  gcc/gimple-match-head.cc  | 14 ++++++++++++++
>  gcc/match.pd              | 30 ++++++++++--------------------
>  3 files changed, 38 insertions(+), 20 deletions(-)
>
> diff --git a/gcc/generic-match-head.cc b/gcc/generic-match-head.cc
> index 0d3f648fe8d..8d8ecfaeb1d 100644
> --- a/gcc/generic-match-head.cc
> +++ b/gcc/generic-match-head.cc
> @@ -59,6 +59,20 @@ types_match (tree t1, tree t2)
>    return TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2);
>  }
>
> +/* Routine to determine if the types T1, T2 and T3 are effectively
> +   the same for GENERIC.  If T1, T2 or T2 is not a type, the test
> +   applies to their TREE_TYPE.  */
> +
> +static inline bool
> +types_match (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);

the above three lines are redundant.

> +  return types_match (t1, t2) && types_match (t2, t3);
> +}
> +
>  /* Return if T has a single use.  For GENERIC, we assume this is
>     always true.  */
>
> diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc
> index 5f8a1a1ad8e..2b7f746ab13 100644
> --- a/gcc/gimple-match-head.cc
> +++ b/gcc/gimple-match-head.cc
> @@ -79,6 +79,20 @@ types_match (tree t1, tree t2)
>    return types_compatible_p (t1, t2);
>  }
>
> +/* Routine to determine if the types T1, T2 and T3 are effectively
> +   the same for GIMPLE.  If T1, T2 or T2 is not a type, the test
> +   applies to their TREE_TYPE.  */
> +
> +static inline bool
> +types_match (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);

likewise.

OK with those removed.

Richard.

> +  return types_match (t1, t2) && types_match (t2, t3);
> +}
> +
>  /* Return if T has a single use.  For GIMPLE, we also allow any
>     non-SSA_NAME (ie constants) and zero uses to cope with uses
>     that aren't linked up yet.  */
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 35e3d82b131..7081d76d56a 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -3048,38 +3048,28 @@ 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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  /* 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.
> --
> 2.34.1
>

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

* RE: [PATCH v4] Match: Add overloaded types_match to avoid code dup [NFC]
  2024-05-23 11:48 ` Richard Biener
@ 2024-05-23 12:05   ` Li, Pan2
  2024-05-23 14:48     ` Li, Pan2
  0 siblings, 1 reply; 4+ messages in thread
From: Li, Pan2 @ 2024-05-23 12:05 UTC (permalink / raw)
  To: Richard Biener
  Cc: gcc-patches, juzhe.zhong, kito.cheng, tamar.christina, pinskia

> the above three lines are redundant.
> OK with those removed.

Got it, will commit it after no surprise in test for removal.

Pan

-----Original Message-----
From: Richard Biener <richard.guenther@gmail.com> 
Sent: Thursday, May 23, 2024 7:49 PM
To: Li, Pan2 <pan2.li@intel.com>
Cc: gcc-patches@gcc.gnu.org; juzhe.zhong@rivai.ai; kito.cheng@gmail.com; tamar.christina@arm.com; pinskia@gmail.com
Subject: Re: [PATCH v4] Match: Add overloaded types_match to avoid code dup [NFC]

On Thu, May 23, 2024 at 2:24 AM <pan2.li@intel.com> wrote:
>
> 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,  add overloaded types_match func
> 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:
>
>         * generic-match-head.cc (types_match): Add overloaded types_match
>         for 3 types.
>         * gimple-match-head.cc (types_match): Ditto.
>         * match.pd: Leverage overloaded types_match.
>
> Signed-off-by: Pan Li <pan2.li@intel.com>
> ---
>  gcc/generic-match-head.cc | 14 ++++++++++++++
>  gcc/gimple-match-head.cc  | 14 ++++++++++++++
>  gcc/match.pd              | 30 ++++++++++--------------------
>  3 files changed, 38 insertions(+), 20 deletions(-)
>
> diff --git a/gcc/generic-match-head.cc b/gcc/generic-match-head.cc
> index 0d3f648fe8d..8d8ecfaeb1d 100644
> --- a/gcc/generic-match-head.cc
> +++ b/gcc/generic-match-head.cc
> @@ -59,6 +59,20 @@ types_match (tree t1, tree t2)
>    return TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2);
>  }
>
> +/* Routine to determine if the types T1, T2 and T3 are effectively
> +   the same for GENERIC.  If T1, T2 or T2 is not a type, the test
> +   applies to their TREE_TYPE.  */
> +
> +static inline bool
> +types_match (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);

the above three lines are redundant.

> +  return types_match (t1, t2) && types_match (t2, t3);
> +}
> +
>  /* Return if T has a single use.  For GENERIC, we assume this is
>     always true.  */
>
> diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc
> index 5f8a1a1ad8e..2b7f746ab13 100644
> --- a/gcc/gimple-match-head.cc
> +++ b/gcc/gimple-match-head.cc
> @@ -79,6 +79,20 @@ types_match (tree t1, tree t2)
>    return types_compatible_p (t1, t2);
>  }
>
> +/* Routine to determine if the types T1, T2 and T3 are effectively
> +   the same for GIMPLE.  If T1, T2 or T2 is not a type, the test
> +   applies to their TREE_TYPE.  */
> +
> +static inline bool
> +types_match (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);

likewise.

OK with those removed.

Richard.

> +  return types_match (t1, t2) && types_match (t2, t3);
> +}
> +
>  /* Return if T has a single use.  For GIMPLE, we also allow any
>     non-SSA_NAME (ie constants) and zero uses to cope with uses
>     that aren't linked up yet.  */
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 35e3d82b131..7081d76d56a 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -3048,38 +3048,28 @@ 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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  /* 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.
> --
> 2.34.1
>

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

* RE: [PATCH v4] Match: Add overloaded types_match to avoid code dup [NFC]
  2024-05-23 12:05   ` Li, Pan2
@ 2024-05-23 14:48     ` Li, Pan2
  0 siblings, 0 replies; 4+ messages in thread
From: Li, Pan2 @ 2024-05-23 14:48 UTC (permalink / raw)
  To: Richard Biener
  Cc: gcc-patches, juzhe.zhong, kito.cheng, tamar.christina, pinskia

Committed as passed below test suites, thanks Richard.

    * The rv64gcv fully regression test.
    * The x86 bootstrap test.
    * The x86 regression test.

Pan

-----Original Message-----
From: Li, Pan2 
Sent: Thursday, May 23, 2024 8:06 PM
To: Richard Biener <richard.guenther@gmail.com>
Cc: gcc-patches@gcc.gnu.org; juzhe.zhong@rivai.ai; kito.cheng@gmail.com; tamar.christina@arm.com; pinskia@gmail.com
Subject: RE: [PATCH v4] Match: Add overloaded types_match to avoid code dup [NFC]

> the above three lines are redundant.
> OK with those removed.

Got it, will commit it after no surprise in test for removal.

Pan

-----Original Message-----
From: Richard Biener <richard.guenther@gmail.com> 
Sent: Thursday, May 23, 2024 7:49 PM
To: Li, Pan2 <pan2.li@intel.com>
Cc: gcc-patches@gcc.gnu.org; juzhe.zhong@rivai.ai; kito.cheng@gmail.com; tamar.christina@arm.com; pinskia@gmail.com
Subject: Re: [PATCH v4] Match: Add overloaded types_match to avoid code dup [NFC]

On Thu, May 23, 2024 at 2:24 AM <pan2.li@intel.com> wrote:
>
> 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,  add overloaded types_match func
> 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:
>
>         * generic-match-head.cc (types_match): Add overloaded types_match
>         for 3 types.
>         * gimple-match-head.cc (types_match): Ditto.
>         * match.pd: Leverage overloaded types_match.
>
> Signed-off-by: Pan Li <pan2.li@intel.com>
> ---
>  gcc/generic-match-head.cc | 14 ++++++++++++++
>  gcc/gimple-match-head.cc  | 14 ++++++++++++++
>  gcc/match.pd              | 30 ++++++++++--------------------
>  3 files changed, 38 insertions(+), 20 deletions(-)
>
> diff --git a/gcc/generic-match-head.cc b/gcc/generic-match-head.cc
> index 0d3f648fe8d..8d8ecfaeb1d 100644
> --- a/gcc/generic-match-head.cc
> +++ b/gcc/generic-match-head.cc
> @@ -59,6 +59,20 @@ types_match (tree t1, tree t2)
>    return TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2);
>  }
>
> +/* Routine to determine if the types T1, T2 and T3 are effectively
> +   the same for GENERIC.  If T1, T2 or T2 is not a type, the test
> +   applies to their TREE_TYPE.  */
> +
> +static inline bool
> +types_match (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);

the above three lines are redundant.

> +  return types_match (t1, t2) && types_match (t2, t3);
> +}
> +
>  /* Return if T has a single use.  For GENERIC, we assume this is
>     always true.  */
>
> diff --git a/gcc/gimple-match-head.cc b/gcc/gimple-match-head.cc
> index 5f8a1a1ad8e..2b7f746ab13 100644
> --- a/gcc/gimple-match-head.cc
> +++ b/gcc/gimple-match-head.cc
> @@ -79,6 +79,20 @@ types_match (tree t1, tree t2)
>    return types_compatible_p (t1, t2);
>  }
>
> +/* Routine to determine if the types T1, T2 and T3 are effectively
> +   the same for GIMPLE.  If T1, T2 or T2 is not a type, the test
> +   applies to their TREE_TYPE.  */
> +
> +static inline bool
> +types_match (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);

likewise.

OK with those removed.

Richard.

> +  return types_match (t1, t2) && types_match (t2, t3);
> +}
> +
>  /* Return if T has a single use.  For GIMPLE, we also allow any
>     non-SSA_NAME (ie constants) and zero uses to cope with uses
>     that aren't linked up yet.  */
> diff --git a/gcc/match.pd b/gcc/match.pd
> index 35e3d82b131..7081d76d56a 100644
> --- a/gcc/match.pd
> +++ b/gcc/match.pd
> @@ -3048,38 +3048,28 @@ 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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  (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 (INTEGRAL_TYPE_P (type) && TYPE_UNSIGNED (type)
> +      && types_match (type, @0, @1))))
>
>  /* 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.
> --
> 2.34.1
>

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

end of thread, other threads:[~2024-05-23 14:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-23  0:24 [PATCH v4] Match: Add overloaded types_match to avoid code dup [NFC] pan2.li
2024-05-23 11:48 ` Richard Biener
2024-05-23 12:05   ` Li, Pan2
2024-05-23 14:48     ` 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).