------- Comment #3 from mikulas at artax dot karlin dot mff dot cuni dot cz  
2009-07-23 13:15 -------
What I would propose to fix this and bug #40667:

Each type has required alignment and preferred alignment. Enforced alignment is
what is needed to not crash and not violate the ABI, preferred alignment is the
alignment that has the best performance. For i386, all the types have enforced
alignment 4-byte, except 128-bit SSE type having enforced alignment 16-bytes
(the movdqa instruction crashes otherwise). Preferred alignment is 8 for double
and 8-byte vector types and 16 for long double and 16-byte vector types.

Now, if the function has some variable with the enforced alignment greater than
the ABI standard (4), the stack must be realigned. The ABI mandates 4-byte
alignment and the function may be called from anywhere. As an optimization, the
realign may be skipped if the function is static and it is proved to be called
only from functions with greater or equal enforced alignment and having stack
size aligned.

Each function aligns its stack size to -mpreferred-stack-boundary, which
basically means "if the stack was aligned before (the most common case),
performance will be good". But you can't rely on this for correctness, as in
the pathological cases, the stack doesn't have to be aligned.

As an optimization, if you can prove that the function will call only functions
manipulating types with preferred alignment at most X and X is lower than
-mpreferred-stack-boundary, you can lower stack alignment to X (so that if
there's a call graph of functions using only "double", you don't have to align
the stack on the default 16 bytes, 8 bytes is sufficient).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40838

Reply via email to