[Mlir-commits] [mlir] [mlir][bufferization] Fix invalid IR in `SimplifyClones` canonicalization (PR #74417)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Mon Dec 4 22:05:31 PST 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Matthias Springer (matthias-springer)
<details>
<summary>Changes</summary>
`SimplifyClones` used to generate an invalid op:
```
error: 'memref.cast' op operand type 'memref<*xf32>' and result type 'memref<*xf32>' are cast incompatible
%2 = bufferization.clone %1 : memref<*xf32> to memref<*xf32
```
This commit fixes tests such as `mlir/test/Dialect/Bufferization/canonicalize.mlir` when verifying the IR after each pattern (#<!-- -->74270).
---
Full diff: https://github.com/llvm/llvm-project/pull/74417.diff
1 Files Affected:
- (modified) mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp (+4-2)
``````````diff
diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
index ec5feab1ed0d8..ca0d2f407c2d8 100644
--- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
+++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
@@ -507,8 +507,10 @@ struct SimplifyClones : public OpRewritePattern<CloneOp> {
return failure();
}
- rewriter.replaceOpWithNewOp<memref::CastOp>(cloneOp, cloneOp.getType(),
- source);
+ if (source.getType() != cloneOp.getType())
+ source = rewriter.create<memref::CastOp>(cloneOp.getLoc(),
+ cloneOp.getType(), source);
+ rewriter.replaceOp(cloneOp, source);
rewriter.eraseOp(redundantDealloc);
return success();
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/74417
More information about the Mlir-commits
mailing list