This removes the TYPE_IS_SIZETYPE macro and all its uses (by
assuming it returns zero and applying trivial folding).  Sizes
and bitsizes can still be treat specially by means of knowing
what the values represent and by means of using helper functions
that assume you are dealing with "sizes" (in particular size_binop
and friends and bit_from_pos, byte_from_pos or pos_from_bit).

Bootstrapped and tested on x86_64-unknown-linux-gnu for all languages
including Ada with the patch optimizing bute_from_pos and pos_from_bit
with the following yet unvestigated regression:

                === gnat tests ===

Running target unix/
FAIL: gnat.dg/specs/alignment1.ads (test for excess errors)

Is the Ada change ok for trunk?  In any case I'll wait a bit for
discussion.

Thanks,
Richard.

2012-05-08  Richard Guenther  <rguent...@suse.de>

        ada/
        * gcc-interface/cuintp.c (UI_From_gnu): Remove TYPE_IS_SIZETYPE use.

        c-family/
        * c-common.c (c_sizeof_or_alignof_type): Remove assert and
        adjust commentary about TYPE_IS_SIZETYPE types.

        * tree.h (TYPE_IS_SIZETYPE): Remove.
        * fold-const.c (int_const_binop_1): Remove TYPE_IS_SIZETYPE use.
        (extract_muldiv_1): Likewise.
        * gimple.c (gtc_visit): Likewise.
        (gimple_types_compatible_p): Likewise.
        (iterative_hash_canonical_type): Likewise.
        (gimple_canonical_types_compatible_p): Likewise.
        * gimplify.c (gimplify_one_sizepos): Likewise.
        * print-tree.c (print_node): Likewise.
        * stor-layout.c (initialize_sizetypes): Do not set TYPE_IS_SIZETYPE.

Index: trunk/gcc/ada/gcc-interface/cuintp.c
===================================================================
*** trunk.orig/gcc/ada/gcc-interface/cuintp.c   2011-04-11 17:01:30.000000000 
+0200
--- trunk/gcc/ada/gcc-interface/cuintp.c        2012-05-07 16:43:43.497218058 
+0200
*************** UI_From_gnu (tree Input)
*** 178,186 ****
    if (host_integerp (Input, 0))
      return UI_From_Int (TREE_INT_CST_LOW (Input));
    else if (TREE_INT_CST_HIGH (Input) < 0
!          && TYPE_UNSIGNED (gnu_type)
!          && !(TREE_CODE (gnu_type) == INTEGER_TYPE
!               && TYPE_IS_SIZETYPE (gnu_type)))
      return No_Uint;
  #endif
  
--- 178,184 ----
    if (host_integerp (Input, 0))
      return UI_From_Int (TREE_INT_CST_LOW (Input));
    else if (TREE_INT_CST_HIGH (Input) < 0
!          && TYPE_UNSIGNED (gnu_type))
      return No_Uint;
  #endif
  
Index: trunk/gcc/c-family/c-common.c
===================================================================
*** trunk.orig/gcc/c-family/c-common.c  2012-05-07 10:48:20.000000000 +0200
--- trunk/gcc/c-family/c-common.c       2012-05-07 16:41:42.363222253 +0200
*************** c_sizeof_or_alignof_type (location_t loc
*** 4539,4550 ****
        value = size_int (TYPE_ALIGN_UNIT (type));
      }
  
!   /* VALUE will have an integer type with TYPE_IS_SIZETYPE set.
!      TYPE_IS_SIZETYPE means that certain things (like overflow) will
!      never happen.  However, this node should really have type
!      `size_t', which is just a typedef for an ordinary integer type.  */
    value = fold_convert_loc (loc, size_type_node, value);
-   gcc_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (value)));
  
    return value;
  }
--- 4539,4548 ----
        value = size_int (TYPE_ALIGN_UNIT (type));
      }
  
!   /* VALUE will have the middle-end integer type sizetype.
!      However, we should really return a value of type `size_t',
!      which is just a typedef for an ordinary integer type.  */
    value = fold_convert_loc (loc, size_type_node, value);
  
    return value;
  }
Index: trunk/gcc/fold-const.c
===================================================================
*** trunk.orig/gcc/fold-const.c 2012-05-04 10:44:44.000000000 +0200
--- trunk/gcc/fold-const.c      2012-05-07 16:59:27.728185367 +0200
*************** int_const_binop_1 (enum tree_code code,
*** 940,947 ****
    tree t;
    tree type = TREE_TYPE (arg1);
    bool uns = TYPE_UNSIGNED (type);
-   bool is_sizetype
-     = (TREE_CODE (type) == INTEGER_TYPE && TYPE_IS_SIZETYPE (type));
    bool overflow = false;
  
    op1 = tree_to_double_int (arg1);
--- 940,945 ----
*************** int_const_binop_1 (enum tree_code code,
*** 1077,1083 ****
      }
  
    t = force_fit_type_double (TREE_TYPE (arg1), res, overflowable,
!                            ((!uns || is_sizetype) && overflow)
                             | TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2));
  
    return t;
