[clang] [llvm] [C++23] [CLANG] Adding C++23 constexpr math functions: fmin, fmax and frexp. (PR #88978)

Hubert Tong via llvm-commits llvm-commits at lists.llvm.org
Thu May 16 15:49:01 PDT 2024


================
@@ -14574,9 +14574,17 @@ bool FloatExprEvaluator::VisitCallExpr(const CallExpr *E) {
   default:
     return false;
 
+  case Builtin::BI__builtin_frexpl:
+    // AIX library function `frexpl` has 'long double' type and not
+    // PPCDoubleDouble type. To make sure we generate the right value, don't
+    // constant evaluate it and instead defer to a libcall.
+    if (Info.Ctx.getTargetInfo().getTriple().isPPC() &&
+        (&Info.Ctx.getTargetInfo().getLongDoubleFormat() !=
+         &llvm::APFloat::PPCDoubleDouble()))
+      return false;
+    LLVM_FALLTHROUGH;
   case Builtin::BI__builtin_frexp:
-  case Builtin::BI__builtin_frexpf:
-  case Builtin::BI__builtin_frexpl: {
+  case Builtin::BI__builtin_frexpf: {
----------------
hubert-reinterpretcast wrote:

> With this change (special casing frexpl for AIX) the IR produced is: `call { double, i32 } @llvm.frexp.f64.i32(double 1.234500e+02)`
> 
> without this change the IR is: `store double 0.000000e+00, ptr %returnValue, align 8`
> 
> This doesn't seem correct to me.

Ignoring considerations around storing to `DummyInt`, the original test code was:
```
  returnValue = __builtin_frexpl(0.0L, &DummyInt);
```
I don't know where the `123.45` came from. That the result is zero for an input of zero is correct.

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


More information about the llvm-commits mailing list