Skip to content

Conversation

@matthias-springer
Copy link
Member

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).

…tion

`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 (llvm#74270).
@llvmbot llvmbot added mlir mlir:bufferization Bufferization infrastructure labels Dec 5, 2023
@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2023

@llvm/pr-subscribers-mlir-bufferization

Author: Matthias Springer (matthias-springer)

Changes

SimplifyClones used to generate an invalid op:

error: 'memref.cast' op operand type 'memref&lt;*xf32&gt;' and result type 'memref&lt;*xf32&gt;' are cast incompatible
  %2 = bufferization.clone %1 : memref&lt;*xf32&gt; to memref&lt;*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 --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();
   }

@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2023

@llvm/pr-subscribers-mlir

Author: Matthias Springer (matthias-springer)

Changes

SimplifyClones used to generate an invalid op:

error: 'memref.cast' op operand type 'memref&lt;*xf32&gt;' and result type 'memref&lt;*xf32&gt;' are cast incompatible
  %2 = bufferization.clone %1 : memref&lt;*xf32&gt; to memref&lt;*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 --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();
   }

@matthias-springer matthias-springer merged commit 68f91cd into llvm:main Dec 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mlir:bufferization Bufferization infrastructure mlir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants