[Mlir-commits] [mlir] [mlir][math] Add vector support for math-to-apfloat (PR #172715)

Maksim Levental llvmlistbot at llvm.org
Thu Jan 15 16:45:14 PST 2026


================
@@ -151,8 +151,52 @@ struct FmaOpToAPFloatConversion final : OpRewritePattern<math::FmaOp> {
     Location loc = op.getLoc();
     rewriter.setInsertionPoint(op);
 
-    auto intWType = rewriter.getIntegerType(floatTy.getWidth());
-    auto int64Type = rewriter.getI64Type();
+    IntegerType intWType = rewriter.getIntegerType(floatTy.getWidth());
+    IntegerType int64Type = rewriter.getI64Type();
+
+    auto scalarFMA = [&rewriter, &loc, &floatTy, &fn, &intWType](
+                         Value operand, Value multiplicand, Value addend) {
+      // Call APFloat function.
+      Value semValue = getAPFloatSemanticsValue(rewriter, loc, floatTy);
+      SmallVector<Value> params = {semValue, operand, multiplicand, addend};
+      auto resultOp =
+          func::CallOp::create(rewriter, loc, TypeRange(rewriter.getI64Type()),
+                               SymbolRefAttr::get(*fn), params);
+
+      // Truncate result to the original width.
+      auto trunc = arith::TruncIOp::create(rewriter, loc, intWType,
+                                           resultOp->getResult(0));
+      return arith::BitcastOp::create(rewriter, loc, floatTy, trunc);
+    };
+
+    if (VectorType vecTy1 = dyn_cast<VectorType>(op.getA().getType())) {
----------------
makslevental wrote:

easier to just one-off here (not many 3+ operand ops to handle...)

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


More information about the Mlir-commits mailing list