[Mlir-commits] [mlir] [mlir][MemRef] Add more ops to narrow type support, strided metadata expansion (PR #102228)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Aug 13 11:35:09 PDT 2024
================
@@ -1060,6 +1095,49 @@ class ExtractStridedMetadataOpCastFolder
}
};
+/// Replace `base, offset, sizes, strides = extract_strided_metadata(
+/// memory_space_cast(src) to dstTy)`
+/// with
+/// ```
+/// oldBase, offset, sizes, strides = extract_strided_metadata(src)
+/// destBaseTy = type(oldBase) with memory space from destTy
+/// base = memory_space_cast(oldBase) to destBaseTy
+/// ```
+///
+/// In other words, propagate metadata extraction accross memory space casts.
+class ExtractStridedMetadataOpMemorySpaceCastFolder
+ : public OpRewritePattern<memref::ExtractStridedMetadataOp> {
+ using OpRewritePattern::OpRewritePattern;
+
+ LogicalResult
+ matchAndRewrite(memref::ExtractStridedMetadataOp extractStridedMetadataOp,
+ PatternRewriter &rewriter) const override {
+ Location loc = extractStridedMetadataOp.getLoc();
+ Value source = extractStridedMetadataOp.getSource();
+ auto memSpaceCastOp = source.getDefiningOp<memref::MemorySpaceCastOp>();
+ if (!memSpaceCastOp)
+ return failure();
+ auto newExtractStridedMetadata =
+ rewriter.create<memref::ExtractStridedMetadataOp>(
+ loc, memSpaceCastOp.getSource());
+ SmallVector<Value> results(newExtractStridedMetadata.getResults());
+ if (!extractStridedMetadataOp.getBaseBuffer().use_empty()) {
----------------
MaheshRavishankar wrote:
Do we need to check for this here? This seems like something that DCE should be able to handle after the fact. So ignore the `use_empty()` case?
https://github.com/llvm/llvm-project/pull/102228
More information about the Mlir-commits
mailing list