skaller <[EMAIL PROTECTED]> writes:

> On Mon, 2007-11-05 at 14:30 -0500, Ross Ridge wrote:
> 
> > One example of where it hurts on just about any platform is something
> > like this:
> > 
> >     void allocate(int **p, unsigned len);
> > 
> >     int *foo(unsigned len) {
> >             int *p;
> >             unsigned i;
> >             allocate(&p, len);
> >             for (i = 0; i < len; i++) 
> >                     p[i] = 1;
> >             return p;
> >     }
> > 
> > Without strict aliasing being enabled, the compiler can't assume that
> > that the assignment "p[i] = 1" won't change "p".  This results the value
> > of p being loaded on every loop iteration, instead of just once at the
> > start of the loop.  It also prevents GCC from vectorizing the loop.
> 
> 
> Now I'm a bit confused.. Ian wrote previously:
> 
> ".... Strict
> aliasing refers to one component of that analysis, really a final
> tie-breaker: using type information to distinguish loads and stores."
> 
> and 
> 
> "Strict aliasing only refers to loads and stores using pointers."
> 
> but the assignment here is of an int.

The assignment is indeed of an int, but it uses a pointer.  Strict
aliasing only refers to loads and stores which use pointers.  The
type-based alias analysis is done on the types to which those pointers
point.

Given two pointers, "T1* p1" and "T2* p2", type based alias analysis
(aka strict aliasing) lets us conclude that p1 and p2 point to
different memory if T1 and T2 are incompatible types with respect to
aliasing.  The rules for alias compatibility come straight from the C
standard.

Ian

Reply via email to