--- 1075,1081 ----
      }
  
    t = force_fit_type_double (TREE_TYPE (arg1), res, overflowable,
!                            (!uns && overflow)
                             | TREE_OVERFLOW (arg1) | TREE_OVERFLOW (arg2));
  
    return t;
*************** extract_muldiv_1 (tree t, tree c, enum t
*** 5639,5646 ****
          /* ... and has wrapping overflow, and its type is smaller
             than ctype, then we cannot pass through as widening.  */
          && ((TYPE_OVERFLOW_WRAPS (TREE_TYPE (op0))
-              && ! (TREE_CODE (TREE_TYPE (op0)) == INTEGER_TYPE
-                    && TYPE_IS_SIZETYPE (TREE_TYPE (op0)))
               && (TYPE_PRECISION (ctype)
                   > TYPE_PRECISION (TREE_TYPE (op0))))
              /* ... or this is a truncation (t is narrower than op0),
--- 5637,5642 ----
*************** extract_muldiv_1 (tree t, tree c, enum t
*** 5818,5824 ****
         the operation since it will change the result if the original
         computation overflowed.  */
        if (TYPE_UNSIGNED (ctype)
-         && ! (TREE_CODE (ctype) == INTEGER_TYPE && TYPE_IS_SIZETYPE (ctype))
          && ctype != type)
        break;
  
--- 5814,5819 ----
*************** extract_muldiv_1 (tree t, tree c, enum t
*** 5844,5857 ****
         (C * 8) % 4 since we know that's zero.  */
        if ((code == TRUNC_MOD_EXPR || code == CEIL_MOD_EXPR
           || code == FLOOR_MOD_EXPR || code == ROUND_MOD_EXPR)
!         /* If the multiplication can overflow we cannot optimize this.
!            ???  Until we can properly mark individual operations as
!            not overflowing we need to treat sizetype special here as
!            stor-layout relies on this opimization to make
!            DECL_FIELD_BIT_OFFSET always a constant.  */
!         && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (t))
!             || (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE
!                 && TYPE_IS_SIZETYPE (TREE_TYPE (t))))
          && TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
          && integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c)))
        {
--- 5839,5846 ----
         (C * 8) % 4 since we know that's zero.  */
        if ((code == TRUNC_MOD_EXPR || code == CEIL_MOD_EXPR
           || code == FLOOR_MOD_EXPR || code == ROUND_MOD_EXPR)
!         /* If the multiplication can overflow we cannot optimize this.  */
!         && TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (t))
          && TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST
          && integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c)))
        {
*************** extract_muldiv_1 (tree t, tree c, enum t
*** 5893,5908 ****
                     (tree_to_double_int (c),
                      TYPE_PRECISION (ctype), TYPE_UNSIGNED (ctype)),
                   false, &overflow_p);
!         overflow_p = (((!TYPE_UNSIGNED (ctype)
!                         || (TREE_CODE (ctype) == INTEGER_TYPE
!                             && TYPE_IS_SIZETYPE (ctype)))
!                        && overflow_p)
                        | TREE_OVERFLOW (c) | TREE_OVERFLOW (op1));
          if (!double_int_fits_to_tree_p (ctype, mul)
              && ((TYPE_UNSIGNED (ctype) && tcode != MULT_EXPR)
!                 || !TYPE_UNSIGNED (ctype)
!                 || (TREE_CODE (ctype) == INTEGER_TYPE
!                     && TYPE_IS_SIZETYPE (ctype))))
            overflow_p = 1;
          if (!overflow_p)
            return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
--- 5882,5892 ----
                     (tree_to_double_int (c),
                      TYPE_PRECISION (ctype), TYPE_UNSIGNED (ctype)),
                   false, &overflow_p);
