diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp --- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -618,7 +618,7 @@ // FIXME: vaarg // FIXME: extractelement // FIXME: insertelement - // FIXME: shufflevector + // ShuffleVector is handled specially. // InsertValue is handled specially. // ExtractValue is handled specially. // FIXME: landingpad @@ -1066,6 +1066,20 @@ instMap[inst] = b.create(loc, type, aggOperand, indices); return success(); } + case llvm::Instruction::ShuffleVector: { + auto *svInst = cast(inst); + Value vec1 = processValue(svInst->getOperand(0)); + if (!vec1) + return failure(); + Value vec2 = processValue(svInst->getOperand(1)); + if (!vec2) + return failure(); + + ArrayAttr mask = b.getI32ArrayAttr(svInst->getShuffleMask()); + + instMap[inst] = b.create(loc, vec1, vec2, mask); + return success(); + } } } diff --git a/mlir/test/Target/LLVMIR/Import/basic.ll b/mlir/test/Target/LLVMIR/Import/basic.ll --- a/mlir/test/Target/LLVMIR/Import/basic.ll +++ b/mlir/test/Target/LLVMIR/Import/basic.ll @@ -572,3 +572,14 @@ ret void } +; Shufflevector +; CHECK-LABEL: llvm.func @shuffle_vec +define <4 x half> @shuffle_vec(<4 x half>* %arg0, <4 x half>* %arg1) { + ; CHECK: %[[V0:.+]] = llvm.load %{{.+}} : !llvm.ptr> + %val0 = load <4 x half>, <4 x half>* %arg0 + ; CHECK: %[[V1:.+]] = llvm.load %{{.+}} : !llvm.ptr> + %val1 = load <4 x half>, <4 x half>* %arg1 + ; CHECK: llvm.shufflevector %[[V0]], %[[V1]] [2 : i32, 3 : i32, -1 : i32, -1 : i32] : vector<4xf16>, vector<4xf16> + %shuffle = shufflevector <4 x half> %val0, <4 x half> %val1, <4 x i32> + ret <4 x half> %shuffle +}