https://github.com/vfdff created 
https://github.com/llvm/llvm-project/pull/100302

Follow PR96025, except expf, more FP math libcalls in libm should also be 
supported.

Fix https://github.com/llvm/llvm-project/issues/86635

>From c750234674531788ee26958954a5f9a6b59ea866 Mon Sep 17 00:00:00 2001
From: zhongyunde 00443407 <zhongyu...@huawei.com>
Date: Tue, 23 Jul 2024 23:10:42 -0400
Subject: [PATCH] [clang codegen] Emit int TBAA metadata on more FP math
 libcalls

Follow PR96025, except expf, more FP math libcalls in libm
should also be supported.

Fix https://github.com/llvm/llvm-project/issues/86635
---
 clang/lib/CodeGen/CGBuiltin.cpp | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a0d03b87ccdc9..a9696ebe61e3a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -692,23 +692,22 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const 
FunctionDecl *FD,
   RValue Call =
       CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
 
-  // Check the supported intrinsic.
+  ASTContext &Context = CGF.getContext();
   if (unsigned BuiltinID = FD->getBuiltinID()) {
     auto IsErrnoIntrinsic = [&]() -> unsigned {
-      switch (BuiltinID) {
-      case Builtin::BIexpf:
-      case Builtin::BI__builtin_expf:
-      case Builtin::BI__builtin_expf128:
+      // Check whether a FP math builtin function, such as BI__builtin_expf
+      QualType ResultTy = FD->getReturnType();
+      bool IsMathLibCall =
+          Context.BuiltinInfo.isLibFunction(BuiltinID) ||
+          Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID);
+      if (IsMathLibCall && CGF.ConvertType(ResultTy)->isFloatingPointTy())
         return true;
-      }
-      // TODO: support more FP math libcalls
       return false;
     }();
 
     // Restrict to target with errno, for example, MacOS doesn't set errno.
     if (IsErrnoIntrinsic && CGF.CGM.getLangOpts().MathErrno &&
         !CGF.Builder.getIsFPConstrained()) {
-      ASTContext &Context = CGF.getContext();
       // Emit "int" TBAA metadata on FP math libcalls.
       clang::QualType IntTy = Context.IntTy;
       TBAAAccessInfo TBAAInfo = CGF.CGM.getTBAAAccessInfo(IntTy);

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to