!         overflow_p = ((!TYPE_UNSIGNED (ctype) && overflow_p)
                        | TREE_OVERFLOW (c) | TREE_OVERFLOW (op1));
          if (!double_int_fits_to_tree_p (ctype, mul)
              && ((TYPE_UNSIGNED (ctype) && tcode != MULT_EXPR)
!                 || !TYPE_UNSIGNED (ctype)))
            overflow_p = 1;
          if (!overflow_p)
            return fold_build2 (tcode, ctype, fold_convert (ctype, op0),
Index: trunk/gcc/gimple.c
===================================================================
*** trunk.orig/gcc/gimple.c     2012-05-03 10:21:42.000000000 +0200
--- trunk/gcc/gimple.c  2012-05-07 17:00:06.084184038 +0200
*************** gtc_visit (tree t1, tree t2,
*** 3326,3333 ****
        return false;
  
        if (TREE_CODE (t1) == INTEGER_TYPE
!         && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2)
!             || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)))
        return false;
  
        /* That's all we need to check for float and fixed-point types.  */
--- 3326,3332 ----
        return false;
  
        if (TREE_CODE (t1) == INTEGER_TYPE
!         && TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2))
        return false;
  
        /* That's all we need to check for float and fixed-point types.  */
*************** gimple_types_compatible_p (tree t1, tree
*** 3752,3759 ****
        return false;
  
        if (TREE_CODE (t1) == INTEGER_TYPE
!         && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2)
!             || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)))
        return false;
  
        /* That's all we need to check for float and fixed-point types.  */
--- 3751,3757 ----
        return false;
  
        if (TREE_CODE (t1) == INTEGER_TYPE
!         && TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2))
        return false;
  
        /* That's all we need to check for float and fixed-point types.  */
