[Mlir-commits] [mlir] [mlir] Fix MemRefType alignment in ConvertVectorToLLVM (PR #137389)

Lily Orth-Smith llvmlistbot at llvm.org
Fri Apr 25 13:03:38 PDT 2025


https://github.com/electriclilies created https://github.com/llvm/llvm-project/pull/137389

Previously, the alignment of a MemRefType was set to the alignment of its element type. This caused us to have to set the preferred alignment of scalar types to the desired preferred alignment for vector types. For example, we had to set the preferred alignment of i1s to 512 in our DataLayoutDescription, which is not ideal. 

This change constructs a vector type which has the same datatype and size as the MemRefType, and then extracts the preferred alignment from that vector type. I did try to use the MemRefType directly, but the output alignments were not correct.

>From a759c0901964cff31d4c2c9afd0d693577a8f472 Mon Sep 17 00:00:00 2001
From: Lily Orth-Smith <lorthsmith at microsoft.com>
Date: Fri, 25 Apr 2025 19:51:30 +0000
Subject: [PATCH] Fix how we get alignment for memrefs

---
 mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
index 076e5512f375b..480819bd07680 100644
--- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -70,8 +70,11 @@ static Value extractOne(ConversionPatternRewriter &rewriter,
 // Helper that returns data layout alignment of a memref.
 LogicalResult getMemRefAlignment(const LLVMTypeConverter &typeConverter,
                                  MemRefType memrefType, unsigned &align) {
-  Type elementTy = typeConverter.convertType(memrefType.getElementType());
-  if (!elementTy)
+  // Align MemRefTypes to the alignment of a VectorType with the same
+  // size and dtype.
+  Type convertedVecType = typeConverter.convertType(
+      VectorType::get(memrefType.getShape(), memrefType.getElementType()));
+  if (!convertedVecType)
     return failure();
 
   // TODO: this should use the MLIR data layout when it becomes available and



More information about the Mlir-commits mailing list