Add a type_has_mode_precision_p helper function
authorRichard Sandiford <richard.sandiford@linaro.org>
Mon, 21 Aug 2017 14:50:56 +0000 (14:50 +0000)
committerRichard Sandiford <rsandifo@gcc.gnu.org>
Mon, 21 Aug 2017 14:50:56 +0000 (14:50 +0000)
...to replace instances of:

    TYPE_PRECISION (t) == GET_MODE_PRECISION (TYPE_MODE (t))

These conditions would need to be rewritten with variable-sized
modes anyway.

2017-08-21  Richard Sandiford  <richard.sandiford@linaro.org>

gcc/
* tree.h (type_has_mode_precision_p): New function.
* convert.c (convert_to_integer_1): Use it.
* expr.c (expand_expr_real_2): Likewise.
(expand_expr_real_1): Likewise.
* fold-const.c (fold_single_bit_test_into_sign_test): Likewise.
* match.pd: Likewise.
* tree-ssa-forwprop.c (simplify_rotate): Likewise.
* tree-ssa-math-opts.c (convert_mult_to_fma): Likewise.
* tree-tailcall.c (process_assignment): Likewise.
* tree-vect-loop.c (vectorizable_reduction): Likewise.
* tree-vect-patterns.c (vect_recog_vector_vector_shift_pattern)
(vect_recog_mult_pattern, vect_recog_divmod_pattern): Likewise.
* tree-vect-stmts.c (vectorizable_conversion): Likewise.
(vectorizable_assignment): Likewise.
(vectorizable_shift): Likewise.
(vectorizable_operation): Likewise.
* tree-vrp.c (register_edge_assert_for_2): Likewise.

From-SVN: r251231

13 files changed:
gcc/ChangeLog
gcc/convert.c
gcc/expr.c
gcc/fold-const.c
gcc/match.pd
gcc/tree-ssa-forwprop.c
gcc/tree-ssa-math-opts.c
gcc/tree-tailcall.c
gcc/tree-vect-loop.c
gcc/tree-vect-patterns.c
gcc/tree-vect-stmts.c
gcc/tree-vrp.c
gcc/tree.h

index 824d95470f6f64f54348cbe1e9c1460d9a16efcb..e7d4e16df59766298d3051f5e23dc4063fb2005e 100644 (file)
@@ -1,3 +1,23 @@
+2017-08-21  Richard Sandiford  <richard.sandiford@linaro.org>
+
+       * tree.h (type_has_mode_precision_p): New function.
+       * convert.c (convert_to_integer_1): Use it.
+       * expr.c (expand_expr_real_2): Likewise.
+       (expand_expr_real_1): Likewise.
+       * fold-const.c (fold_single_bit_test_into_sign_test): Likewise.
+       * match.pd: Likewise.
+       * tree-ssa-forwprop.c (simplify_rotate): Likewise.
+       * tree-ssa-math-opts.c (convert_mult_to_fma): Likewise.
+       * tree-tailcall.c (process_assignment): Likewise.
+       * tree-vect-loop.c (vectorizable_reduction): Likewise.
+       * tree-vect-patterns.c (vect_recog_vector_vector_shift_pattern)
+       (vect_recog_mult_pattern, vect_recog_divmod_pattern): Likewise.
+       * tree-vect-stmts.c (vectorizable_conversion): Likewise.
+       (vectorizable_assignment): Likewise.
+       (vectorizable_shift): Likewise.
+       (vectorizable_operation): Likewise.
+       * tree-vrp.c (register_edge_assert_for_2): Likewise.
+
 2017-08-21  Wilco Dijkstra  <wdijkstr@arm.com>
 
        * match.pd: Add pow (C, x) simplification.
index b1a53afb81166c1e7b2dadec6888bfbd563fca15..22152cae79b1742033d7f869b2aaf027790f2e2f 100644 (file)
@@ -711,8 +711,7 @@ convert_to_integer_1 (tree type, tree expr, bool dofold)
             the signed-to-unsigned case the high-order bits have to
             be cleared.  */
          if (TYPE_UNSIGNED (type) != TYPE_UNSIGNED (TREE_TYPE (expr))
-             && (TYPE_PRECISION (TREE_TYPE (expr))
-                 != GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (expr)))))
+             && !type_has_mode_precision_p (TREE_TYPE (expr)))
            code = CONVERT_EXPR;
          else
            code = NOP_EXPR;
