Skip to content

Fix memref.expand_shape verifier #91501

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
merged 1 commit into from
May 8, 2024
Merged

Conversation

bjacob
Copy link
Contributor

@bjacob bjacob commented May 8, 2024

Torch-mlir integration is currently blocked on memref.expand_shape verifier errors of the form

'memref.expand_shape' op invalid output shape provided at pos 1

The verifier code generating these errors was introduced in #91245. I have commented there why I believe it's incorrect. This PR has my suggested fix.

Unfortunately, this does not seem to be directly testable on memref IR, because static_output_shape is not directly exposed in the custom assembly format.

@bjacob bjacob marked this pull request as ready for review May 8, 2024 16:30
@bjacob bjacob requested a review from MaheshRavishankar May 8, 2024 16:30
@llvmbot
Copy link
Member

llvmbot commented May 8, 2024

@llvm/pr-subscribers-mlir-memref

@llvm/pr-subscribers-mlir

Author: Benoit Jacob (bjacob)

Changes

Torch-mlir integration is currently blocked on memref.expand_shape verifier errors of the form

'memref.expand_shape' op invalid output shape provided at pos 1

The verifier code generating these errors was introduced in #91245. I have commented there why I believe it's incorrect. This PR has my suggested fix.

Unfortunately, this does not seem to be directly testable on memref IR, because static_output_shape is not directly exposed in the custom assembly format.


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

1 Files Affected:

  • (modified) mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp (+4-5)
diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
index 78201ae29cd9..dc6fd770d9bd 100644
--- a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
+++ b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
@@ -2356,12 +2356,11 @@ LogicalResult ExpandShapeOp::verify() {
   // Verify if provided output shapes are in agreement with output type.
   DenseI64ArrayAttr staticOutputShapes = getStaticOutputShapeAttr();
   ArrayRef<int64_t> resShape = getResult().getType().getShape();
-  unsigned staticShapeNum = 0;
-
-  for (auto [pos, shape] : llvm::enumerate(resShape))
-    if (!ShapedType::isDynamic(shape) &&
-        shape != staticOutputShapes[staticShapeNum++])
+  for (auto [pos, shape] : llvm::enumerate(resShape)) {
+    if (!ShapedType::isDynamic(shape) && shape != staticOutputShapes[pos]) {
       emitOpError("invalid output shape provided at pos ") << pos;
+    }
+  }
 
   return success();
 }

@bjacob bjacob force-pushed the fix-expand-verifier branch from e874691 to 420a815 Compare May 8, 2024 16:57
@bjacob bjacob requested a review from MaheshRavishankar May 8, 2024 16:58
@bjacob bjacob merged commit dabdec1 into llvm:main May 8, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants