[Mlir-commits] [flang] [mlir] [mlir] Align num elements type to LLVM ArrayType (PR #93230)
Tobias Gysi
llvmlistbot at llvm.org
Wed May 29 11:14:32 PDT 2024
================
@@ -632,8 +632,40 @@ llvm::Constant *mlir::LLVM::detail::getLLVMConstant(
llvm::ElementCount::get(numElements, /*Scalable=*/isScalable), child);
if (llvmType->isArrayTy()) {
auto *arrayType = llvm::ArrayType::get(elementType, numElements);
- SmallVector<llvm::Constant *, 8> constants(numElements, child);
- return llvm::ConstantArray::get(arrayType, constants);
+ if (child->isZeroValue()) {
+ return llvm::ConstantAggregateZero::get(arrayType);
+ } else {
+ if (llvm::ConstantDataSequential::isElementTypeCompatible(
+ elementType)) {
+ // TODO: Handle all compatible types. This code only handles integer.
+ if (llvm::IntegerType *iTy =
+ dyn_cast<llvm::IntegerType>(elementType)) {
+ if (llvm::ConstantInt *ci = dyn_cast<llvm::ConstantInt>(child)) {
+ if (ci->getBitWidth() == 8) {
+ SmallVector<int8_t> constants(numElements, ci->getZExtValue());
+ return llvm::ConstantDataArray::get(elementType->getContext(),
+ constants);
+ } else if (ci->getBitWidth() == 16) {
----------------
gysit wrote:
nit: These else's are probably also redundant?
https://github.com/llvm/llvm-project/pull/93230
More information about the Mlir-commits
mailing list