Skip to content

[mlir][vector] Fix rewrite pattern API violation in VectorToSCF #77909

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

matthias-springer
Copy link
Member

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

@llvmbot
Copy link
Member

llvmbot commented Jan 12, 2024

@llvm/pr-subscribers-mlir

Author: Matthias Springer (matthias-springer)

Changes

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) &lt;{in_bounds = [true, true], operandSegmentSizes = array&lt;i32: 1, 2, 1, 1&gt;, permutation_map = affine_map&lt;(d0, d1) -&gt; (d0, d1)&gt;}&gt; : (memref&lt;?x4xf32&gt;, index, index, f32, vector&lt;[4]x4xi1&gt;) -&gt; vector&lt;[4]x4xf32&gt;

  * Pattern (anonymous namespace)::lowering_n_d_unrolled::UnrollTransferReadConversion : 'vector.transfer_read -&gt; ()' {
Trying to match "(anonymous namespace)::lowering_n_d_unrolled::UnrollTransferReadConversion"
    ** Insert  : 'vector.splat'(0x55823a445640)
"(anonymous namespace)::lowering_n_d_unrolled::UnrollTransferReadConversion" result 0
  } -&gt; failure : pattern failed to match

LLVM ERROR: pattern returned failure but IR did change

Full diff: https://github.com/llvm/llvm-project/pull/77909.diff

1 Files Affected:

  • (modified) mlir/lib/Conversion/VectorToSCF/VectorToSCF.cpp (+4-5)
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];

Copy link
Contributor

@nicolasvasilache nicolasvasilache left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we're here, can we also add some return notifyMatchFailure to improve UX?

@matthias-springer matthias-springer force-pushed the fix_vector_to_scf_rewrite_api branch from 2eedc0e to ecb9d3b Compare January 12, 2024 11:46
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
```
@matthias-springer matthias-springer force-pushed the fix_vector_to_scf_rewrite_api branch from ecb9d3b to 5a4f8b2 Compare January 12, 2024 12:40
@matthias-springer matthias-springer merged commit aa2dc79 into llvm:main Jan 12, 2024
justinfargnoli pushed a commit to justinfargnoli/llvm-project that referenced this pull request Jan 28, 2024
…vm#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
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants