[LLVMdev] structure member alignment for vector types

Eli Friedman eli.friedman at gmail.com
Sun Aug 18 18:17:25 PDT 2013


On Sun, Aug 18, 2013 at 3:37 PM, Nicholas Chapman
<admin at indigorenderer.com>wrote:

> Hi All,
> I have run into an issue when writing some LLVM code to read from a C++
> structure.
> The structure as defined in LLVM is { { <4 x float> }, { <4 x float> }, {
> <16 x float> }, { <4 x float> }, { <4 x float> } }.
> On Windows, with Visual Studio 2012, the vector members of the structure
> are packed tightly together.
> However, LLVM seems to be leaving 32 bytes between the second 4 x float
> vector and the 16 x float vector.  This is maybe because the 16 x float
> vector
> is getting aligned to 64 bytes inside the structure.
> The result is that the JIT'd LLVM code is reading from the wrong memory
> location, resulting in errors.
>
> Is this known behaviour of LLVM?  Presumably the structure layout is
> supposed to match that of the platform / Visual Studio?
> Why would it leave a 32 byte gap anyway?
>
> I'm using LLVM 3.2, on Windows 64 bit.
>
>
>
The natural alignment of a 32-byte vector is 32 bytes, so LLVM will add
padding as appropriate.

It's possible the data layout string for Windows targets is incorrect,
though.  Take a look at the data layout string in your IR and
X86TargetMachine.cpp (which overrides the string specified in the IR for
code generation, IIRC).

Alternatively, you can use a packed struct and add the padding by hand.

-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130818/4587ddef/attachment.html>


More information about the llvm-dev mailing list