index b194866313d9d1751cc4d085225f8800cf48b385..7f34f5d12a7d0d52de94e7af27484f98140fba29 100644 (file)
@@ -8244,7 +8244,7 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
      result to be reduced to the precision of the bit-field type,
      which is narrower than that of the type's mode.  */
   reduce_bit_field = (INTEGRAL_TYPE_P (type)
-                     && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
+                     && !type_has_mode_precision_p (type));
 
   if (reduce_bit_field && modifier == EXPAND_STACK_PARM)
     target = 0;
@@ -9097,8 +9097,7 @@ expand_expr_real_2 (sepops ops, rtx target, machine_mode tmode,
     case LROTATE_EXPR:
     case RROTATE_EXPR:
       gcc_assert (VECTOR_MODE_P (TYPE_MODE (type))
-                 || (GET_MODE_PRECISION (TYPE_MODE (type))
-                     == TYPE_PRECISION (type)));
+                 || type_has_mode_precision_p (type));
       /* fall through */
 
     case LSHIFT_EXPR:
@@ -9671,7 +9670,7 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode,
      which is narrower than that of the type's mode.  */
   reduce_bit_field = (!ignore
                      && INTEGRAL_TYPE_P (type)
-                     && GET_MODE_PRECISION (mode) > TYPE_PRECISION (type));
+                     && !type_has_mode_precision_p (type));
 
   /* If we are going to ignore this result, we need only do something
      if there is a side-effect somewhere in the expression.  If there
index fef9b1a707a89b0b420f04e9dfdda6514510c226..de60f681514aacedb993d5c83c081354fa3b342b 100644 (file)
@@ -6638,8 +6638,7 @@ fold_single_bit_test_into_sign_test (location_t loc,
       if (arg00 != NULL_TREE
          /* This is only a win if casting to a signed type is cheap,
             i.e. when arg00's type is not a partial mode.  */
-         && TYPE_PRECISION (TREE_TYPE (arg00))
-            == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (arg00))))
+         && type_has_mode_precision_p (TREE_TYPE (arg00)))
        {
          tree stype = signed_type_for (TREE_TYPE (arg00));
          return fold_build2_loc (loc, code == EQ_EXPR ? GE_EXPR : LT_EXPR,
index a5552c5096de5100a882d52add6b620ba87c1f72..69dd8193cd0524d99fba8be8da8183230b8d621a 100644 (file)
@@ -992,7 +992,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
           || GET_MODE_CLASS (TYPE_MODE (type)) != MODE_INT
           /* Or if the precision of TO is not the same as the precision
              of its mode.  */
-          || TYPE_PRECISION (type) != GET_MODE_PRECISION (TYPE_MODE (type))))
+          || !type_has_mode_precision_p (type)))
    (convert (bitop @0 (convert @1))))))
 
 (for bitop (bit_and bit_ior)
@@ -1920,8 +1920,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        if (shift == LSHIFT_EXPR)
         zerobits = ((HOST_WIDE_INT_1U << shiftc) - 1);
        else if (shift == RSHIFT_EXPR
-               && (TYPE_PRECISION (shift_type)
-                   == GET_MODE_PRECISION (TYPE_MODE (shift_type))))
+               && type_has_mode_precision_p (shift_type))
         {
           prec = TYPE_PRECISION (TREE_TYPE (@3));
           tree arg00 = @0;
@@ -1931,8 +1930,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
               && TYPE_UNSIGNED (TREE_TYPE (@0)))
             {
               tree inner_type = TREE_TYPE (@0);
-              if ((TYPE_PRECISION (inner_type)
-                   == GET_MODE_PRECISION (TYPE_MODE (inner_type)))
+              if (type_has_mode_precision_p (inner_type)
                   && TYPE_PRECISION (inner_type) < prec)
                 {
                   prec = TYPE_PRECISION (inner_type);
@@ -3226,8 +3224,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
  (simplify
   (cmp (bit_and (convert?@2 @0) integer_pow2p@1) integer_zerop)
   (if (INTEGRAL_TYPE_P (TREE_TYPE (@0))
-       && (TYPE_PRECISION (TREE_TYPE (@0))
-          == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@0))))
+       && type_has_mode_precision_p (TREE_TYPE (@0))
        && element_precision (@2) >= element_precision (@0)
        && wi::only_sign_bit_p (@1, element_precision (@0)))
    (with { tree stype = signed_type_for (TREE_TYPE (@0)); }
@@ -4039,11 +4036,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
         /* The precision of the type of each operand must match the
            precision of the mode of each operand, similarly for the
            result.  */
-        && (TYPE_PRECISION (TREE_TYPE (@0))
-            == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@0))))
-        && (TYPE_PRECISION (TREE_TYPE (@1))
-            == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@1))))
-        && TYPE_PRECISION (type) == GET_MODE_PRECISION (TYPE_MODE (type))
+        && type_has_mode_precision_p (TREE_TYPE (@0))
+        && type_has_mode_precision_p (TREE_TYPE (@1))
+        && type_has_mode_precision_p (type)
         /* The inner conversion must be a widening conversion.  */
         && TYPE_PRECISION (TREE_TYPE (@2)) > TYPE_PRECISION (TREE_TYPE (@0))
         && types_match (@0, type)
