[Mlir-commits] [mlir] [mlir][arith] `arith-to-apfloat`: Add vector support (PR #171024)

Maksim Levental llvmlistbot at llvm.org
Sun Dec 7 09:14:58 PST 2025


================
@@ -90,6 +91,75 @@ static Value getSemanticsValue(OpBuilder &b, Location loc, FloatType floatTy) {
                                    b.getIntegerAttr(b.getI32Type(), sem));
 }
 
+/// Given two operands of vector type and vector result type (with the same
+/// shape), call the given function for each pair of scalar operands and
+/// package the result into a vector. If the given operands and result type are
+/// not vectors, call the function directly. The second operand is optional.
+template <typename Fn, typename... Values>
+static Value forEachScalarValue(RewriterBase &rewriter, Location loc,
+                                Value operand1, Value operand2, Type resultType,
+                                Fn fn) {
+  auto vecTy1 = dyn_cast<VectorType>(operand1.getType());
+  if (operand2) {
+    // Sanity check: Operand types must match.
+    assert(vecTy1 == dyn_cast<VectorType>(operand2.getType()) &&
+           "expected same vector types");
+  }
+  if (!vecTy1) {
+    // Not a vector. Call the function directly.
+    return fn(operand1, operand2, resultType);
+  }
+
+  // Prepare scalar operands.
+  auto sclars1 = vector::ToElementsOp::create(rewriter, loc, operand1);
----------------
makslevental wrote:

nit
```suggestion
  Value sclars1 = vector::ToElementsOp::create(rewriter, loc, operand1);
```

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


More information about the Mlir-commits mailing list