I am trying to use vectors inside structures with LLVM. I have the following C definition of my structure:
struct Foo
{
uint32_t len;
uint32_t data[32] __attribute__ ((aligned (16)));
};
and here is some LLVM code to add 42 to element number 3 of the field data:
%Foo = type { i32, <32 x i32> }
define void @process(%Foo*) {
_L1:
%data = getelementptr %Foo* %0, i32 0, i32 1
%vec = load <32 x i32>* %data
%x = extractelement <32 x i32> %vec, i32 3
%xNew = add i32 42, %x
%vecNew = insertelement <32 x i32> %vec, i32 %xNew, i32 3
store <32 x i32> %vecNew, <32 x i32>* %data
ret void
}
However, the output of llc looks as if the vectors should be aligned with 128 bytes, which seems wasteful as well as incorrect (AFAIK vectors should be aligned by 16 bytes):
.file "process.bc"
.text
.globl process
.align 16, 0x90
.type process,@function
process:
.Leh_func_begin0:
movdqa 128(%rdi), %xmm0
pextrd $3, %xmm0, %eax
addl $42, %eax
pinsrd $3, %eax, %xmm0
movdqa %xmm0, 128(%rdi)
ret
.Ltmp0:
.size process, .Ltmp0-process
.Leh_func_end0:
Of course, if I changed the definition of C to also align the data field with 128 bytes, it works, but spending 124 bytes (compared to 12 when using 16-byte alignment) just seems wrong. So what is going on here?