[Mlir-commits] [mlir] 6904998 - Fix crash in ConvertVectorToLLVM.cpp pattern

Mehdi Amini llvmlistbot at llvm.org
Fri Mar 3 02:16:56 PST 2023


Author: Mehdi Amini
Date: 2023-03-03T11:16:43+01:00
New Revision: 690499882973f5cac997e1074162b3fb31c53ef2

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

LOG: Fix crash in ConvertVectorToLLVM.cpp pattern

Fixes #61094

Added: 
    mlir/test/Conversion/GPUCommon/lower-vector.mlir

Modified: 
    mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
index b73c01afa8f93..d1b78bf626973 100644
--- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -21,6 +21,7 @@
 #include "mlir/IR/TypeUtilities.h"
 #include "mlir/Target/LLVMIR/TypeToLLVM.h"
 #include "mlir/Transforms/DialectConversion.h"
+#include "llvm/Support/Casting.h"
 #include <optional>
 
 using namespace mlir;
@@ -820,11 +821,10 @@ class VectorMaskOpConversionBase
   matchAndRewrite(vector::MaskOp maskOp, OpAdaptor adaptor,
                   ConversionPatternRewriter &rewriter) const override final {
     // Match against the maskable operation kind.
-    Operation *maskableOp = maskOp.getMaskableOp();
-    if (!isa<MaskedOp>(maskableOp))
+    auto maskedOp = llvm::dyn_cast_or_null<MaskedOp>(maskOp.getMaskableOp());
+    if (!maskedOp)
       return failure();
-    return matchAndRewriteMaskableOp(
-        maskOp, cast<MaskedOp>(maskOp.getMaskableOp()), rewriter);
+    return matchAndRewriteMaskableOp(maskOp, maskedOp, rewriter);
   }
 
 protected:

diff  --git a/mlir/test/Conversion/GPUCommon/lower-vector.mlir b/mlir/test/Conversion/GPUCommon/lower-vector.mlir
new file mode 100644
index 0000000000000..44deb45cd752b
--- /dev/null
+++ b/mlir/test/Conversion/GPUCommon/lower-vector.mlir
@@ -0,0 +1,11 @@
+// RUN: mlir-opt %s --gpu-to-llvm | FileCheck %s
+
+module {
+  func.func @func(%arg: vector<11xf32>) {
+    %cst_41 = arith.constant dense<true> : vector<11xi1>
+    // CHECK: vector.mask
+    // CHECK-SAME: vector.yield %arg0
+    %127 = vector.mask %cst_41 { vector.yield %arg : vector<11xf32> } : vector<11xi1> -> vector<11xf32>
+    return
+  }
+}


        


More information about the Mlir-commits mailing list