[Mlir-commits] [mlir] [mlir][LLVM] Preserve scalable array bit sizes (PR #236862)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Thu Oct 29 10:46:23 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-mlir
Author: Akimasa Watanuki (Men-cotton)
<details>
<summary>Changes</summary>
Preserve the scalable factor in LLVM array bit-size queries, including nested arrays of scalable vectors. Prevent these queries from aborting when the array size depends on `vscale`.
Assisted-by: Codex / GPT-6
---
Full diff: https://github.com/llvm/llvm-project/pull/236862.diff
2 Files Affected:
- (modified) mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp (+1-2)
- (modified) mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp (+10)
``````````diff
diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
index 2d99c0e4a4931d..03fe8a15c5d30c 100644
--- a/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
+++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMTypes.cpp
@@ -181,8 +181,7 @@ LLVMArrayType::verify(function_ref<InFlightDiagnostic()> emitError,
llvm::TypeSize
LLVMArrayType::getTypeSizeInBits(const DataLayout &dataLayout,
DataLayoutEntryListRef params) const {
- return llvm::TypeSize::getFixed(kBitsInByte *
- getTypeSize(dataLayout, params));
+ return getTypeSize(dataLayout, params) * kBitsInByte;
}
llvm::TypeSize LLVMArrayType::getTypeSize(const DataLayout &dataLayout,
diff --git a/mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp b/mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp
index 72d8867d232aad..7428f0fe39da76 100644
--- a/mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp
+++ b/mlir/unittests/Dialect/LLVMIR/LLVMTypeTest.cpp
@@ -60,3 +60,13 @@ TEST_F(LLVMIRTest, StructElementOffsets) {
EXPECT_EQ(packedAlloc.getElementOffset(dataLayout, 1), 16u);
EXPECT_EQ(dataLayout.getTypeSize(packedAlloc), 17u);
}
+
+TEST_F(LLVMIRTest, ScalableVectorArrayLayout) {
+ DataLayout layout;
+ auto vector = VectorType::get({3}, IntegerType::get(&context, 32), {true});
+ auto array = LLVMArrayType::get(LLVMArrayType::get(vector, 2), 3);
+ EXPECT_EQ(layout.getTypeSizeInBits(array).getKnownMinValue(), 768u);
+ EXPECT_TRUE(layout.getTypeSizeInBits(array).isScalable());
+ EXPECT_EQ(layout.getTypeSize(array).getKnownMinValue(), 96u);
+ EXPECT_TRUE(layout.getTypeSize(array).isScalable());
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/236862
More information about the Mlir-commits
mailing list