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] [RFC] loop index promotion pass


On Wed, 20 May 2009, Richard Guenther wrote:

> > void
> > frob (unsigned char *in, unsigned char *out)
> > {
> > ?unsigned short h = 640, w = 480;
> > ?INDEX_TYPE i, j;
> >
> > ?for (i = 1; i < (h - 1); i++)
> > ? ?for (j = 1; j < (w - 1); j++)
> > ? ? ?{

> Yes, but that is as far as I remember from my attempt to analyze
> that testcase because it cannot prove that there is no overflow.
> Which is why I questioned the validity of your transformation ;)
> (I couldn't think of any way to prove non-wrapping for the above loop
> either...)

The limits are within the range of unsigned short, so an unsigned short 
variable, incremented by 1, cannot wrap in these loops.  (Because h and w 
are local variables, assignments through *out cannot modify them, but I 
don't think this observation is needed in this case.)

If you had a limit that could be 65536 or greater (with <; a limit <= 
65535 would also be a problem) then you would indeed have issues with 
wrapping; likewise with smaller limits and incrementing by more than 1.

-- 
Joseph S. Myers
joseph@codesourcery.com

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