[cfe-commits] Alignment of return from __builtin_alloca

David Sehr sehr at google.com
Fri Jun 8 12:39:04 PDT 2012


To back up a couple of steps:
1) __builtin_alloca currently returns a value aligned less than the
stack frame (basically always 0mod4) for LLVM, which is incompatible
with the same builtin in gcc, which seems bad.
2) I'm proposing aligning __builtin_alloca return values to SuitableAlign.
3) SuitableAlign is no larger than the stack alignment (from
DescriptionString for most) for x86-32, x86-64, ARM, MSP430, and (I
think) PowerPC.  So a call to __builtin_alloca results in no need to
align stack frames on any of these.  Hence we're not talking about
"hyper-aligning" on any of these, and there is no need for a base
pointer.
4) Dynamically-sized alloca has always triggered the need for frame
pointers, and this proposal doesn't change anything related to that.

How about we proceed with aligning __builtin_alloca, and on targets
where SuitableAlign > stackAlignment, SuitableAlign is changed to be
<= stackAlignment?

David


On Fri, Jun 8, 2012 at 11:07 AM, Jakob Stoklund Olesen <stoklund at 2pi.dk> wrote:
>
> 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.
>
> /jakob
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list