This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] New predicate covering NOP_EXPR and CONVERT_EXPR


On 12/2/05, Richard Kenner <kenner@vlsi1.ultra.nyu.edu> wrote:
>      Given that, in tree-ssa times, *most* of the compiler does not know
>      the difference between NOP_EXPR and CONVERT_EXPR and the exact
>      semantics are gone, I think such an audit will be a waste of time, and
>      in practice nobody will ever do it and we'll have to live with those
>      duplicate trees for more time.
>
> I agree and think it was true long before "tree-ssa" times.  It's been
> quite a while since anybody can articulate a difference between the
> handling of the two tree codes. This is probably even before I
> got involved in GCC, since I've always treated them as synonyms when
> analyzing trees.
>
>      Java has to be fixed (probably with a frontend-specific tree code),
>      and maybe also Ada.
>
> Ada does not.  It generates CONVERT_EXPR vs. NOP_EXPR in some attempt
> to preserve some old-semantic difference but always treats them the
> same when looking at trees.

So you agree to something along

Index: ada/utils.c
===================================================================
*** ada/utils.c (revision 107909)
--- ada/utils.c (working copy)
*************** convert (tree type, tree expr)
*** 2789,2797 ****
    /* If the input is a biased type, adjust first.  */
    if (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype))
      return convert (type, fold (build2 (PLUS_EXPR, TREE_TYPE (etype),
!                                       fold (build1 (NOP_EXPR,
!                                                     TREE_TYPE (etype),
!                                                     expr)),
                                        TYPE_MIN_VALUE (etype))));

    /* If the input is a justified modular type, we need to extract the actual
--- 2789,2796 ----
    /* If the input is a biased type, adjust first.  */
    if (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype))
      return convert (type, fold (build2 (PLUS_EXPR, TREE_TYPE (etype),
!                                       fold_convert (TREE_TYPE (etype),
!                                                     expr),
                                        TYPE_MIN_VALUE (etype))));

    /* If the input is a justified modular type, we need to extract the actual
*************** convert (tree type, tree expr)
*** 2940,2946 ****
    else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (etype)
           || (code == INTEGER_CST && ecode == INTEGER_CST
               && (type == TREE_TYPE (etype) || etype == TREE_TYPE (type))))
!     return fold (build1 (NOP_EXPR, type, expr));

    switch (code)
      {
--- 2939,2945 ----
    else if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (etype)
           || (code == INTEGER_CST && ecode == INTEGER_CST
               && (type == TREE_TYPE (etype) || etype == TREE_TYPE (type))))
!     return fold_convert (type, expr);

    switch (code)
      {
*************** convert (tree type, tree expr)
*** 2948,2954 ****
        return build1 (CONVERT_EXPR, type, expr);

      case BOOLEAN_TYPE:
!       return fold (build1 (NOP_EXPR, type,
gnat_truthvalue_conversion (expr)));

      case INTEGER_TYPE:
        if (TYPE_HAS_ACTUAL_BOUNDS_P (type)
--- 2947,2953 ----
        return build1 (CONVERT_EXPR, type, expr);

      case BOOLEAN_TYPE:
!       return fold_convert (type, gnat_truthvalue_conversion (expr));

      case INTEGER_TYPE:
        if (TYPE_HAS_ACTUAL_BOUNDS_P (type)
*************** convert (tree type, tree expr)
*** 2956,2965 ****
              || (ecode == RECORD_TYPE && TYPE_CONTAINS_TEMPLATE_P (etype))))
        return unchecked_convert (type, expr, false);
        else if (TYPE_BIASED_REPRESENTATION_P (type))
!       return fold (build1 (CONVERT_EXPR, type,
!                            fold (build2 (MINUS_EXPR, TREE_TYPE (type),
!                                          convert (TREE_TYPE (type), expr),
!                                          TYPE_MIN_VALUE (type)))));

        /* ... fall through ... */

--- 2955,2964 ----
              || (ecode == RECORD_TYPE && TYPE_CONTAINS_TEMPLATE_P (etype))))
        return unchecked_convert (type, expr, false);
        else if (TYPE_BIASED_REPRESENTATION_P (type))
!       return fold_convert (type,
!                            fold_build2 (MINUS_EXPR, TREE_TYPE (type),
!                                         convert (TREE_TYPE (type), expr),
!                                         TYPE_MIN_VALUE (type)));

        /* ... fall through ... */

?

Richard.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]