@@ -4073,11 +4068,9 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
        /* The precision of the type of each operand must match the
          precision of the mode of each operand, similarly for the
          result.  */
-       && (TYPE_PRECISION (TREE_TYPE (@0))
-          == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@0))))
-       && (TYPE_PRECISION (TREE_TYPE (@1))
-          == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (@1))))
-       && TYPE_PRECISION (type) == GET_MODE_PRECISION (TYPE_MODE (type))
+       && type_has_mode_precision_p (TREE_TYPE (@0))
+       && type_has_mode_precision_p (TREE_TYPE (@1))
+       && type_has_mode_precision_p (type)
        /* The inner conversion must be a widening conversion.  */
        && TYPE_PRECISION (TREE_TYPE (@2)) > TYPE_PRECISION (TREE_TYPE (@0))
        && types_match (@0, @1)
index 5719b992eb81fe6ca9deea9dde07217975e879d0..529620672374d71445d0b7851747976182b1eade 100644 (file)
@@ -1529,7 +1529,7 @@ simplify_rotate (gimple_stmt_iterator *gsi)
   /* Only create rotates in complete modes.  Other cases are not
      expanded properly.  */
   if (!INTEGRAL_TYPE_P (rtype)
-      || TYPE_PRECISION (rtype) != GET_MODE_PRECISION (TYPE_MODE (rtype)))
+      || !type_has_mode_precision_p (rtype))
     return false;
 
   for (i = 0; i < 2; i++)
@@ -1609,8 +1609,7 @@ simplify_rotate (gimple_stmt_iterator *gsi)
              && INTEGRAL_TYPE_P (TREE_TYPE (cdef_arg1[i]))
              && TYPE_PRECISION (TREE_TYPE (cdef_arg1[i]))
                 > floor_log2 (TYPE_PRECISION (rtype))
-             && TYPE_PRECISION (TREE_TYPE (cdef_arg1[i]))
-                == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (cdef_arg1[i]))))
+             && type_has_mode_precision_p (TREE_TYPE (cdef_arg1[i])))
            {
              def_arg2_alt[i] = cdef_arg1[i];
              defcodefor_name (def_arg2_alt[i], &cdef_code[i],
@@ -1639,8 +1638,7 @@ simplify_rotate (gimple_stmt_iterator *gsi)
                && INTEGRAL_TYPE_P (TREE_TYPE (tem))
                && TYPE_PRECISION (TREE_TYPE (tem))
                 > floor_log2 (TYPE_PRECISION (rtype))
-               && TYPE_PRECISION (TREE_TYPE (tem))
-                == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (tem)))
+               && type_has_mode_precision_p (TREE_TYPE (tem))
                && (tem == def_arg2[1 - i]
                    || tem == def_arg2_alt[1 - i]))
              {
@@ -1667,8 +1665,7 @@ simplify_rotate (gimple_stmt_iterator *gsi)
                && INTEGRAL_TYPE_P (TREE_TYPE (tem))
                && TYPE_PRECISION (TREE_TYPE (tem))
                 > floor_log2 (TYPE_PRECISION (rtype))
-               && TYPE_PRECISION (TREE_TYPE (tem))
-                == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (tem))))
+               && type_has_mode_precision_p (TREE_TYPE (tem)))
              defcodefor_name (tem, &code, &tem, NULL);
 
            if (code == NEGATE_EXPR)
@@ -1683,8 +1680,7 @@ simplify_rotate (gimple_stmt_iterator *gsi)
                    && INTEGRAL_TYPE_P (TREE_TYPE (tem))
                    && TYPE_PRECISION (TREE_TYPE (tem))
                       > floor_log2 (TYPE_PRECISION (rtype))
