From 3da65c4c0b00b9fc0cf2db77c18a58bc6fca251f Mon Sep 17 00:00:00 2001 From: Min-Yih Hsu Date: Wed, 20 Apr 2022 19:57:32 -0700 Subject: [PATCH] [mlir][LLVMIR] Add support for translating shufflevector Add support for translating llvm::ShuffleVectorInst Differential Revision: https://reviews.llvm.org/D125030 --- mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp | 16 +++++++++++++++- mlir/test/Target/LLVMIR/Import/basic.ll | 11 +++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp index 00f850c..124d82b 100644 --- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -618,7 +618,7 @@ static StringRef lookupOperationNameFromOpcode(unsigned opcode) { // 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 @@ LogicalResult Importer::processInstruction(llvm::Instruction *inst) { 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 index d5a7667..24810ac7 100644 --- a/mlir/test/Target/LLVMIR/Import/basic.ll +++ b/mlir/test/Target/LLVMIR/Import/basic.ll @@ -572,3 +572,14 @@ define void @insert_extract_value_array([4 x [4 x i8]] %x1) { 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 +} -- 2.7.4