# Convert a vector size

Hi,

Based on LLVM lang spec (http://llvm.org/docs/LangRef.html#i_bitcast) notes
I have understood ,that bitcast of vectors to vectors is OK,only if provided the vectors are of
the same size.Is it possible to convert a vectors from different size? For example a vector of 3 elements Int16Ty type to vector having one element of 64 bit Int64Ty ?

Thank you

Is it possible to convert a vectors from different size? For example
a vector of 3 elements Int16Ty type to vector having one element of
64 bit Int64Ty ?

Not with a bitcast. You'd probably use a shuffle followed by a bitcast for that:

%temp = shufflevector <3 x i16> %incoming, <3 x i16> undef, <4 x i32>
<i32 0, i32 1, i32 2, i32 undef>
%out = bitcast <4 x i16> %temp to i64

This creates a vector with its first elements the <3 x i16> and its
last element undefined, which *can* be bitcast.

Of course, the real question is why you want to do this: any solution
is going to have nasty issues around: endianness, legal types, more
stuff I haven't considered. Exactly how do you want the incoming <3 x
i16> to contribute to the i64? A slightly eccentric answer to that
question would make my code sequence horribly wrong.

Tim.

%temp = shufflevector <3 x i16> %incoming, <3 x i16> undef, <4 x i32>
<i32 0, i32 1, i32 2, i32 undef>
%out = bitcast <4 x i16> %temp to i64

I seem to have misread the destination type, you'd obviously want "<1
x i64>" instead of "i64" in everything I've written.

Tim.

I have a function that should work only with vector types having
element type as a power of 2.

So if I get total 48 bit vector I should force it to be rounded to
total 64 bit vector

Yakov

I checked the spec for shuffle vector inst -
http://llvm.org/docs/doxygen/html/classllvm_1_1ShuffleVectorInst.html
It is not clear to me 100%.
Can you please send me example?
Or say what should be a mask?