-                   && TYPE_PRECISION (TREE_TYPE (tem))
-                      == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (tem)))
+                   && type_has_mode_precision_p (TREE_TYPE (tem))
                    && (tem == def_arg2[1 - i]
                        || tem == def_arg2_alt[1 - i]))
                  {
index 87940b6e00db0d34a472504cf70923d1d334eccb..0d75751f230723c5c1a4c80474171bf99e6d1338 100644 (file)
@@ -3564,8 +3564,7 @@ convert_mult_to_fma (gimple *mul_stmt, tree op1, tree op2)
 
   /* We don't want to do bitfield reduction ops.  */
   if (INTEGRAL_TYPE_P (type)
-      && (TYPE_PRECISION (type)
-         != GET_MODE_PRECISION (TYPE_MODE (type))))
+      && !type_has_mode_precision_p (type))
     return false;
 
   /* If the target doesn't support it, don't generate it.  We assume that
index e0497e596bb0cad7ad29faf9036c90a597222157..c4b8cee4d27738a663d08a09ad0af28b5218ed45 100644 (file)
@@ -289,8 +289,7 @@ process_assignment (gassign *stmt,
             type is smaller than mode's precision,
             reduce_to_bit_field_precision would generate additional code.  */
          if (INTEGRAL_TYPE_P (TREE_TYPE (dest))
-             && (GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (dest)))
-                 > TYPE_PRECISION (TREE_TYPE (dest))))
+             && !type_has_mode_precision_p (TREE_TYPE (dest)))
            return FAIL;
        }
 
