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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Thu Sep 28 12:38:48 PDT 2023


Author: Kunwar Grover
Date: 2023-09-29T01:08:43+05:30
New Revision: 35ec6ea6441d892e6d43a89683b35abb9cf9e0e7

URL: https://github.com/llvm/llvm-project/commit/35ec6ea6441d892e6d43a89683b35abb9cf9e0e7
DIFF: https://github.com/llvm/llvm-project/commit/35ec6ea6441d892e6d43a89683b35abb9cf9e0e7.diff

LOG: [mlir][memref] Fix offset update in emulating narrow type for strided memref (#67714)

The offset when converting type in emulating narrow types did not
account for the offset in strided memrefs. This patch fixes this.

Added: 
    

Modified: 
    mlir/lib/Dialect/MemRef/Transforms/EmulateNarrowType.cpp

Removed: 
    


################################################################################
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