Minimum target alignment for a datatype

Chris Lattner CLATTNER@apple.com
Fri Jul 22 21:15:00 GMT 2005


On Jul 22, 2005, at 1:14 PM, Richard Henderson wrote:

> On Fri, Jul 22, 2005 at 11:30:40AM -0700, Chris Lattner wrote:
>
>> Understood.  I'm just looking for the minimum type alignment without
>> user alignment.  It appears that this is impossible to get from the
>> targets, due to the way the targets can override type alignments in
>> (almost completely) general ways.  Is this true?
>>
>
> For !STRICT_ALIGNMENT, there is no interesting minimum.

After talking to people on IRC about this, some have mentioned that  
this may be a bug in the darwin-ppc target description.  Consider  
this (untested) code:

struct X {
    int A; double D;
};

void test(double *P) {
    // alignof(double) == 8, but the dynamic alignment of P is only 4.
    memset(P, 0, sizeof(double));
}

void problem() {    // This could be in another translation unit.
   struct X a;    // 4 byte alignment.
   test(&a.D);
}

The problem in this case is that the optimizer cannot assume that a  
T* is at least as aligned as TYPE_ALIGN(T) in this case.  People have  
pointed out that the alignment of double could be represented as 4,  
and increased when necessary (instead of represented as 8 and reduced  
when needed).

I have no idea whether this is right or wrong, but as Dale recently  
noticed, TYPE_ALIGN leaks out to user code through __alignof__, so  
changing it may not be practical.

Anyone have any thoughts or opinions?  This may have impact on a  
number of things, including any pointer alignment analysis.

-Chris




More information about the Gcc mailing list