On 03/26/2015 05:28 PM, Steve Ellcey wrote:
The issue that I am trying to address is MSA registers on MIPS. The O32
MIPS ABI specifies an 8 byte aligned stack but MSA registers should be 16
byte aligned when spilled to memory. I don't see anyway to do this unless
we can force the stack to be 16 byte aligned.
Richard Henderson created a way of aligning local variables with an
alignment greater than the maximum stack alignment by using alloca
and creating an aligned pointer in to that space but that doesn't help
when reload or LRA is spilling a register to memory.
Right.
My thought was to use alloca, not to create space, but to move the stack
pointer to an aligned address so that subsequent spills using the stack
pointer would be to aligned addresses. As a test I created a simple gimple
pass that called __builtin_alloca at the beginning of each function just
to see if that was possible and it seemed to work fine. This seemed to be
much cleaner than when I tried to modify the stack pointer in expand_prologue.
When I did it there I had issues with tests that use setjmp/longjmp and there
seems to be a lot of bookkeeping needed to track registers and offsets when
working at that level. With this gimple pass that was all taken care of by
existing mechanisms.
But I don't see how using alloca ensures that you're going to have an
aligned spill slot. It can get you an aligned stack pointer, but that
doesn't ensure alignment of any particular spill slot IIRC.
Of course that test just did an alloca of 8 bytes, the actual code needs
to allocate a dynamic number of bytes depending on the current value of the
stack pointer.
__builtin_alloca(stack_pointer MOD desired_alignment)
So my first question is: Is there way to access/refrence the stack pointer
in a gimple pass? If so, how?
Not that I'm aware of. In general gimple isn't supposed to know about
things at that level. You might be able to argue that a stack pointer
is conceptually generic enough to provide access to it at gimple, but
it'd certainly require some discussion.
My second question is what do people think about this as a way to dymanically
align the stack? It seems a lot simpler and more target independent than
what x86 is doing.
My biggest worry is the large disconnect between where you're trying to
solve the problem (gimple) and where the problematic bits are
(LRA/reload). That seems like to be fragile in the long run.
jeff