[Mlir-commits] [mlir] [mlir][vector] Fix crash in vector.from_elements folding with poison values (PR #158528)

Jhalak Patel llvmlistbot at llvm.org
Wed Sep 17 11:01:41 PDT 2025


================
@@ -2472,10 +2473,12 @@ static OpFoldResult foldFromElementsToConstant(FromElementsOp fromElementsOp,
   if (!destEltType.isIntOrIndexOrFloat() && !isa<ComplexType>(destEltType))
     return {};
 
-  // Constant attributes might have a different type than the return type.
-  // Convert them before creating the dense elements attribute.
-  auto convertedElements = llvm::map_to_vector(elements, [&](Attribute attr) {
-    return convertIntegerAttr(attr, destEltType);
+  // Convert integer attributes to the target type if needed, leave others unchanged.
+  auto convertedElements = llvm::map_to_vector(elements, [&](Attribute attr) -> Attribute {
+    if (auto intAttr = dyn_cast<IntegerAttr>(attr)) {
+      return convertIntegerAttr(intAttr, destEltType);
+    }
+    return attr; // Non-integer attributes (FloatAttr, etc.) returned unchanged
----------------
jhalakpatel wrote:

> That makes sense. As described in #147691, such type mismatches can also occur with float attributes. This part has been missing. IMHO, we can:
> 
> 1. Rename `convertIntegerAttr` to `convertNumericAttr`, and add an assertion to ensure the input attribute is either an integer or float attribute.
> 2. Or, add a new helper function `convertFloatAttr`.

This looks like an improvement to existing code irrespective of the fix for poison values. Is it OK if I address this in a follow up PR?

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


More information about the Mlir-commits mailing list