index 906323b4d765421279b480551669c90422aa0dd4..59e41f69d9f556944dbc9c6f32de3df4dd625a14 100644 (file)
@@ -5848,8 +5848,7 @@ vectorizable_reduction (gimple *stmt, gimple_stmt_iterator *gsi,
     return false;
 
   /* Do not try to vectorize bit-precision reductions.  */
-  if ((TYPE_PRECISION (scalar_type)
-       != GET_MODE_PRECISION (TYPE_MODE (scalar_type))))
+  if (!type_has_mode_precision_p (scalar_type))
     return false;
 
   /* All uses but the last are expected to be defined in the loop.
index 17d10835038f31b9bef8fafd98074789baaa1554..877711a4f800bd26518cfce6aa1f061993e97e4c 100644 (file)
@@ -2067,8 +2067,7 @@ vect_recog_vector_vector_shift_pattern (vec<gimple *> *stmts,
   if (TREE_CODE (oprnd0) != SSA_NAME
       || TREE_CODE (oprnd1) != SSA_NAME
       || TYPE_MODE (TREE_TYPE (oprnd0)) == TYPE_MODE (TREE_TYPE (oprnd1))
-      || TYPE_PRECISION (TREE_TYPE (oprnd1))
-        != GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (oprnd1)))
+      || !type_has_mode_precision_p (TREE_TYPE (oprnd1))
       || TYPE_PRECISION (TREE_TYPE (lhs))
         != TYPE_PRECISION (TREE_TYPE (oprnd0)))
     return NULL;
@@ -2470,7 +2469,7 @@ vect_recog_mult_pattern (vec<gimple *> *stmts,
   if (TREE_CODE (oprnd0) != SSA_NAME
       || TREE_CODE (oprnd1) != INTEGER_CST
       || !INTEGRAL_TYPE_P (itype)
-      || TYPE_PRECISION (itype) != GET_MODE_PRECISION (TYPE_MODE (itype)))
+      || !type_has_mode_precision_p (itype))
     return NULL;
 
   vectype = get_vectype_for_scalar_type (itype);
@@ -2585,7 +2584,7 @@ vect_recog_divmod_pattern (vec<gimple *> *stmts,
   if (TREE_CODE (oprnd0) != SSA_NAME
       || TREE_CODE (oprnd1) != INTEGER_CST
       || TREE_CODE (itype) != INTEGER_TYPE
-      || TYPE_PRECISION (itype) != GET_MODE_PRECISION (TYPE_MODE (itype)))
+      || !type_has_mode_precision_p (itype))
     return NULL;
 
   vectype = get_vectype_for_scalar_type (itype);
index ee32c5671e292627eb845500acbae2dd66ac119d..0629c12a4bef8d1feca353220750d45fb8eddafb 100644 (file)
@@ -4098,11 +4098,9 @@ vectorizable_conversion (gimple *stmt, gimple_stmt_iterator *gsi,
 
   if (!VECTOR_BOOLEAN_TYPE_P (vectype_out)
       && ((INTEGRAL_TYPE_P (lhs_type)
-          && (TYPE_PRECISION (lhs_type)
-              != GET_MODE_PRECISION (TYPE_MODE (lhs_type))))
+          && !type_has_mode_precision_p (lhs_type))
          || (INTEGRAL_TYPE_P (rhs_type)
-             && (TYPE_PRECISION (rhs_type)
-                 != GET_MODE_PRECISION (TYPE_MODE (rhs_type))))))
+             && !type_has_mode_precision_p (rhs_type))))
     {
       if (dump_enabled_p ())
        dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
@@ -4696,10 +4694,8 @@ vectorizable_assignment (gimple *stmt, gimple_stmt_iterator *gsi,
   if ((CONVERT_EXPR_CODE_P (code)
        || code == VIEW_CONVERT_EXPR)
       && INTEGRAL_TYPE_P (TREE_TYPE (scalar_dest))
-      && ((TYPE_PRECISION (TREE_TYPE (scalar_dest))
-          != GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (scalar_dest))))
-         || ((TYPE_PRECISION (TREE_TYPE (op))
-              != GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (op))))))
+      && (!type_has_mode_precision_p (TREE_TYPE (scalar_dest))
+         || !type_has_mode_precision_p (TREE_TYPE (op)))
       /* But a conversion that does not change the bit-pattern is ok.  */
       && !((TYPE_PRECISION (TREE_TYPE (scalar_dest))
            > TYPE_PRECISION (TREE_TYPE (op)))
@@ -4875,8 +4871,7 @@ vectorizable_shift (gimple *stmt, gimple_stmt_iterator *gsi,
 
   scalar_dest = gimple_assign_lhs (stmt);
   vectype_out = STMT_VINFO_VECTYPE (stmt_info);
-  if (TYPE_PRECISION (TREE_TYPE (scalar_dest))
-      != GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (scalar_dest))))
+  if (!type_has_mode_precision_p (TREE_TYPE (scalar_dest)))
     {
       if (dump_enabled_p ())
         dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
@@ -5264,8 +5259,7 @@ vectorizable_operation (gimple *stmt, gimple_stmt_iterator *gsi,
   /* Most operations cannot handle bit-precision types without extra
      truncations.  */
   if (!VECTOR_BOOLEAN_TYPE_P (vectype_out)
-      && (TYPE_PRECISION (TREE_TYPE (scalar_dest))
-         != GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (scalar_dest))))
+      && !type_has_mode_precision_p (TREE_TYPE (scalar_dest))
       /* Exception are bitwise binary operations.  */
       && code != BIT_IOR_EXPR
       && code != BIT_XOR_EXPR
index e3735ff4023a0bed6e193a3af47442dffe274eb3..e1038a10b7a353de3b97a9e2d278abbb97f1d261 100644 (file)
@@ -5247,7 +5247,7 @@ register_edge_assert_for_2 (tree name, edge e,
              && tree_fits_uhwi_p (cst2)
              && INTEGRAL_TYPE_P (TREE_TYPE (name2))
              && IN_RANGE (tree_to_uhwi (cst2), 1, prec - 1)
-             && prec == GET_MODE_PRECISION (TYPE_MODE (TREE_TYPE (val))))
+             && type_has_mode_precision_p (TREE_TYPE (val)))
            {
              mask = wi::mask (tree_to_uhwi (cst2), false, prec);
              val2 = fold_binary (LSHIFT_EXPR, TREE_TYPE (val), val, cst2);
index 47899ce9c7eda57490813469d84e4c9a1616c698..c855a4ccb5d14cbd3662ae6e6d0c176bf33fb52c 100644 (file)
@@ -5414,4 +5414,13 @@ struct builtin_structptr_type
   const char *str;
 };
 extern const builtin_structptr_type builtin_structptr_types[6];
+
+/* Return true if type T has the same precision as its underlying mode.  */
+
+inline bool
+type_has_mode_precision_p (const_tree t)
+{
+  return TYPE_PRECISION (t) == GET_MODE_PRECISION (TYPE_MODE (t));
+}
+
 #endif  /* GCC_TREE_H  */