Hello, LLVM team! I faced a problem with passing structures by value on Windows (both x86 and x64). I tried to write simple { i32 i32 } Vector2D addition using IR builder (signature is Vector2D add(Vector2D a, Vector2D b)). x86 version worked fine, but on x64 function returned incorrect value. Some research showed, that { i16 i16 } addition also fails on x86, so I guess the problem is in passing structures as values. On x64 VC++ passes two { i32 i32 } structs in RCX and RDX respectively and reads result from RAX, but it seems LLVM reads parameters from ECX, EDX (first vector) and R8D, R9D (second vector). Currently, I can't figure out how to dump IR, but there is a link with disassembly shown by Visual Studio for generated functions: comparing { i32 i32 } add on 32-bit and 64-bit (first one works): http://pastebin.com/ijjCNWKJ Best regards, Milovanov Victor.
Hello> On x64 VC++ passes two { i32 i32 } structs in RCX and RDX respectively > and reads result from RAX, but it seems LLVM reads parameters from > ECX, EDX (first vector) and R8D, R9D (second vector).It's a frontend task to lower the code to follow the vendor ABI. In this case you have to bitcast your struct to i64 before passing as argument. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
> Is this documented somethere?This is the standard assumption. The calling convention can be complex enough and operate with the language-dependent definitions (e.g. "C" structs, etc.), thus frontend should lower such constructs as needed. For reference, normal x86-64 ABI has pretty complex rules wrt passing aggregates by value. You might want to look into llvm-gcc as an example. -- With best regards, Anton Korobeynikov Faculty of Mathematics and Mechanics, Saint Petersburg State University
---------- Forwarded message ---------- From: lost <lostfreeman at gmail.com> Date: 2010/6/5 Subject: Re: [LLVMdev] Passing structures by value on Windows To: Anton Korobeynikov <anton at korobeynikov.info> Ok, but how to bitcast structure? Documentation<http://llvm.org/docs/LangRef.html#i_bitcast>says that bitcast does not applicable to aggregate values. 2010/6/3 Anton Korobeynikov <anton at korobeynikov.info>:>> Is this documented somethere? > This is the standard assumption. The calling convention can be complex > enough and operate with the language-dependent definitions (e.g. "C" > structs, etc.), thus frontend should lower such constructs as needed. > > For reference, normal x86-64 ABI has pretty complex rules wrt passing > aggregates by value. You might want to look into llvm-gcc as an > example. > > -- > With best regards, Anton Korobeynikov > Faculty of Mathematics and Mechanics, Saint Petersburg State University >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20100606/e08dcd1a/attachment.html>
On Sat, Jun 5, 2010 at 2:16 PM, lost <lostfreeman at gmail.com> wrote:> > > ---------- Forwarded message ---------- > From: lost <lostfreeman at gmail.com> > Date: 2010/6/5 > Subject: Re: [LLVMdev] Passing structures by value on Windows > To: Anton Korobeynikov <anton at korobeynikov.info> > > > Ok, but how to bitcast structure? Documentation says that bitcast does not > applicable to aggregate values.Just make an alloca, store the members of the struct to it, cast it to an i64* (or whatever is appropriate), and load from it. -Eli