[Mlir-commits] [mlir] [mlir][memref] Fix offset update in emulating narrow type for strided memref (PR #67714)

Kunwar Grover llvmlistbot at llvm.org
Thu Sep 28 10:36:44 PDT 2023


https://github.com/Groverkss created https://github.com/llvm/llvm-project/pull/67714

None

>From 1d35fff989326db12ef4e1d4bfab964713bdd698 Mon Sep 17 00:00:00 2001
From: Groverkss <groverkss at gmail.com>
Date: Thu, 28 Sep 2023 22:45:20 +0530
Subject: [PATCH] [mlir][memref] Fix offset update in emulating narrow type for
 strided memref

---
 mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp b/mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp
index 2a524ceb9db887b..702a6f6d527f9d8 100644
--- a/mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp
+++ b/mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp
@@ -272,6 +272,12 @@ void memref::populateMemRefNarrowTypeEmulationConversions(
 
         StridedLayoutAttr layoutAttr;
         if (offset != 0) {
+          // Check if the number of bytes are a multiple of the loadStoreWidth
+          // and if so, divide it by the loadStoreWidth to get the offset.
+          if ((offset * width) % loadStoreWidth != 0)
+            return std::nullopt;
+          offset = (offset * width) / loadStoreWidth;
+
           layoutAttr = StridedLayoutAttr::get(ty.getContext(), offset,
                                               ArrayRef<int64_t>{1});
         }



More information about the Mlir-commits mailing list