[llvm] [llubi] Upstream existing floating-point intrinsics (PR #196034)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu May 7 10:14:47 PDT 2026
================
@@ -1304,6 +1388,286 @@ class InstExecutor : public InstVisitor<InstExecutor, void>,
}
return std::move(Res);
}
+ case Intrinsic::vector_reduce_fadd:
+ case Intrinsic::vector_reduce_fmul:
+ case Intrinsic::vector_reduce_fmaximum:
+ case Intrinsic::vector_reduce_fminimum: {
+ const auto DenormMode = getCurrentDenormalMode(RetTy);
+ const bool HasStart = IID == Intrinsic::vector_reduce_fadd ||
+ IID == Intrinsic::vector_reduce_fmul;
+ const AnyValue &Vector = HasStart ? Args[1] : Args[0];
+ std::optional<APFloat> Res;
+ if (HasStart) {
+ if (Args[0].isPoison())
+ return AnyValue::poison();
+ const AnyValue ValidatedStart =
+ handleFMFFlags(Args[0], FMF, /*IsInput=*/true);
+ if (ValidatedStart.isPoison())
+ return AnyValue::poison();
+ Res = handleDenormal(ValidatedStart.asFloat(), DenormMode.Input,
+ /*IsInput=*/true);
+ }
+ for (const auto &V : Vector.asAggregate()) {
+ if (V.isPoison())
+ return AnyValue::poison();
+ const AnyValue ValidatedOp = handleFMFFlags(V, FMF, /*IsInput=*/true);
+ if (ValidatedOp.isPoison())
+ return AnyValue::poison();
+ APFloat Op = handleDenormal(ValidatedOp.asFloat(), DenormMode.Input,
+ /*IsInput=*/true);
+ if (!Res) {
+ Res = std::move(Op);
+ continue;
+ }
+ switch (IID) {
+ case Intrinsic::vector_reduce_fadd:
+ *Res = *Res + Op;
+ break;
+ case Intrinsic::vector_reduce_fmul:
+ *Res = *Res * Op;
+ break;
+ case Intrinsic::vector_reduce_fmaximum:
+ *Res = maximum(*Res, Op);
+ break;
+ case Intrinsic::vector_reduce_fminimum:
+ *Res = minimum(*Res, Op);
+ break;
+ default:
+ llvm_unreachable("Unexpected intrinsic ID");
+ }
+ }
+ if (Res.has_value()) {
+ const AnyValue ValidatedRes =
+ handleFMFFlags(*Res, FMF, /*IsInput=*/false);
+ if (ValidatedRes.isPoison()) {
+ Res.reset();
+ }
+ const APFloat FRes =
+ handleDenormal(ValidatedRes.asFloat(), DenormMode.Output,
+ /*IsInput=*/false);
+ std::vector<AnyValue> RawInputVec = Vector.asAggregate();
+ std::vector<const APFloat *> InputVec;
+ InputVec.reserve(RawInputVec.size());
+ transform(
+ RawInputVec, std::back_inserter(InputVec),
+ [](const AnyValue &V) -> const APFloat * { return &V.asFloat(); });
+ return applyNaNPropagation(FRes, InputVec);
+ }
+ return AnyValue::poison();
+ }
+ case Intrinsic::vector_reduce_fmax:
+ case Intrinsic::vector_reduce_fmin: {
+ const auto DenormMode = getCurrentDenormalMode(RetTy);
+ const auto &Vector = Args[0].asAggregate();
+ std::optional<APFloat> Res;
+ SmallVector<APFloat, 16> InputFloats;
+ std::vector<const APFloat *> InputVec;
----------------
dtcxzyw wrote:
Use SmallVector
https://github.com/llvm/llvm-project/pull/196034
More information about the llvm-commits
mailing list