[clang] [TBAA] Emit int TBAA metadata on FP math libcalls (PR #96025)

via cfe-commits cfe-commits at lists.llvm.org
Sat Jun 22 02:07:56 PDT 2024


================
@@ -707,7 +707,34 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *FD,
                               const CallExpr *E, llvm::Constant *calleeValue) {
   CodeGenFunction::CGFPOptionsRAII FPOptsRAII(CGF, E);
   CGCallee callee = CGCallee::forDirect(calleeValue, GlobalDecl(FD));
-  return CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+  RValue Call =
+      CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
+
+  // Check the supported intrinsic.
+  if (unsigned BuiltinID = FD->getBuiltinID()) {
+    auto IntrinsicID = [&]() -> unsigned {
+      switch (BuiltinID) {
+      case Builtin::BIexpf:
+      case Builtin::BI__builtin_expf:
+      case Builtin::BI__builtin_expf128:
+        return true;
+      }
+      // TODO: support more FP math libcalls
+      return false;
+    }();
+
+    if (IntrinsicID) {
+      llvm::MDBuilder MDHelper(CGF.getLLVMContext());
+      MDNode *RootMD = CGF.CGM.getTBAARoot();
+      // Emit "int" TBAA metadata on FP math libcalls.
+      MDNode *AliasType = MDHelper.createTBAANode("int", RootMD);
----------------
vfdff wrote:

sorry, I don't find the metadata for "int". 

ps:I will update the **createTBAANode** into **createTBAAScalarTypeNode** according [switch from old TBAA format to the new struct-path aware TBAA format](https://discourse.llvm.org/t/dragonegg-switch-from-old-tbaa-format-to-the-new-struct-path-aware-tbaa-format/29448)

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


More information about the cfe-commits mailing list