[Mlir-commits] [mlir] [mlir][memref] Fix emulate narrow types for strided memref offset (PR #68181)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Oct 4 09:24:29 PDT 2023
================
@@ -209,6 +209,74 @@ struct ConvertMemRefLoad final : OpConversionPattern<memref::LoadOp> {
return success();
}
};
+
+//===----------------------------------------------------------------------===//
+// ConvertMemRefSubview
+//===----------------------------------------------------------------------===//
+
+struct ConvertMemRefSubview final : OpConversionPattern<memref::SubViewOp> {
+ using OpConversionPattern::OpConversionPattern;
+
+ LogicalResult
+ matchAndRewrite(memref::SubViewOp op, OpAdaptor adaptor,
+ ConversionPatternRewriter &rewriter) const override {
+ auto convertedType =
+ cast<MemRefType>(getTypeConverter()->convertType(op.getSourceType()));
+ auto convertedElementType = convertedType.getElementType();
+ auto oldElementType = op.getSourceType().getElementType();
+ int srcBits = oldElementType.getIntOrFloatBitWidth();
+ int dstBits = convertedElementType.getIntOrFloatBitWidth();
+ if (dstBits % srcBits != 0) {
+ return rewriter.notifyMatchFailure(
+ op, "only dstBits % srcBits == 0 supported");
+ }
+
+ MemRefType newTy =
+ cast<MemRefType>(getTypeConverter()->convertType(op.getType()));
----------------
MaheshRavishankar wrote:
Use `dyn_cast`. Also you can probably just check this on the `op.getType()` directly.
https://github.com/llvm/llvm-project/pull/68181
More information about the Mlir-commits
mailing list