I have a packed struct <{<3 x i32>, i32}> type that LLVM determines to be 20 bytes. Is this the expected size for this type? I wrote a small example to illustrate: ; ModuleID = 'myexample.bc' target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128" target triple = "x86_64-pc-linux" %mytype = type <{<3 x i32>, i32}> define void @myexample(%mytype* %src, i64 %index, i32* %result) { entry: %vectoraddr = getelementptr %mytype* %src, i64 %index, i32 0 %vector = load <3 x i32>* %vectoraddr %tmp1 = extractelement <3 x i32> %vector, i32 2 store i32 %tmp1, i32* %result ret void } When I generate code (llc revision: 103084) i get: .Leh_func_begin0: # BB#0: # %entry leaq (%rsi,%rsi,4), %rax <- Multiply index by 5 pshufd $2, (%rdi,%rax,4), %xmm0 <- multiply again by 4 (element size 20) and add base pointer movd %xmm0, (%rdx) ret My guess was that the size should be 16 because I thought there should be no padding between elements. - Jan
Duncan Sands
2010-May-05 16:13 UTC
[LLVMdev] Size of packed struct type <{<3 x i32>, i32}>
On 05/05/10 17:29, Jan Sjodin wrote:> I have a packed struct<{<3 x i32>, i32}> type that LLVM determines to be 20 bytes. > Is this the expected size for this type?Yes. LLVM systematically allocates the same amount of memory for an object of a given type (here <3 x i32>), whether on the stack, in an array, in a struct, or a packed struct etc. The fact that the struct is packed is not relevant [*].> My guess was that the size should be 16 because I thought there should be no padding between elements.There is no padding between elements, there is padding inside an element! Ciao, Duncan. [*] This used to be different: when I first rationalized the notion of size in LLVM, I allocated less memory to types when they are in a packed struct. But I later reverted that, since having this exceptional case seemed too confusing.