splat instruction

Hi!

as highlevel languages (like opencl) support operations with a vector
on one side and a scalar on the other side (e.g. vector * scalar) it would
be convenient if llvm ir would have a splat instruction that takes
a scalar and produces a vector with all elements filled with the scalar.

i assume that i'm not the first one who has this idea so what was
the reason not to include such an instruction?

a splat instruction would also be handy to scalarize the code as much
as possible before outputting it again to a highlevel language.

-jochen

Hi Jochen,

this can be modeled like this:

%single = insertelement <1 x i32> undef, i32 %scalar, i32 0
%vector = shufflevector <1 x i32> %single, <1 x i32> undef,
                           <8 x i32> zeroinitializer

As any new instruction needs special treatment all over LLVM, people in general tend to avoid new special-case instructions if the same computation can easily be expressed with existing instructions.

Cheers
Tobi