[Mlir-commits] [mlir] [mlir][arith.constant]Fix element type of the dense attributes in target attributes to be consistent with result type in LLVM::detail::oneToOneRewrite() (PR #149787)
Krzysztof Drewniak
llvmlistbot at llvm.org
Mon Jul 21 08:20:28 PDT 2025
================
@@ -331,10 +331,35 @@ LogicalResult LLVM::detail::oneToOneRewrite(
return failure();
}
+ // If the targetAttrs contains DenseElementsAttr,
+ // and the element type of the DenseElementsAttr and result type is
+ // inconsistent after the conversion of result types, we need to convert the
+ // element type of the DenseElementsAttr to the target type by creating a new
+ // DenseElementsAttr with the converted element type, and use the new
+ // DenseElementsAttr to replace the old one in the targetAttrs
+ SmallVector<NamedAttribute> convertedAttrs;
+ for (auto attr : targetAttrs) {
+ if (auto denseAttr = dyn_cast<DenseElementsAttr>(attr.getValue())) {
+ VectorType vectorType = dyn_cast<VectorType>(denseAttr.getType());
+ if (vectorType) {
+ auto convertedElementType =
+ typeConverter.convertType(vectorType.getElementType());
+ VectorType convertedVectorType =
+ VectorType::get(vectorType.getShape(), convertedElementType,
+ vectorType.getScalableDims());
+ convertedAttrs.emplace_back(
+ attr.getName(), DenseElementsAttr::getFromRawBuffer(
+ convertedVectorType, denseAttr.getRawData()));
+ }
+ } else {
+ convertedAttrs.push_back(attr);
----------------
krzysz00 wrote:
Shouldn't this also be done for scalar attributes? Ex. a index constant becoming an i64 constant?
https://github.com/llvm/llvm-project/pull/149787
More information about the Mlir-commits
mailing list