Type casting between scalable and fixed vectors

Hi everyone,

I would like to get some insights on how to type-cast a fixed vector type to a scalable vector type (for example RISCV vector type) and vice-versa in the Clang frontend.

For example, the type-casting between the following types

  1. typedef int32_t int32x4_t attribute ((vector_size(16))); // Vector of 4 32bit integer
  2. vint32m2_t; // RISCV vector type with LMUL=2 and 32bit integer elements

In the LLVM-IR the former gets translated to <4 x i32>, while the latter to <vscale x 4 x i32>.

I think a Clang ‘_builtin…’ can be used to achieve that, but I don’t know what the implementation of such casting operations would be like.


The IR form would be

call <vscale x 4 x i32> @llvm.experimental.vector.insert.nxv4i32.v4i32(<vscale x 4 x i32> poison, <4 x i32> %fixedvec, i32 0)


call <4 x i32> @llvm.experimental.vector.extract.v4i32.nxv4i32(<vscale x 4 x i32> %scalablevec, i32 0)

The fixed vector type should always be the “subvector”

Thanks a lot,

Just curious, how would you generate such instructions from Clang?

I don’t think we have any builtins to do it from clang right now.

Thanks for the clarification.