[Mlir-commits] [mlir] Fix `memref.expand_shape` verifier (PR #91501)
Benoit Jacob
llvmlistbot at llvm.org
Wed May 8 09:30:27 PDT 2024
https://github.com/bjacob created https://github.com/llvm/llvm-project/pull/91501
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 https://github.com/llvm/llvm-project/pull/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.
>From bae8252983a73369a3acb346244ff6e5d9b186fe Mon Sep 17 00:00:00 2001
From: Benoit Jacob <jacob.benoit.1 at gmail.com>
Date: Wed, 8 May 2024 12:27:35 -0400
Subject: [PATCH] fix-expand-verifier
---
mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp | 9 ++++-----
1 file changed, 4 insertions(+), 5 deletions(-)
diff --git a/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp b/mlir/lib/Dialect/MemRef/IR/MemRefOps.cpp
index 78201ae29cd9b..dc6fd770d9bd7 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();
}
More information about the Mlir-commits
mailing list