[cfe-commits] Alignment of return from __builtin_alloca

Jakob Stoklund Olesen stoklund at 2pi.dk
Fri Jun 8 11:07:43 PDT 2012

On Jun 7, 2012, at 5:52 PM, Chandler Carruth <chandlerc at google.com> wrote:

> On Thu, Jun 7, 2012 at 5:22 PM, Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:
> On Jun 7, 2012, at 4:33 PM, Chandler Carruth <chandlerc at google.com> wrote:
>> 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).
> Realigning the stack requires the function to have a frame pointer, so frame pointer elimination is no longer possible. If you  have dynamically sized allocas, a reserved base pointer register is also necessary.
> Yes, but we don't need to re-align the stack AFAICT. We can just alloca some padding, and and off the low bits of the pointer. We still need the base pointer register in order to handle the dynamically sized alloca, but the stack can be at any alignment it pleases. Maybe I'm missing something?

No, that could work. A hyper-aligned dynamically sized alloca shouldn't need to trigger stack realignment in the prolog. We can simply go:

  subq %Size, %rsp
  andq -Align, %rsp
  movq %rsp, %Alloca

I don't know if codegen actually does this. It should.

We need a frame pointer, that is inevitable with dynamically sized allocas. The extra base pointer is only required with dynamically sized allocas AND hyper-aligned fixed-size stack objects.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120608/f55fad60/attachment.html>

More information about the cfe-commits mailing list