]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Match: Add overloaded types_match to avoid code dup [NFC]
authorPan Li <pan2.li@intel.com>
Thu, 23 May 2024 00:09:40 +0000 (08:09 +0800)
committerPan Li <pan2.li@intel.com>
Thu, 23 May 2024 14:46:43 +0000 (22:46 +0800)
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
gcc/gimple-match-head.cc
gcc/match.pd

index 0d3f648fe8dbd410dfe32e64f6e714682cd0fe02..e2e1e4b2d6458898a6874fa5857a473d76163d0c 100644 (file)
@@ -59,6 +59,16 @@ 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)
+{
+  return types_match (t1, t2) && types_match (t2, t3);
+}
+
 /* Return if T has a single use.  For GENERIC, we assume this is
    always true.  */
 
index 5f8a1a1ad8e3ebc30ff06b91c69fe5c2e92a68c6..49b1dde6ae4774b78b9860867f522b144dcd3488 100644 (file)
@@ -79,6 +79,16 @@ 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)
+{
+  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.  */
index 35e3d82b1319d6f826250842f66de9d64e1a3ee9..7081d76d56a6ea7cdd4c30ec8e757a4d8c49424c 100644 (file)
@@ -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.