Joerg Sonnenberger
2012-Mar-02 03:37 UTC
[LLVMdev] Stack alignment on X86 AVX seems incorrect
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=10841I 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
Anton Korobeynikov
2012-Mar-02 11:57 UTC
[LLVMdev] Stack alignment on X86 AVX seems incorrect
Joerg,> 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.It does not seem to be enough. Even is there are *no* allocas in the function the stack realignment might still be necessary, for example due to spill of vector register. So, we'll need to decide very late whether we'll need realignment or not. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
On Mar 2, 2012, at 3:57 AM, Anton Korobeynikov <anton at korobeynikov.info> wrote:> Joerg, > >> 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. > It does not seem to be enough. Even is there are *no* allocas in the > function the stack realignment might still be necessary, for example > due to spill of vector register. > So, we'll need to decide very late whether we'll need realignment or not. >Absolutely right. Which means it will need to be a heuristic, because regalloc needs to know early whether to reserve the register or not. There's already some of this sort of thing for whether the frame pointer is reserved or not. The ARM backend already does a fair bit of this (see hasBasePointer() and friends) and may be useful as an example of what's involved. -Jim> -- > With best regards, Anton Korobeynikov > Faculty of Mathematics and Mechanics, Saint Petersburg State University > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
Maybe Matching Threads
- [LLVMdev] Stack alignment on X86 AVX seems incorrect
- [LLVMdev] Stack alignment on X86 AVX seems incorrect
- [LLVMdev] Stack alignment on X86 AVX seems incorrect
- [LLVMdev] Stack alignment on X86 AVX seems incorrect
- [LLVMdev] Stack alignment on X86 AVX seems incorrect