[Mlir-commits] [mlir] f088b99 - [mlir][LLVMIR] Use the correct way to determine if it's a scalable vector

Min-Yih Hsu llvmlistbot at llvm.org
Fri May 20 21:47:42 PDT 2022


Author: Min-Yih Hsu
Date: 2022-05-20T21:45:50-07:00
New Revision: f088b99eac74e5ab44fd8a576cd5dc28d7042029

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

LOG: [mlir][LLVMIR] Use the correct way to determine if it's a scalable vector

One of the ShuffleVectorOp::build functions checks if the incoming
vector operands is scalable vector by casting its type to
mlir::VectorType first. However, in some cases the operand is not
necessarily mlir::VectorType (e.g. it might be a LLVMVectorType).

This patch fixes this issue by using the dedicated
`LLVM::isScalableVectorType` function to determine if the incoming
vector is scalable vector or not.

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

Added: 
    mlir/test/Target/LLVMIR/Import/incorrect-scalable-vector-check.ll

Modified: 
    mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
index ca28fdf64ad7f..958142b03d245 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
@@ -2049,9 +2049,9 @@ void LLVM::ShuffleVectorOp::build(OpBuilder &b, OperationState &result,
                                   Value v1, Value v2, ArrayAttr mask,
                                   ArrayRef<NamedAttribute> attrs) {
   auto containerType = v1.getType();
-  auto vType = LLVM::getVectorType(
-      LLVM::getVectorElementType(containerType), mask.size(),
-      containerType.cast<VectorType>().isScalable());
+  auto vType = LLVM::getVectorType(LLVM::getVectorElementType(containerType),
+                                   mask.size(),
+                                   LLVM::isScalableVectorType(containerType));
   build(b, result, vType, v1, v2, mask);
   result.addAttributes(attrs);
 }

diff  --git a/mlir/test/Target/LLVMIR/Import/incorrect-scalable-vector-check.ll b/mlir/test/Target/LLVMIR/Import/incorrect-scalable-vector-check.ll
new file mode 100644
index 0000000000000..03ddee2da3eeb
--- /dev/null
+++ b/mlir/test/Target/LLVMIR/Import/incorrect-scalable-vector-check.ll
@@ -0,0 +1,8 @@
+; RUN: mlir-translate --import-llvm %s | FileCheck %s
+
+; CHECK: llvm.func @shufflevector_crash
+define void @shufflevector_crash(<2 x i32*> %arg0) {
+  ; CHECK: llvm.shufflevector %{{.+}}, %{{.+}} [1 : i32, 0 : i32] : !llvm.vec<2 x ptr<i32>>, !llvm.vec<2 x ptr<i32>>
+  %1 = shufflevector <2 x i32*> %arg0, <2 x i32*> undef, <2 x i32> <i32 1, i32 0>
+  ret void
+}


        


More information about the Mlir-commits mailing list