On Fri, 1 May 2015, Jeff Law wrote:

Slight refactoring of the condition by using types_match as suggested by Richi. I also applied the new types_match to 2 other patterns in match.pd where it seemed clearly appropriate.

I would like to propose this small tweak (regtested ok). If we had a different type for trees and types, this would be overloading the function. We already do this in a few places, and I find the resulting shorter code more readable.

2015-05-14  Marc Glisse  <marc.gli...@inria.fr>

        * generic-match-head.c (types_match): Handle non-types.
        * gimple-match-head.c (types_match): Likewise.
        * match.pd: Remove unnecessary TREE_TYPE for types_match.

--
Marc Glisse
Index: gcc/generic-match-head.c
===================================================================
--- gcc/generic-match-head.c    (revision 223194)
+++ gcc/generic-match-head.c    (working copy)
@@ -76,6 +76,11 @@
 static inline bool
 types_match (tree t1, tree t2)
 {
+  if (!TYPE_P (t1))
+    t1 = TREE_TYPE (t1);
+  if (!TYPE_P (t2))
+    t2 = TREE_TYPE (t2);
+
   return TYPE_MAIN_VARIANT (t1) == TYPE_MAIN_VARIANT (t2);
 }
 
Index: gcc/gimple-match-head.c
===================================================================
--- gcc/gimple-match-head.c     (revision 223194)
+++ gcc/gimple-match-head.c     (working copy)
@@ -867,6 +867,11 @@
 static inline bool
 types_match (tree t1, tree t2)
 {
+  if (!TYPE_P (t1))
+    t1 = TREE_TYPE (t1);
+  if (!TYPE_P (t2))
+    t2 = TREE_TYPE (t2);
+
   return types_compatible_p (t1, t2);
 }
 
Index: gcc/match.pd
===================================================================
--- gcc/match.pd        (revision 223194)
+++ gcc/match.pd        (working copy)
@@ -289,7 +289,7 @@
   (if (((TREE_CODE (@1) == INTEGER_CST
         && INTEGRAL_TYPE_P (TREE_TYPE (@0))
         && int_fits_type_p (@1, TREE_TYPE (@0)))
-       || types_match (TREE_TYPE (@0), TREE_TYPE (@1)))
+       || types_match (@0, @1))
        /* ???  This transform conflicts with fold-const.c doing
          Convert (T)(x & c) into (T)x & (T)c, if c is an integer
          constants (if x has signed type, the sign bit cannot be set
@@ -948,7 +948,7 @@
 /* Unordered tests if either argument is a NaN.  */
 (simplify
  (bit_ior (unordered @0 @0) (unordered @1 @1))
- (if (types_match (TREE_TYPE (@0), TREE_TYPE (@1)))
+ (if (types_match (@0, @1))
   (unordered @0 @1)))
 (simplify
  (bit_ior:c (unordered @0 @0) (unordered:c@2 @0 @1))
@@ -1068,8 +1068,8 @@
         && TYPE_PRECISION (type) == GET_MODE_PRECISION (TYPE_MODE (type))
         /* The inner conversion must be a widening conversion.  */
         && TYPE_PRECISION (TREE_TYPE (@2)) > TYPE_PRECISION (TREE_TYPE (@0))
-        && types_match (TREE_TYPE (@0), TREE_TYPE (@1))
-        && types_match (TREE_TYPE (@0), type)
+        && types_match (@0, @1)
+        && types_match (@0, type)
         && single_use (@4))
       (if (TYPE_OVERFLOW_WRAPS (TREE_TYPE (@0)))
        (convert (op @0 @1)))
@@ -1099,7 +1099,7 @@
         && TYPE_PRECISION (type) == GET_MODE_PRECISION (TYPE_MODE (type))
         /* The inner conversion must be a widening conversion.  */
         && TYPE_PRECISION (TREE_TYPE (@2)) > TYPE_PRECISION (TREE_TYPE (@0))
-        && types_match (TREE_TYPE (@0), TREE_TYPE (@1))
+        && types_match (@0, @1)
         && (tree_int_cst_min_precision (@4, UNSIGNED)
             <= TYPE_PRECISION (TREE_TYPE (@0)))
         && single_use (@5))

Reply via email to