[cfe-commits] Alignment of return from __builtin_alloca

Joerg Sonnenberger joerg at britannica.bec.de
Fri Jun 8 07:40:49 PDT 2012

On Thu, Jun 07, 2012 at 04:33:14PM -0700, Chandler Carruth wrote:
> > At least we are getting to the point where LLVM handles all cases
> > correctly. Requiring larger than natural stack alignment for allocar
> > at the very least adds an additional AND to all functions using dynamic
> > allocas. That said, unlike malloc and the posix_memalign interface,
> > expecting anything but natural alignment
> > for memory returned by alloca seems to be a very strong assumption...
> >
> Regardless of how it seems, there is evidence that GCC at least does this,
> and it seems quite likely that a great deal of code expects equivalent
> alignment guarantees for 'alloca' and 'malloc'. I think it is a mistake to
> not provide such alignment. However, it does seem like this should be no
> more than an 'and' instruction in the worst case (we don't have known
> alignment of the stack).

Problem is that even plain malloc on most systems will not be good
enough for AVX either. I don't think forcing every alloca user to
consume unnecessary stack space is the right approach. Maybe it is
really time to introduce a new __builtin_alloca_aligned() builtin to
make it explicit what stack alignment is needed. It would make those
allocations a bit more expensive by adding the and, but not waste stack
space otherwise.


More information about the cfe-commits mailing list