[clang] [clang] constexpr built-in fma function. (PR #113020)

Timm Baeder via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 19 00:31:44 PDT 2024


================
@@ -15314,6 +15314,22 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
       Result.changeSign();
     return true;
 
+  case Builtin::BI__builtin_fma:
+  case Builtin::BI__builtin_fmaf:
+  case Builtin::BI__builtin_fmal:
+  case Builtin::BI__builtin_fmaf128: {
+    APFloat Y(0.), Z(0.);
+    if (!EvaluateFloat(E->getArg(0), Result, Info) ||
+        !EvaluateFloat(E->getArg(1), Y, Info) ||
+        !EvaluateFloat(E->getArg(2), Z, Info))
+      return false;
+
+    llvm::RoundingMode RM = getActiveRoundingMode(Info, E);
+    Result.multiply(Y, RM);
+    Result.add(Z, RM);
----------------
tbaederr wrote:

Shouldn't we check the status they return? And shouldn't this use `APFloat::fusedMultiplyAdd()`?

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


More information about the cfe-commits mailing list