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

llvmlistbot at llvm.org llvmlistbot at llvm.org
Fri Apr 25 13:04:13 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-mlir

Author: Lily Orth-Smith (electriclilies)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/137389.diff


1 Files Affected:

- (modified) mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp (+5-2) 


``````````diff
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

``````````

</details>


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


More information about the Mlir-commits mailing list