LLVM has the bitcast
instruction which is often used to convert one type of pointer to another type of pointer - e.g., i32*
to i8*
.
So for example, if you want to access the 3rd byte of a 4-byte number, doing the following is perfectly legitimate:
%bytes = bitcast i32* %num to i8*
%third_byte = getelementptr i8* %bytes, i32 2
Just keep in mind the endianess when you do stuff like that.
And yes, you can use this technique to obtain pointers to specific locations in an array and store
and load
values from there, enabling you to do duplicate your entire example.