Spilled variables using unaligned moves

Hi all,

It looks like vector spills don’t use aligned moves even though the stack is aligned. This seems like an optimization opportunity.

The attached replacement of fibonacci.cpp generates x86 code like this:

03A70010 push ebp

03A70011 mov ebp,esp

03A70013 and esp,0FFFFFFF0h

03A70019 sub esp,1A0h

03A7006C movups xmmword ptr [esp+180h],xmm7

03A70229 mulps xmm1,xmmword ptr [esp+180h]

03A70682 movups xmm0,xmmword ptr [esp+180h]

Note how stores and loads use unaligned moves while it could use aligned moves. It’s also interesting that the multiply does correctly assume the stack to be 16-byte aligned.

Is there something I’m doing wrong (again), or is this already known?

Thanks a lot,

Nicolas Capens

fibonacci.cpp (2.19 KB)

This is on Windows / Cygwin? I think the dynamic stack pointer re-alignment doesn’t happen until post- register allocation.

Assuming there aren’t other instructions between the prologue and the first movups that mess up esp (there shouldn’t), this is indeed a bug. Please file a bug and attach a bc file. Thanks.

Evan

Hi all,

It looks like vector spills don’t use aligned moves even though the stack is aligned. This seems like an optimization opportunity.

What target is this? Linux doesn’t have a 16-byte aligned stack.

-Chris

Hi all,

It looks like vector spills don’t use aligned moves even though the stack is aligned. This seems like an optimization opportunity.

What target is this? Linux doesn’t have a 16-byte aligned stack.

-Chris

It does now:) Anton (I think) implemented dynamic stack alignment for functions with XMM variables.
Note the “and esp” in the fragment below.

This is on Windows / MSVC++ 2005. I’ll file a bug.

Hi Evan,

Could you maybe point me to the source files where this issue might originate? I’d like to learn more about LLVM’s innards but so far I’ve just scraped the surface and I don’t know where what phase of instruction selection / register allocation / stack layout / etc. happens.

If I understand correctly this issue might be fixed by moving stack pointer alignment before register allocation? Is this something that might be reasonably straightforward or are there complicated dependencies involved?

Thanks again,

Nicolas

Hi Evan,

Could you maybe point me to the source files where this issue might originate? I’d like to learn more about LLVM’s innards but so far I’ve just scraped the surface and I don’t know where what phase of instruction selection / register allocation / stack layout / etc. happens.

It’s in X86InstrInfo.cpp. Please see my reply to Anton’s email for details.

If I understand correctly this issue might be fixed by moving stack pointer alignment before register allocation? Is this something that might be reasonably straightforward or are there complicated dependencies involved?

This is already being taken care of.

Evan