Skip to content

Commit 5f1f9cf

Browse files
authored
[mlir][Vector] Fix an assertion on failing cast in vector-transfer-flatten-patterns (#86030)
When the result is not a vectorType, there is an assert. This patch will do the check and bail when the result is not a VectorType.
1 parent 0a42994 commit 5f1f9cf

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

mlir/lib/Dialect/Vector/Transforms/VectorLinearize.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ using namespace mlir;
2222
static bool isLessThanTargetBitWidth(Operation *op, unsigned targetBitWidth) {
2323
auto resultTypes = op->getResultTypes();
2424
for (auto resType : resultTypes) {
25-
VectorType vecType = cast<VectorType>(resType);
25+
VectorType vecType = dyn_cast<VectorType>(resType);
2626
// Reject index since getElementTypeBitWidth will abort for Index types.
27-
if (vecType.getElementType().isIndex())
27+
if (!vecType || vecType.getElementType().isIndex())
2828
return false;
2929
unsigned trailingVecDimBitWidth =
3030
vecType.getShape().back() * vecType.getElementTypeBitWidth();

mlir/test/Dialect/Vector/linearize.mlir

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,16 @@ func.func @test_index_no_linearize(%arg0: vector<2x2xindex>, %arg1: vector<2x2xi
9090
%0 = arith.addi %arg0, %arg1 : vector<2x2xindex>
9191
return %0 : vector<2x2xindex>
9292
}
93+
94+
// -----
95+
96+
// vectorizable operation (arith.mulf) with tensor result types.
97+
98+
func.func @nonvec_result(%arg0: tensor<2x2xf32>, %arg1: tensor<2x2xf32>) -> (tensor<2x2xf32>, tensor<2x2xf32>) {
99+
// CHECK: %[[MULF:.*]] = arith.mulf %arg0, %arg1 : tensor<2x2xf32>
100+
// CHECK128: %[[MULF:.*]] = arith.mulf %arg0, %arg1 : tensor<2x2xf32>
101+
// CHECK0: %[[MULF:.*]] = arith.mulf %arg0, %arg1 : tensor<2x2xf32>
102+
%0 = arith.mulf %arg0, %arg1 : tensor<2x2xf32>
103+
104+
return %0, %arg0 : tensor<2x2xf32>, tensor<2x2xf32>
105+
}

0 commit comments

Comments
 (0)