[Mlir-commits] [mlir] [mlir] Fix MemRefType alignment in ConvertVectorToLLVM (PR #137389)
Lily Orth-Smith
llvmlistbot at llvm.org
Fri Apr 25 15:15:51 PDT 2025
https://github.com/electriclilies updated https://github.com/llvm/llvm-project/pull/137389
>From de7365648aabbd0834b4d50667938be211139f2f 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
---
.../VectorToLLVM/ConvertVectorToLLVM.cpp | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
index 076e5512f375b..d5b312d6929be 100644
--- a/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
+++ b/mlir/lib/Conversion/VectorToLLVM/ConvertVectorToLLVM.cpp
@@ -70,15 +70,26 @@ 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)
+ // If shape is statically known, assign MemRefTypes to the alignment of a
+ // VectorType with the same size and dtype. Otherwise, fall back to the
+ // alignment of the element type.
+ Type convertedType;
+ if (memrefType.hasStaticShape()) {
+ convertedType = typeConverter.convertType(VectorType::get(
+ memrefType.getNumElements(), memrefType.getElementType()));
+ } else {
+ convertedType = typeConverter.convertType(memrefType.getElementType());
+ }
+
+ if (!convertedType)
return failure();
// TODO: this should use the MLIR data layout when it becomes available and
// stop depending on translation.
llvm::LLVMContext llvmContext;
- align = LLVM::TypeToLLVMIRTranslator(llvmContext)
- .getPreferredAlignment(elementTy, typeConverter.getDataLayout());
+ align =
+ LLVM::TypeToLLVMIRTranslator(llvmContext)
+ .getPreferredAlignment(convertedType, typeConverter.getDataLayout());
return success();
}
More information about the Mlir-commits
mailing list