[Mlir-commits] [mlir] [mlir][memref] canonicalization for erasing copying subview to identical subview (PR #125852)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Feb 6 18:12:22 PST 2025


================
@@ -824,8 +824,36 @@ struct FoldSelfCopy : public OpRewritePattern<CopyOp> {
 
   LogicalResult matchAndRewrite(CopyOp copyOp,
                                 PatternRewriter &rewriter) const override {
-    if (copyOp.getSource() != copyOp.getTarget())
-      return failure();
+    if (copyOp.getSource() != copyOp.getTarget()) {
+      // If the source and target are SubViews and they are identical, we can
+      // fold.
+      auto source = copyOp.getSource().getDefiningOp<SubViewOp>();
+      auto target = copyOp.getTarget().getDefiningOp<SubViewOp>();
+      if (!source || !target || source.getSource() != target.getSource() ||
----------------
MaheshRavishankar wrote:

This is hard to read. Can we split this out int separate conditions. Checking source and target are non null and equal in one condition is fine. Better to split the rest into separate conditions.

https://github.com/llvm/llvm-project/pull/125852


More information about the Mlir-commits mailing list