[LLVMdev] Stack alignment on X86 AVX seems incorrect

Joerg Sonnenberger joerg at britannica.bec.de
Thu Mar 1 19:37:55 PST 2012


On Fri, Mar 02, 2012 at 12:18:19AM -0300, Bruno Cardoso Lopes wrote:
> Hi Elena,
> 
> On Thu, Mar 1, 2012 at 8:28 PM, Demikhovsky, Elena
> <elena.demikhovsky at intel.com> wrote:
> > Even if you explicitly specify –stack-alignment=16 the aligned movs are
> > still generated.
> >
> > It is not an issue related to ABI.
> 
> This looks like PR10841, explanation and the way to solve it:
> http://llvm.org/bugs/show_bug.cgi?id=10841

I was looking at this again today. What about the following approach:

(1) Change AllocaInst to compute the isStaticAlloca once and remember
    it.

(2) Check all functions for
  (a) static allocations with an alignment larger than the default stack
      alignemnt
  (b) dynamic alloca

(3) If (a) is present and not (b), use the frame pointer to address
    arguments and the stack pointer to address local variables.

    If (b) is present and not (a), use the frame pointer to address
    arguments and local variables. Realign the stack pointer to the
    largest alignment needed for dynamic alloca.

    If (a) and (b) are present, adjust the isStatic attribute of all
    allocas with alignment larger than the default stack alignment.
    Deal with the rest like the case before.

At least for 32bit x86 reserving another register as alternative frame
pointer is very heavy. The above would allow normal spill logic to
decide when to keep a reference in register and when not. It also reuses
existing functionality as much as possible.

Joerg



More information about the llvm-dev mailing list