[Mlir-commits] [mlir] [mlir][memref] Canonicalize memref.reinterpret_cast when offset/sizes/strides are constants. (PR #163505)

Matthias Springer llvmlistbot at llvm.org
Fri Oct 17 01:33:22 PDT 2025


================
@@ -2158,11 +2158,33 @@ struct ReinterpretCastOpExtractStridedMetadataFolder
     return success();
   }
 };
+
+struct ReinterpretCastOpConstantFolder
+    : public OpRewritePattern<ReinterpretCastOp> {
+public:
+  using OpRewritePattern<ReinterpretCastOp>::OpRewritePattern;
+
+  LogicalResult matchAndRewrite(ReinterpretCastOp op,
+                                PatternRewriter &rewriter) const override {
+    if (!llvm::any_of(llvm::concat<OpFoldResult>(op.getOffsets(), op.getSizes(),
----------------
matthias-springer wrote:

Actually, I think this is not good enough.

You want to return "success" if and only if the IR was modified. I think your approach does not guarantee that.

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


More information about the Mlir-commits mailing list