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


Hi,

> > Well, it's not particularly small, but you can tweak the testcase I
> > posted in my initial mail about the pass:
> >
> > ------------------------------------------------------------------------
> > #ifndef PROMOTE
> > #define INDEX_TYPE unsigned short
> > #else
> > #define INDEX_TYPE unsigned int
> > #endif
> >
> > 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++)
> > ? ? ?{
> > ? ? ? ?unsigned int c = (i * w) + j;
> > ? ? ? ?unsigned short b = (in[c - w -1]
> > ? ? ? ? ? ? ? ? ? ? ? ? ? + in[c - w]
> > ? ? ? ? ? ? ? ? ? ? ? ? ? + in[c - w + 1]
> > ? ? ? ? ? ? ? ? ? ? ? ? ? + in[c - 1]
> > ? ? ? ? ? ? ? ? ? ? ? ? ? + in[c]
> > ? ? ? ? ? ? ? ? ? ? ? ? ? + in[c + 1]
> > ? ? ? ? ? ? ? ? ? ? ? ? ? + in[c + w + 1]
> > ? ? ? ? ? ? ? ? ? ? ? ? ? + in[c + w]
> > ? ? ? ? ? ? ? ? ? ? ? ? ? + in[c + w - 1]);
> > ? ? ? ?*out++ = b;
> > ? ? ?}
> > }
> > ------------------------------------------------------------------------
> >
> > Compile with and without -DPROMOTE and compare dump files; you should
> > notice a lot of missed opportunities when compiling without -DPROMOTE.
> > At the very least, I know simple_iv returns false on the loop indices
> > above. ?analyze_scalar_evolution_in_loop does not return bare CHRECs for
> > the appropriate IVs; it returns upcasted ones, which confuse simple_iv.
> 
> 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...)

more precisely, the loops do not wrap (there is just no way how
for (; i < end; i++) loop could wrap).  However, the expression
(i * w) + j could wrap (and in fact, it will, assuming 16-bit short int),

Zdenek


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