*************** iterative_hash_canonical_type (tree type
*** 4202,4211 ****
  
    /* For integer types hash the types min/max values and the string flag.  */
    if (TREE_CODE (type) == INTEGER_TYPE)
!     {
!       v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
!       v = iterative_hash_hashval_t (TYPE_IS_SIZETYPE (type), v);
!     }
  
    /* For array types hash their domain and the string flag.  */
    if (TREE_CODE (type) == ARRAY_TYPE
--- 4200,4206 ----
  
    /* For integer types hash the types min/max values and the string flag.  */
    if (TREE_CODE (type) == INTEGER_TYPE)
!     v = iterative_hash_hashval_t (TYPE_STRING_FLAG (type), v);
  
    /* For array types hash their domain and the string flag.  */
    if (TREE_CODE (type) == ARRAY_TYPE
*************** gimple_canonical_types_compatible_p (tre
*** 4421,4428 ****
        return false;
  
        if (TREE_CODE (t1) == INTEGER_TYPE
!         && (TYPE_IS_SIZETYPE (t1) != TYPE_IS_SIZETYPE (t2)
!             || TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2)))
        return false;
  
        /* For canonical type comparisons we do not want to build SCCs
--- 4416,4422 ----
        return false;
  
        if (TREE_CODE (t1) == INTEGER_TYPE
!         && TYPE_STRING_FLAG (t1) != TYPE_STRING_FLAG (t2))
        return false;
  
        /* For canonical type comparisons we do not want to build SCCs
Index: trunk/gcc/gimplify.c
===================================================================
*** trunk.orig/gcc/gimplify.c   2012-05-03 15:10:08.000000000 +0200
--- trunk/gcc/gimplify.c        2012-05-08 10:29:06.085004867 +0200
*************** gimplify_type_sizes (tree type, gimple_s
*** 8094,8100 ****
  void
  gimplify_one_sizepos (tree *expr_p, gimple_seq *stmt_p)
  {
!   tree type, expr = *expr_p;
  
    /* We don't do anything if the value isn't there, is constant, or contains
       A PLACEHOLDER_EXPR.  We also don't want to do anything if it's already
--- 8094,8100 ----
  void
  gimplify_one_sizepos (tree *expr_p, gimple_seq *stmt_p)
  {
!   tree expr = *expr_p;
  
    /* We don't do anything if the value isn't there, is constant, or contains
       A PLACEHOLDER_EXPR.  We also don't want to do anything if it's already
*************** gimplify_one_sizepos (tree *expr_p, gimp
*** 8106,8135 ****
        || CONTAINS_PLACEHOLDER_P (expr))
      return;
  
-   type = TREE_TYPE (expr);
    *expr_p = unshare_expr (expr);
  
    gimplify_expr (expr_p, stmt_p, NULL, is_gimple_val, fb_rvalue);
    expr = *expr_p;
- 
-   /* Verify that we've an exact type match with the original expression.
-      In particular, we do not wish to drop a "sizetype" in favour of a
-      type of similar dimensions.  We don't want to pollute the generic
-      type-stripping code with this knowledge because it doesn't matter
-      for the bulk of GENERIC/GIMPLE.  It only matters that TYPE_SIZE_UNIT
-      and friends retain their "sizetype-ness".  */
-   if (TREE_TYPE (expr) != type
-       && TREE_CODE (type) == INTEGER_TYPE
-       && TYPE_IS_SIZETYPE (type))
-     {
-       tree tmp;
-       gimple stmt;
- 
-       *expr_p = create_tmp_var (type, NULL);
-       tmp = build1 (NOP_EXPR, type, expr);
-       stmt = gimplify_assign (*expr_p, tmp, stmt_p);
-       gimple_set_location (stmt, EXPR_LOC_OR_HERE (expr));
-     }
  }
  
  /* Gimplify the body of statements of FNDECL and return a GIMPLE_BIND node
--- 8106,8115 ----
Index: trunk/gcc/print-tree.c
===================================================================
*** trunk.orig/gcc/print-tree.c 2012-03-16 10:54:05.000000000 +0100
--- trunk/gcc/print-tree.c      2012-05-07 17:00:33.200183099 +0200
*************** print_node (FILE *file, const char *pref
*** 611,619 ****
           || code == QUAL_UNION_TYPE)
          && TYPE_NO_FORCE_BLK (node))
        fputs (" no-force-blk", file);
-       else if (code == INTEGER_TYPE
-              && TYPE_IS_SIZETYPE (node))
-       fputs (" sizetype", file);
  
        if (TYPE_STRING_FLAG (node))
        fputs (" string-flag", file);
--- 611,616 ----
Index: trunk/gcc/stor-layout.c
===================================================================
*** trunk.orig/gcc/stor-layout.c        2012-05-02 13:22:39.000000000 +0200
--- trunk/gcc/stor-layout.c     2012-05-07 17:01:22.048181420 +0200
*************** initialize_sizetypes (void)
*** 2465,2476 ****
    TYPE_NAME (sizetype) = get_identifier ("sizetype");
    TYPE_PRECISION (sizetype) = precision;
    TYPE_UNSIGNED (sizetype) = 1;
-   TYPE_IS_SIZETYPE (sizetype) = 1;
    bitsizetype = make_node (INTEGER_TYPE);
    TYPE_NAME (bitsizetype) = get_identifier ("bitsizetype");
    TYPE_PRECISION (bitsizetype) = bprecision;
    TYPE_UNSIGNED (bitsizetype) = 1;
-   TYPE_IS_SIZETYPE (bitsizetype) = 1;
  
    /* Now layout both types manually.  */
    SET_TYPE_MODE (sizetype, smallest_mode_for_size (precision, MODE_INT));
--- 2465,2474 ----
*************** initialize_sizetypes (void)
*** 2491,2500 ****
    /* Create the signed variants of *sizetype.  */
    ssizetype = make_signed_type (TYPE_PRECISION (sizetype));
    TYPE_NAME (ssizetype) = get_identifier ("ssizetype");
-   TYPE_IS_SIZETYPE (ssizetype) = 1;
    sbitsizetype = make_signed_type (TYPE_PRECISION (bitsizetype));
    TYPE_NAME (sbitsizetype) = get_identifier ("sbitsizetype");
-   TYPE_IS_SIZETYPE (sbitsizetype) = 1;
  }
  
  /* TYPE is an integral type, i.e., an INTEGRAL_TYPE, ENUMERAL_TYPE
--- 2489,2496 ----
Index: trunk/gcc/tree.h
===================================================================
*** trunk.orig/gcc/tree.h       2012-05-04 10:44:44.000000000 +0200
--- trunk/gcc/tree.h    2012-05-07 17:01:10.308181815 +0200
*************** extern enum machine_mode vector_type_mod
*** 2251,2267 ****
  #define TYPE_NO_FORCE_BLK(NODE) \
    (TYPE_CHECK (NODE)->type_common.no_force_blk_flag)
  
- /* In an INTEGER_TYPE, it means the type represents a size.  We use
-    this both for validity checking and to permit optimizations that
-    are unsafe for other types.  Note that the C `size_t' type should
-    *not* have this flag set.  The `size_t' type is simply a typedef
-    for an ordinary integer type that happens to be the type of an
-    expression returned by `sizeof'; `size_t' has no special
-    properties.  Expressions whose type have TYPE_IS_SIZETYPE set are
-    always actual sizes.  */
- #define TYPE_IS_SIZETYPE(NODE) \
-   (INTEGER_TYPE_CHECK (NODE)->type_common.no_force_blk_flag)
- 
  /* Nonzero in a type considered volatile as a whole.  */
  #define TYPE_VOLATILE(NODE) (TYPE_CHECK (NODE)->base.volatile_flag)
  
--- 2251,2256 ----

Reply via email to