[clang] [Clang] Add `__builtin_[ordered_]reduce_fadd` for ordered/unordered fp reductions (PR #176160)
Benjamin Maxwell via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 27 02:15:22 PST 2026
================
@@ -3628,6 +3630,44 @@ Sema::CheckBuiltinFunctionCall(FunctionDecl *FDecl, unsigned BuiltinID,
break;
}
+ case Builtin::BI__builtin_reduce_addf:
+ case Builtin::BI__builtin_ordered_reduce_addf: {
+ if (checkArgCountRange(TheCall, 1, 2))
+ return ExprError();
+
+ ExprResult Vec = UsualUnaryConversions(TheCall->getArg(0));
+ if (Vec.isInvalid())
+ return ExprError();
+
+ TheCall->setArg(0, Vec.get());
+
+ QualType ElTy = getVectorElementType(Context, Vec.get()->getType());
+ if (ElTy.isNull() || !ElTy->isRealFloatingType()) {
+ Diag(Vec.get()->getBeginLoc(), diag::err_builtin_invalid_arg_type)
+ << 1 << /* vector of */ 4 << /* no int */ 0 << /* fp */ 1
+ << Vec.get()->getType();
+ return ExprError();
+ }
+
+ if (TheCall->getNumArgs() == 2) {
+ ExprResult StartValue = UsualUnaryConversions(TheCall->getArg(1));
+ if (StartValue.isInvalid())
+ return ExprError();
+
+ if (!StartValue.get()->getType()->isRealFloatingType()) {
----------------
MacDue wrote:
I defined the innit value as being cast to the element type to allow things to work with Clang's floating-point promotions, which means for example, promotes Float16 to float32 if it's not a natively supported scalar. But maybe, I can avoid emitting the promotions in the first place.
https://github.com/llvm/llvm-project/pull/176160
More information about the cfe-commits
mailing list