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] builtins.c, fold-const.c: Don't create type


> > Steven Bosscher 
> >> On Saturday 16 April 2005 16:36, Roger Sayle wrote:
> >> Converting "ptr + strlen(ptr)" into "ptr + (char*)strlen(ptr)" in
> >> builtins.c, just appears a little strange at first sight.
> >
> > Why does this appear strange?  It just makes the semantics of
> > pointer addition explicit.

It appears strange.  If I encounter this in the backend, the result
has to be loaded into a register and we probably loose an opportunity
to do an indexed load or store.

> Possibly because the subtraction of two pointers correctly yields an integer
> (pointer unit difference), not a pointer; and correspondingly a pointer
> plus/minus an integer (pointer unit difference), yields a pointer; where all
> other operations would seem to truly only apply to integers, not pointers.
> 
> Which may be helpful for targets which require/or-could-benefit-from the
> clearer distinct between mixed pointer/integer vs. integer only operations,
> not to mention more formally correct, and possibly easier to verify.
> 
> Thereby for example, if given some expression:
> 
>   float *element_ptr = (int *)array_base +
>                      + (sizeof(float) * (int)x_index)
>                      + (sizeof(float) * (int)y_index);
> 
> It may then be more consistently directly represented without requiring
> integers be cast to pointers, which prevents "(ptr)x + (ptr)y" ambiguously
> specifying either "(ptr)x + (int)y" or "(int)x + (ptr)y"; as it may be
> necessary for targets which represent pointers distinctly from integers to
> differentiate between to efficiently add an integer offset to a pointer;
> and would seem to correspondingly be required to enable type-correct folding
> optimization?

Yes.  I question whether the REG_POINTER flag is the best way to keep
track of pointers.  There are number of places where this flag gets
lost, the most obvious being in reload when a pseudo gets a hard
register.  It would be useful to know if a register contains pointer
post reload to do some peephole optimizations.

Dave
-- 
J. David Anglin                                  dave.anglin@nrc-cnrc.gc.ca
National Research Council of Canada              (613) 990-0752 (FAX: 952-6602)


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