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]

[PATCH][1/n] Extend useless_type_conversion_p and friends


I have been working on this on the lto branch and will install
this piecewise on the trunk.  This is part 1 - add some more
useless conversions, particularly to pointers to incomplete
structs.  It also adds the obviously missing case of fixed-point
types.  It also cleans up make_vector_type to work like all
the other type generation functions - generate the main-variant
and then the qualified type.

Bootstrapped and tested on x86_64-unknown-linux-gnu, I'll install
this next week.

Thanks,
Richard.

2009-08-01  Richard Guenther  <rguenther@suse.de>

	* tree.c (make_vector_type): Build a main variant first,
	get the canonical one and then build the variant.
	* tree-ssa.c (useless_type_conversion_p_1): Handle
	fixed-point types.
	(useless_type_conversion_p): Conversions to pointers to
	incomplete record types are useless.

Index: gcc/tree.c
===================================================================
*** gcc/tree.c	(revision 150313)
--- gcc/tree.c	(working copy)
*************** make_vector_type (tree innertype, int nu
*** 8424,8444 ****
    tree t;
    hashval_t hashcode = 0;
  
-   /* Build a main variant, based on the main variant of the inner type, then
-      use it to build the variant we return.  */
-   if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
-       && TYPE_MAIN_VARIANT (innertype) != innertype)
-     return build_type_attribute_qual_variant (
- 	    make_vector_type (TYPE_MAIN_VARIANT (innertype), nunits, mode),
- 	    TYPE_ATTRIBUTES (innertype),
- 	    TYPE_QUALS (innertype));
- 
    t = make_node (VECTOR_TYPE);
    TREE_TYPE (t) = TYPE_MAIN_VARIANT (innertype);
    SET_TYPE_VECTOR_SUBPARTS (t, nunits);
    SET_TYPE_MODE (t, mode);
-   TYPE_READONLY (t) = TYPE_READONLY (innertype);
-   TYPE_VOLATILE (t) = TYPE_VOLATILE (innertype);
  
    if (TYPE_STRUCTURAL_EQUALITY_P (innertype))
      SET_TYPE_STRUCTURAL_EQUALITY (t);
--- 8424,8433 ----
*************** make_vector_type (tree innertype, int nu
*** 8468,8476 ****
    }
  
    hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode);
    hashcode = iterative_hash_host_wide_int (mode, hashcode);
!   hashcode = iterative_hash_object (TYPE_HASH (innertype), hashcode);
!   return type_hash_canon (hashcode, t);
  }
  
  static tree
--- 8457,8476 ----
    }
  
    hashcode = iterative_hash_host_wide_int (VECTOR_TYPE, hashcode);
+   hashcode = iterative_hash_host_wide_int (nunits, hashcode);
    hashcode = iterative_hash_host_wide_int (mode, hashcode);
!   hashcode = iterative_hash_object (TYPE_HASH (TREE_TYPE (t)), hashcode);
!   t = type_hash_canon (hashcode, t);
! 
!   /* We have built a main variant, based on the main variant of the
!      inner type. Use it to build the variant we return.  */
!   if ((TYPE_ATTRIBUTES (innertype) || TYPE_QUALS (innertype))
!       && TREE_TYPE (t) != innertype)
!     return build_type_attribute_qual_variant (t,
! 					      TYPE_ATTRIBUTES (innertype),
! 					      TYPE_QUALS (innertype));
! 
!   return t;
  }
  
  static tree
Index: gcc/tree-ssa.c
===================================================================
*** gcc/tree-ssa.c	(revision 150313)
--- gcc/tree-ssa.c	(working copy)
*************** useless_type_conversion_p_1 (tree outer_
*** 894,899 ****
--- 896,906 ----
  	   && SCALAR_FLOAT_TYPE_P (outer_type))
      return true;
  
+   /* Fixed point types with the same mode are compatible.  */
+   else if (FIXED_POINT_TYPE_P (inner_type)
+ 	   && FIXED_POINT_TYPE_P (outer_type))
+     return true;
+ 
    /* We need to take special care recursing to pointed-to types.  */
    else if (POINTER_TYPE_P (inner_type)
  	   && POINTER_TYPE_P (outer_type))
*************** useless_type_conversion_p_1 (tree outer_
*** 997,1008 ****
  bool
  useless_type_conversion_p (tree outer_type, tree inner_type)
  {
!   /* If the outer type is (void *), then the conversion is not
!      necessary.  We have to make sure to not apply this while
!      recursing though.  */
    if (POINTER_TYPE_P (inner_type)
        && POINTER_TYPE_P (outer_type)
!       && TREE_CODE (TREE_TYPE (outer_type)) == VOID_TYPE)
      return true;
  
    return useless_type_conversion_p_1 (outer_type, inner_type);
--- 1056,1072 ----
  bool
  useless_type_conversion_p (tree outer_type, tree inner_type)
  {
!   /* If the outer type is (void *) or a pointer to an incomplete record type,
!      then the conversion is not necessary.
!      We have to make sure to not apply this while recursing though.  */
    if (POINTER_TYPE_P (inner_type)
        && POINTER_TYPE_P (outer_type)
!       && (VOID_TYPE_P (TREE_TYPE (outer_type))
! 	  || (AGGREGATE_TYPE_P (TREE_TYPE (outer_type))
! 	      && TREE_CODE (TREE_TYPE (outer_type)) != ARRAY_TYPE
! 	      && (TREE_CODE (TREE_TYPE (outer_type))
! 		  == TREE_CODE (TREE_TYPE (inner_type)))
! 	      && TYPE_FIELDS (TREE_TYPE (outer_type)) == NULL_TREE)))
      return true;
  
    return useless_type_conversion_p_1 (outer_type, inner_type);


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