[Mlir-commits] [mlir] 3da65c4 - [mlir][LLVMIR] Add support for translating shufflevector

Min-Yih Hsu llvmlistbot at llvm.org
Sat May 14 15:15:29 PDT 2022


Author: Min-Yih Hsu
Date: 2022-05-14T15:14:40-07:00
New Revision: 3da65c4c0b00b9fc0cf2db77c18a58bc6fca251f

URL: https://github.com/llvm/llvm-project/commit/3da65c4c0b00b9fc0cf2db77c18a58bc6fca251f
DIFF: https://github.com/llvm/llvm-project/commit/3da65c4c0b00b9fc0cf2db77c18a58bc6fca251f.diff

LOG: [mlir][LLVMIR] Add support for translating shufflevector

Add support for translating llvm::ShuffleVectorInst

Differential Revision: https://reviews.llvm.org/D125030

Added: 
    

Modified: 
    mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
    mlir/test/Target/LLVMIR/Import/basic.ll

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
index 00f850c5278a8..124d82b3f78c1 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<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();
+  }
   }
 }
 

diff  --git a/mlir/test/Target/LLVMIR/Import/basic.ll b/mlir/test/Target/LLVMIR/Import/basic.ll
index d5a7667388039..24810ac7732b5 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<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
+}


        


More information about the Mlir-commits mailing list