[clang] [CIR] Lowering for __builtin_reduce_add/mul/min/max/in_order_fadd (PR #224204)

Kunal Dubey via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 17 22:03:00 PDT 2026


================
@@ -2160,7 +2197,32 @@ RValue CIRGenFunction::emitBuiltinExpr(const GlobalDecl &gd, unsigned builtinID,
         cast<cir::VectorType>(convertType(e->getArg(0)->getType()))
             .getElementType());
   case Builtin::BI__builtin_reduce_assoc_fadd:
-  case Builtin::BI__builtin_reduce_in_order_fadd:
+    return errorBuiltinNYI(*this, e, builtinID);
+  case Builtin::BI__builtin_reduce_in_order_fadd: {
+    mlir::Value vector = emitScalarExpr(e->getArg(0));
+    auto vectorTy = cast<cir::VectorType>(vector.getType());
+    mlir::Type scalarTy = vectorTy.getElementType();
+    mlir::Value startValue;
+    mlir::Location loc = getLoc(e->getExprLoc());
+    if (e->getNumArgs() == 2) {
+      startValue = emitScalarExpr(e->getArg(1));
+      if (startValue.getType() != scalarTy)
+        startValue =
+            builder.createCast(getLoc(e->getArg(1)->getExprLoc()),
+                               cir::CastKind::floating, startValue, scalarTy);
+    } else {
+      auto fpTy = cast<cir::FPTypeInterface>(scalarTy);
+      startValue = cir::ConstantOp::create(
+          builder, loc,
+          cir::FPAttr::get(scalarTy,
+                           llvm::APFloat::getZero(fpTy.getFloatSemantics(),
----------------
xakep8 wrote:

Yes I saw that Sema rejects single arg on reduce_in_order_fadd I just left it there because I was targeting the support for fast-math in cir::LLVMIntrinsicCallOp but ig for this PR I'll remove that and bring it back with proper support in the next one.

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


More information about the cfe-commits mailing list