[Mlir-commits] [mlir] [mlir][vector] Fix rewrite pattern API violation in `VectorToSCF` (PR #77909)
Matthias Springer
llvmlistbot at llvm.org
Fri Jan 12 03:32:10 PST 2024
https://github.com/matthias-springer created https://github.com/llvm/llvm-project/pull/77909
A rewrite pattern is not allowed to change the IR if it returns "failure". This commit fixes `test/Conversion/VectorToSCF/vector-to-scf.mlir` when running with `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS`.
```
Processing operation : 'vector.transfer_read'(0x55823a409a60) {
%5 = "vector.transfer_read"(%arg0, %0, %0, %2, %4) <{in_bounds = [true, true], operandSegmentSizes = array<i32: 1, 2, 1, 1>, permutation_map = affine_map<(d0, d1) -> (d0, d1)>}> : (memref<?x4xf32>, index, index, f32, vector<[4]x4xi1>) -> vector<[4]x4xf32>
* Pattern (anonymous namespace)::lowering_n_d_unrolled::UnrollTransferReadConversion : 'vector.transfer_read -> ()' {
Trying to match "(anonymous namespace)::lowering_n_d_unrolled::UnrollTransferReadConversion"
** Insert : 'vector.splat'(0x55823a445640)
"(anonymous namespace)::lowering_n_d_unrolled::UnrollTransferReadConversion" result 0
} -> failure : pattern failed to match
LLVM ERROR: pattern returned failure but IR did change
```
>From 2eedc0ee0dcd668006757393e042eff11bb0999c Mon Sep 17 00:00:00 2001
From: Matthias Springer <springerm at google.com>
Date: Fri, 12 Jan 2024 11:30:50 +0000
Subject: [PATCH] [mlir][vector] Fix rewrite pattern API violation in
`VectorToSCF`
A pattern is not allowed to change the IR if it returns "failure". This commit fixes `test/Conversion/VectorToSCF/vector-to-scf.mlir` when running with `MLIR_ENABLE_EXPENSIVE_PATTERN_API_CHECKS`.
```
Processing operation : 'vector.transfer_read'(0x55823a409a60) {
%5 = "vector.transfer_read"(%arg0, %0, %0, %2, %4) <{in_bounds = [true, true], operandSegmentSizes = array<i32: 1, 2, 1, 1>, permutation_map = affine_map<(d0, d1) -> (d0, d1)>}> : (memref<?x4xf32>, index, index, f32, vector<[4]x4xi1>) -> vector<[4]x4xf32>
* Pattern (anonymous namespace)::lowering_n_d_unrolled::UnrollTransferReadConversion : 'vector.transfer_read -> ()' {
Trying to match "(anonymous namespace)::lowering_n_d_unrolled::UnrollTransferReadConversion"
** Insert : 'vector.splat'(0x55823a445640)
"(anonymous namespace)::lowering_n_d_unrolled::UnrollTransferReadConversion" result 0
} -> failure : pattern failed to match
LLVM ERROR: pattern returned failure but IR did change
```
---
mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp b/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
index a1aff1ab36a52b..4dfd78a9b91042 100644
--- a/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
+++ b/mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp
@@ -1105,17 +1105,16 @@ struct UnrollTransferReadConversion
if (xferOp.getVectorType().getElementType() !=
xferOp.getShapedType().getElementType())
return failure();
-
- auto insertOp = getInsertOp(xferOp);
- auto vec = getResultVector(xferOp, rewriter);
- auto vecType = dyn_cast<VectorType>(vec.getType());
auto xferVecType = xferOp.getVectorType();
-
if (xferVecType.getScalableDims()[0]) {
// Cannot unroll a scalable dimension at compile time.
return failure();
}
+ auto insertOp = getInsertOp(xferOp);
+ auto vec = getResultVector(xferOp, rewriter);
+ auto vecType = dyn_cast<VectorType>(vec.getType());
+
VectorType newXferVecType = VectorType::Builder(xferVecType).dropDim(0);
int64_t dimSize = xferVecType.getShape()[0];
More information about the Mlir-commits
mailing list