[LLVMdev] Stack alignment on X86 AVX seems incorrect

Cameron McInally cameron.mcinally at nyu.edu
Thu Mar 1 14:30:40 PST 2012


On Thu, Mar 1, 2012 at 4:29 PM, Evandro Menezes <emenezes at codeaurora.org>wrote:
...

> Aligning the stack to 32 bytes when there are auto AVX vector variables
> present shouldn't necessarily break the x86-64 ABI, as long as smaller auto
> variables remain properly aligned.  A similar approach was taken for i386
> in GCC in order to support SSE vectors.
>
> Perhaps you could elaborate where the ABI was violated when your patch is
> applied.
>

Sorry, I confused myself. This was worked out about a year ago, so it's not
in my cache.

You're right. In my last email I wrote "align the stack", when I should
have written "align the frame when variable sized objects are in play".
Take main(...) for example, with a few alloca's. If one would like to spill
AVX regs with aligned moves, one must align the frame to 32 bytes to ensure
that the spill slots are aligned correctly, since spill slots are based off
of the frame pointer.

The x86-64 ABI lays out the stack frame as...

...
16(%rbp)  mem arg[0]
8(%rbp)    return address
0(%rbp)    previous %rbp
-8(%rbp)   stack

My patch breaks the ABI since the ABI requires the return address to be
found at 8(%rbp) and mem arg[0] at 16(%rbp). Unfortunately, to align the
frame at runtime, it's sometimes required to insert padding in between the
two.

I'll ask for my company's permission to share my implementation. Until
then, I'll have to bite my tongue.

-Cameron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120301/e9a0be25/attachment.html>


More information about the llvm-dev mailing list