[VectorOps] Add lowering of vector.shuffle to LLVM IR
authorAart Bik <ajcbik@google.com>
Thu, 12 Dec 2019 22:11:27 +0000 (14:11 -0800)
committerA. Unique TensorFlower <gardener@tensorflow.org>
Thu, 12 Dec 2019 22:11:56 +0000 (14:11 -0800)
commit1c81adf362ec79750850dc5ecb0bf3e60399e54f
tree67355d032779f502620845e1d6bb5a44aa95bf0d
parent41a73ddce8923f506eaf6e8c5a61d32add5e4c06
[VectorOps] Add lowering of vector.shuffle to LLVM IR

For example, a shuffle

%1 = vector.shuffle %arg0, %arg1 [0 : i32, 1 : i32] : vector<2xf32>, vector<2xf32>

becomes a direct LLVM shuffle

0 = llvm.shufflevector %arg0, %arg1 [0 : i32, 1 : i32] : !llvm<"<2 x float>">, !llvm<"<2 x float>">

but

%1 = vector.shuffle %a, %b[1 : i32, 0 : i32, 2: i32] : vector<1x4xf32>, vector<2x4xf32>

becomes the more elaborate (note the index permutation that drives
argument selection for the extract operations)

%0 = llvm.mlir.undef : !llvm<"[3 x <4 x float>]">
%1 = llvm.extractvalue %arg1[0] : !llvm<"[2 x <4 x float>]">
%2 = llvm.insertvalue %1, %0[0] : !llvm<"[3 x <4 x float>]">
%3 = llvm.extractvalue %arg0[0] : !llvm<"[1 x <4 x float>]">
%4 = llvm.insertvalue %3, %2[1] : !llvm<"[3 x <4 x float>]">
%5 = llvm.extractvalue %arg1[1] : !llvm<"[2 x <4 x float>]">
%6 = llvm.insertvalue %5, %4[2] : !llvm<"[3 x <4 x float>]">

PiperOrigin-RevId: 285268164
mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir