LLVM 13 added a short note on the bit representation of sub-byte elements to its documentation on vector types. I can follow everything it says except for the memory diagram for little endian which doesn't look right and disagrees with my experiments. I'm wondering if I'm misunderstanding something:
The same example for little endian:
%val = bitcast <4 x i4> <i4 1, i4 2, i4 3, i4 5> to i16 ; Bitcasting from a vector to an integral type can be seen as ; concatenating the values: ; %val now has the hexadecimal value 0x5321. store i16 %val, i16* %ptr ; In memory the content will be (8-bit addressing): ; ; [%ptr + 0]: 01010011 (0x53) ; [%ptr + 1]: 00100001 (0x21)
I agree that %val
has value 0x5321
, but shouldn't the memory layout be 0x21 0x53
(33 83
in decimal) instead of 0x53 0x21
? For example, bitcasting %val
to <2 x i8>
yields <i8 33, i8 83>
.
Yup, It was an error. Fixed in this commit: https://github.com/llvm/llvm-project/commit/9a53fe50f4355e6dfcd6af534cb394a62128963b