[mlir][vector] Use dyn_cast instead of cast in patterns
authorLei Zhang <antiagainst@google.com>
Mon, 8 Nov 2021 17:33:55 +0000 (12:33 -0500)
committerLei Zhang <antiagainst@google.com>
Mon, 8 Nov 2021 17:34:14 +0000 (12:34 -0500)
This avoids crashes when the pattern is applied to ops with
tensor semantics.

Reviewed By: ThomasRaoux

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

mlir/lib/Dialect/Vector/VectorTransforms.cpp

index 9120310..6528789 100644 (file)
@@ -3579,7 +3579,7 @@ class DropInnerMostUnitDims : public OpRewritePattern<vector::TransferReadOp> {
 
   LogicalResult matchAndRewrite(vector::TransferReadOp readOp,
                                 PatternRewriter &rewriter) const override {
-    auto srcType = readOp.source().getType().cast<MemRefType>();
+    auto srcType = readOp.source().getType().dyn_cast<MemRefType>();
     if (!srcType || !srcType.hasStaticShape())
       return failure();