[mlir][LLVMIR] Add support for translating shufflevector

Add support for translating llvm::ShuffleVectorInst

Differential Revision: https://reviews.llvm.org/D125030
This commit is contained in:
Min-Yih Hsu 2022-04-20 19:57:32 -07:00
parent b8f52c08f8
commit 3da65c4c0b
2 changed files with 26 additions and 1 deletions

View File

@ -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<ExtractValueOp>(loc, type, aggOperand, indices);
return success();
}
case llvm::Instruction::ShuffleVector: {
auto *svInst = cast<llvm::ShuffleVectorInst>(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<ShuffleVectorOp>(loc, vec1, vec2, mask);
return success();
}
}
}

View File

@ -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<vector<4xf16>>
%val0 = load <4 x half>, <4 x half>* %arg0
; CHECK: %[[V1:.+]] = llvm.load %{{.+}} : !llvm.ptr<vector<4xf16>>
%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> <i32 2, i32 3, i32 undef, i32 undef>
ret <4 x half> %shuffle
}