[LLVMdev] Win64 bugs

Nicolas Capens nicolas at capens.net
Fri Jul 31 09:25:12 PDT 2009


Hi Peter,

The attached patch is a workaround for the XMM misalignment issue. Basically
it uses the fallback method of saving and restoring registers on the stack,
which does work correctly with alignment. If I recall correctly it also
doesn't save any registers unnecessarily, but I could be wrong about that.

Anyway, it's hack, but if all you want for now is to be able to work with
Win64 and use SSE this might offer a solution.

I wasn't aware of the second bug you're describing, but the one in your
latest e-mail about not being able to have more than four arguments I'm
experiencing as well. I'm afraid I haven't found any workaround for that
yet.

Cheers,

Nicolas


-----Original Message-----
From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On
Behalf Of Peter Shugalev
Sent: vrijdag 31 juli 2009 2:32
To: LLVMdev at cs.uiuc.edu
Subject: [LLVMdev] Win64 bugs

Hello!

I've just tried generating Win64 code and the result is not that good.

First of all, XMM registers are saved without reason to do so. Not only
this slows the performance but leads to random crashes too. XMMs are
stored to the stack with MOVAPS instruction which requires 16-byte
alignment which is not always the case. lli.exe (built in debug mode)
randomly crashes on some simple hello-world-alike tests due to misalignment.

Though the most problematic stuff is the lack of 'shadow zone' support
in Win64 ABI. Or maybe I haven't figured out how to turn this on. In
Win64 any function can treat 32 bytes of stack (RSP+08h..RSP+28h just
after the call instruction) as scratch data. VC++ compiler stores
arguments passed in registers there. In debug builds this doesn't get
optimized away.

Consider this C++ code:

#include <stdio.h>

int main () {
	for ( int i=0; i<5; i++ )
		printf ( "%d\n", 0 );
	return 0;
}

Compile it to llvm bytecode with -O0 flag. Then run debug build of
64-bit lli.exe (with -mtriple=x86_64-pc-windows argument). For me it
prints 0's forever.

The reason for this is printf function using shadow zone to store its
arguments. Second arguments goes to the stack at address RSP+10h and
overwrites 'i' variable always resetting it to zero.

Is anyone aware of the second bug? If I have some time I'll try to fix
it by myself but it'd be much better if someone hints me where to start
from.


-- 
Best Regards
Peter Shugalev
_______________________________________________
LLVM Developers mailing list
LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Win64workaround.patch
Type: application/octet-stream
Size: 899 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20090731/840878f1/attachment.obj>


More information about the llvm-dev mailing list