[LLVMdev] Question on bit layout of array after bitcasting in llvm

Tim Northover t.p.northover at gmail.com
Tue Sep 24 02:17:35 PDT 2013


Hi,

> %0 = bitcast i16 %arg1 to <2 x i8>
> %2 = extractelement <2 x i8> %0, i32 1
>
> %arg1 in mem :
> 0000000011111111
> |---8bit---| |---8bit---|
>
> After bitcasting, %0 is an ptr to vector.

This isn't quite right. %0 is a real vector, not a pointer to one. If
you have hardware support for <2 x i8> then both elements would
probably be living in a single register ready for SIMD operations to
be performed on them.

It should be identical to if you'd stored %arg1 to some address as i16
and reloaded it as <2 x i8>.

> And what is %2 exactly? Is it the second element of vector(11111111) or,
> 00000000?

Being slightly obtuse: yes. The extractelement would normally be a
register-move rather than any kind of load (unless %0 had been spilled
due to pressure) and result in an i8 having one of those two values.

Exactly which of those it is depends slightly on whether your target
is big-endian or little-endian and exactly how it handles the
endianness of vectors. On a little-endian machine it would almost
always be 00000000 I think.

Cheers.

Tim.



More information about the llvm-dev mailing list