diff --git a/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp b/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp --- a/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp +++ b/mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp @@ -2462,6 +2462,9 @@ VectorType castSrcType = bitcastOp.getSourceVectorType(); VectorType castDstType = bitcastOp.getResultVectorType(); assert(castSrcType.getRank() == castDstType.getRank()); + // Skip 0-D vector which will not from InsertStridedSliceOp. + if (castSrcType.getRank() == 0) + return failure(); int64_t castSrcLastDim = castSrcType.getShape().back(); int64_t castDstLastDim = castDstType.getShape().back(); diff --git a/mlir/test/Dialect/Vector/vector-cast-0D.mlir b/mlir/test/Dialect/Vector/vector-cast-0D.mlir new file mode 100644 --- /dev/null +++ b/mlir/test/Dialect/Vector/vector-cast-0D.mlir @@ -0,0 +1,9 @@ +// RUN: mlir-opt %s -test-vector-to-vector-lowering | FileCheck %s + +// Make sure not crash on 0-D vector. +// CHECK:func.func @func +// CHECK-NEXT:vector.bitcast +func.func @func(%arg0: vector) -> vector { + %0 = vector.bitcast %arg0 : vector to vector + return %0 : vector +}