Patchwork [tree-ssa] conversion between dissimilar-sized pointers is not useless

login
register
mail settings
Submitter DJ Delorie
Date March 9, 2011, 3:44 a.m.
Message ID <201103090344.p293iXWw004901@greed.delorie.com>
Download mbox | patch
Permalink /patch/86056/
State New
Headers show

Comments

DJ Delorie - March 9, 2011, 3:44 a.m.
Affects tpf, mips64, and m32c.  Hand-checked tpf by inspection, m32c
tests running now.  Look OK so far?

	* tree-ssa.c (useless_type_conversion_p): Conversions between
	pointers of different modes are not useless.
Richard Guenther - March 9, 2011, 9:51 a.m.
On Wed, Mar 9, 2011 at 4:44 AM, DJ Delorie <dj@redhat.com> wrote:
>
> Affects tpf, mips64, and m32c.  Hand-checked tpf by inspection, m32c
> tests running now.  Look OK so far?
>
>        * tree-ssa.c (useless_type_conversion_p): Conversions between
>        pointers of different modes are not useless.
>
> Index: tree-ssa.c
> ===================================================================
> --- tree-ssa.c  (revision 170807)
> +++ tree-ssa.c  (working copy)
> @@ -1227,6 +1227,14 @@
>          != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
>        return false;
>
> +      /* Some targets support multiple pointer sizes, others support
> +        partial-int modes for some pointer types.  Do not lose casts
> +        between these.  */
> +      if (TYPE_SIZE (inner_type) != TYPE_SIZE (outer_type)
> +         || (GET_MODE_CLASS (TYPE_MODE (inner_type))
> +             != GET_MODE_CLASS (TYPE_MODE (outer_type))))
> +       return false;

Why not simply

  if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type))
    return false;

?  This only breaks because of the VOID_TYPE_P check below,
right?

Richard.

>       /* Do not lose casts to restrict qualified pointers.  */
>       if ((TYPE_RESTRICT (outer_type)
>           != TYPE_RESTRICT (inner_type))
>
Richard Guenther - March 9, 2011, 9:52 a.m.
On Wed, Mar 9, 2011 at 10:51 AM, Richard Guenther
<richard.guenther@gmail.com> wrote:
> On Wed, Mar 9, 2011 at 4:44 AM, DJ Delorie <dj@redhat.com> wrote:
>>
>> Affects tpf, mips64, and m32c.  Hand-checked tpf by inspection, m32c
>> tests running now.  Look OK so far?
>>
>>        * tree-ssa.c (useless_type_conversion_p): Conversions between
>>        pointers of different modes are not useless.
>>
>> Index: tree-ssa.c
>> ===================================================================
>> --- tree-ssa.c  (revision 170807)
>> +++ tree-ssa.c  (working copy)
>> @@ -1227,6 +1227,14 @@
>>          != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
>>        return false;
>>
>> +      /* Some targets support multiple pointer sizes, others support
>> +        partial-int modes for some pointer types.  Do not lose casts
>> +        between these.  */
>> +      if (TYPE_SIZE (inner_type) != TYPE_SIZE (outer_type)
>> +         || (GET_MODE_CLASS (TYPE_MODE (inner_type))
>> +             != GET_MODE_CLASS (TYPE_MODE (outer_type))))
>> +       return false;
>
> Why not simply
>
>  if (TYPE_MODE (inner_type) != TYPE_MODE (outer_type))
>    return false;
>
> ?  This only breaks because of the VOID_TYPE_P check below,
> right?

Oh, btw - I expect that a lot more code will be confused about different
size pointer types, notably IVOPTs and the POINTER_PLUS_EXPR
restriction of only accepting sizetype offsets.

Richard.

Patch

Index: tree-ssa.c
===================================================================
--- tree-ssa.c	(revision 170807)
+++ tree-ssa.c	(working copy)
@@ -1227,6 +1227,14 @@ 
 	  != TYPE_ADDR_SPACE (TREE_TYPE (inner_type)))
 	return false;
 
+      /* Some targets support multiple pointer sizes, others support
+	 partial-int modes for some pointer types.  Do not lose casts
+	 between these.  */
+      if (TYPE_SIZE (inner_type) != TYPE_SIZE (outer_type)
+	  || (GET_MODE_CLASS (TYPE_MODE (inner_type))
+	      != GET_MODE_CLASS (TYPE_MODE (outer_type))))
+	return false;
+
       /* Do not lose casts to restrict qualified pointers.  */
       if ((TYPE_RESTRICT (outer_type)
 	   != TYPE_RESTRICT (inner_type))