LLVMdev Digest, Vol 93, Issue 3

Subject: Re: [LLVMdev] Stack alignment on X86 AVX seems incorrect

vmovaps should not access stack if it is not aligned to 32

I’m not completely sure I understand your problem. Are you saying that
the generated code assumes 256bit alignment, your default stack
alignment is 128bit and LLVM doesn’t adjust it automatically?


Hey Joerg,

The faulty code can be found in function X86InstrInfo::storeRegToStackSlot(…) from /lib/Target/X86/X86InstrInfo.cpp.

bool isAligned = (RI.getStackAlignment() >= 16) || RI.canRealignStack(MF);

When creating the spill’s machine instruction, the spill slot is assumed to be aligned if the alignment is >= 16 bytes, which is not the case for AVX. AVX spills require 32 byte alignment to make use of aligned moves. The stack is not adjusted automatically.

For performance, the best fix is to align the frame to a 32-byte boundary, ensuring that the YMM spill slots are also on 32-byte boundaries. This, of course, breaks the ABI.