I have an array and a vector, and both of them hold the same data, like 0, 1, 2, 3, 4.
Then I use GEP to get the ptr of array,
%0 = getelementptr [5 x i32]* %arr, i32 0, i32 3
%1 = load i32* %0
%2 = bitcast <5 x i32>* %Vec to i32*
%3 = getelementptr i32* %2, i32 3
%4 = load i32* %3
You can use a
bitcast followed by a
gep to get the 4th item in a vector, but it's redundant - you can just use a
gep by itself, in exactly the same way as you have done with the array.
gep, you don't need to know anything about the memory layouts. In any case the memory for vectors is always laid out sequentially, as can be inferred from how
bitcast behaves between vectors and integers; and since you can't
bitcast arrays, their memory layout is immaterial.