https://github.com/zahiraam updated https://github.com/llvm/llvm-project/pull/107598
>From 0763f8d25194e18a040d4cd4cde7c88b6fccbb44 Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat <zahira.ammarguel...@intel.com> Date: Fri, 6 Sep 2024 08:01:25 -0700 Subject: [PATCH 1/3] Don't emit int TBAA metadata on more complex FP math libcalls. --- clang/lib/CodeGen/CGBuiltin.cpp | 15 +++++++-- .../test/CodeGen/complex-math-libcalls-tbaa.c | 31 +++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 clang/test/CodeGen/complex-math-libcalls-tbaa.c diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index e4d169d2ad6030..a84c9ca4be8a72 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -699,9 +699,20 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *FD, bool ConstWithoutErrnoAndExceptions = Context.BuiltinInfo.isConstWithoutErrnoAndExceptions(BuiltinID); // Restrict to target with errno, for example, MacOS doesn't set errno. - // TODO: Support builtin function with complex type returned, eg: cacosh + bool CallWithPointerArgsOrPointerReturnType = false; + if (Call.isScalar()) { + if (CallBase *CB = dyn_cast<CallBase>(Call.getScalarVal())) { + for (Value *A : CB->args()) + if (A->getType()->isPointerTy()) + CallWithPointerArgsOrPointerReturnType = true; + CallWithPointerArgsOrPointerReturnType = + CallWithPointerArgsOrPointerReturnType || + CB->getFunctionType()->getReturnType()->isPointerTy(); + } + } if (ConstWithoutErrnoAndExceptions && CGF.CGM.getLangOpts().MathErrno && - !CGF.Builder.getIsFPConstrained() && Call.isScalar()) { + !CGF.Builder.getIsFPConstrained() && Call.isScalar() && + !CallWithPointerArgsOrPointerReturnType) { // Emit "int" TBAA metadata on FP math libcalls. clang::QualType IntTy = Context.IntTy; TBAAAccessInfo TBAAInfo = CGF.CGM.getTBAAAccessInfo(IntTy); diff --git a/clang/test/CodeGen/complex-math-libcalls-tbaa.c b/clang/test/CodeGen/complex-math-libcalls-tbaa.c new file mode 100644 index 00000000000000..957dae6361b6f6 --- /dev/null +++ b/clang/test/CodeGen/complex-math-libcalls-tbaa.c @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple x86_64-unknown-unknown -o - %s | FileCheck %s -check-prefixes=CHECK +// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple x86_64-pc-win64 -o - %s | FileCheck %s -check-prefixes=CHECK +// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple i686-unknown-unknown -o - %s | FileCheck %s -check-prefixes=CHECK +// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple powerpc-unknown-unknown -o - %s | FileCheck %s -check-prefixes=CHECK-PPC +// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple armv7-none-linux-gnueabi -o - %s | FileCheck %s -check-prefixes=CHECK-TBAA,TBAA +// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple armv7-none-linux-gnueabihf -o - %s | FileCheck %s -check-prefixes=CHECK-ARM,TBAA +// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple thumbv7k-apple-watchos2.0 -o - -target-abi aapcs16 %s | FileCheck %s -check-prefixes=CHECK-THUMB,TBAA +// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple aarch64-unknown-unknown -o - %s | FileCheck %s -check-prefixes=CHECK-AARCH,TBAA +// RUN: %clang_cc1 %s -O3 -fmath-errno -emit-llvm -triple spir -o - %s | FileCheck %s -check-prefixes=CHECK-SPIR + +_Complex long double foo() { + _Complex long double cld; + long double v2 = __builtin_cargl(cld); + _Complex long double tmp = v2 * cld; + return tmp; +} +// CHECK: tail call x86_fp80 @cargl(ptr noundef nonnull byval({ {{.*}}, {{.*}} }) +// CHECK-PPC: tail call ppc_fp128 @cargl(ptr noundef nonnull byval({ ppc_fp128, ppc_fp128 }) +// CHECK-TBAA: tail call double @cargl([2 x i64] noundef undef) #[[ATTR1:[0-9]+]], !tbaa [[TBAA3:![0-9]+]] + +// CHECK-ARM: tail call double @cargl({ double, double } noundef undef) #[[ATTR1:[0-9]+]], !tbaa [[TBAA3:![0-9]+]] + +// CHECK-THUMB: tail call double @cargl([2 x double] noundef undef) #[[ATTR1:[0-9]+]], !tbaa [[TBAA3:![0-9]+]] + +// CHECK-AARCH: tail call fp128 @cargl([2 x fp128] noundef alignstack(16) undef) #[[ATTR1:[0-9]+]], !tbaa [[TBAA3:![0-9]+]] + +// CHECK-SPIR: tail call spir_func double @cargl(ptr noundef nonnull byval({ {{.*}}, {{.*}} }) + +// TBAA: [[TBAA3]] = !{[[META4:![0-9]+]], [[META4]], i64 0} +// TBAA: [[META4]] = !{!"int", [[META5:![0-9]+]], i64 0} +// TBAA: [[META5]] = !{!"omnipotent char", [[META6:![0-9]+]], i64 0} >From 358407997bee2c218bfc3a7e11704fd3191b8abb Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat <zahira.ammarguel...@intel.com> Date: Fri, 6 Sep 2024 08:19:17 -0700 Subject: [PATCH 2/3] Fix format. --- clang/lib/CodeGen/CGBuiltin.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index a84c9ca4be8a72..3b9d994041ecab 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -706,8 +706,8 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *FD, if (A->getType()->isPointerTy()) CallWithPointerArgsOrPointerReturnType = true; CallWithPointerArgsOrPointerReturnType = - CallWithPointerArgsOrPointerReturnType || - CB->getFunctionType()->getReturnType()->isPointerTy(); + CallWithPointerArgsOrPointerReturnType || + CB->getFunctionType()->getReturnType()->isPointerTy(); } } if (ConstWithoutErrnoAndExceptions && CGF.CGM.getLangOpts().MathErrno && >From 72d939befeea47c609de5bfc3850c7376a6e5865 Mon Sep 17 00:00:00 2001 From: Zahira Ammarguellat <zahira.ammarguel...@intel.com> Date: Fri, 6 Sep 2024 11:55:30 -0700 Subject: [PATCH 3/3] Added fix to the failed LIT tests. --- clang/lib/CodeGen/CGBuiltin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 3b9d994041ecab..ed8a977c8088ab 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -700,7 +700,7 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *FD, Context.BuiltinInfo.isConstWithoutErrnoAndExceptions(BuiltinID); // Restrict to target with errno, for example, MacOS doesn't set errno. bool CallWithPointerArgsOrPointerReturnType = false; - if (Call.isScalar()) { + if (Call.isScalar() && Call.getScalarVal()) { if (CallBase *CB = dyn_cast<CallBase>(Call.getScalarVal())) { for (Value *A : CB->args()) if (A->getType()->isPointerTy()) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits