https://github.com/lei137 updated https://github.com/llvm/llvm-project/pull/75226
>From f38e709e414d1c9dae4f9d75f1decaf363bf9427 Mon Sep 17 00:00:00 2001 From: Lei Huang <l...@ca.ibm.com> Date: Tue, 12 Dec 2023 10:58:34 -0600 Subject: [PATCH 1/3] [PowerPC] Emit libcall to frexpl for calls to frexp(ppcDoublDouble) On Linux PPC call lib func ``frexpl`` for calls to ``frexp()`` for input of type PPCDoubleDouble. Fixes bug: https://github.com/llvm/llvm-project/issues/64426 --- clang/lib/CodeGen/CGBuiltin.cpp | 17 ++++++++++++++++- .../c.math/constexpr-cxx23-clang.pass.cpp | 6 ------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 353b7930b3c1ea..e733bbf8be8b71 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -137,6 +137,10 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, {Builtin::BI__builtin_modfl, "modf"}, }; + static SmallDenseMap<unsigned, StringRef, 4> PPCDoubleDoubleBuiltins{ + {Builtin::BI__builtin_frexpl, "frexpl"}, + }; + // If the builtin has been declared explicitly with an assembler label, // use the mangled name. This differs from the plain label on platforms // that prefix labels. @@ -149,6 +153,11 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad() && F128Builtins.contains(BuiltinID)) Name = F128Builtins[BuiltinID]; + else if (getTriple().isPPC() && getTriple().isOSLinux() && + &getTarget().getLongDoubleFormat() == + &llvm::APFloat::PPCDoubleDouble() && + PPCDoubleDoubleBuiltins.contains(BuiltinID)) + Name = PPCDoubleDoubleBuiltins[BuiltinID]; else if (getTriple().isOSAIX() && &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEdouble() && @@ -3410,9 +3419,15 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, { Src0->getType(), Src1->getType() }); return RValue::get(Builder.CreateCall(F, { Src0, Src1 })); } + case Builtin::BI__builtin_frexpl: { + auto &Triple = getTarget().getTriple(); + if (Triple.isPPC() && Triple.isOSLinux() && + &getTarget().getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble()) + break; + LLVM_FALLTHROUGH; + } case Builtin::BI__builtin_frexp: case Builtin::BI__builtin_frexpf: - case Builtin::BI__builtin_frexpl: case Builtin::BI__builtin_frexpf128: case Builtin::BI__builtin_frexpf16: return RValue::get(emitFrexpBuiltin(*this, E, Intrinsic::frexp)); diff --git a/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp b/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp index 31511064ce7ca5..a07260a34516f1 100644 --- a/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp +++ b/libcxx/test/libcxx/numerics/c.math/constexpr-cxx23-clang.pass.cpp @@ -58,15 +58,9 @@ int main(int, char**) { ASSERT_NOT_CONSTEXPR_CXX23(std::frexp(0.0f, &DummyInt) == 0.0f); ASSERT_NOT_CONSTEXPR_CXX23(std::frexp(0.0, &DummyInt) == 0.0); -//FIXME: currently linux powerpc does not support this expansion -// since 0.0L lowers to ppcf128 and special handling is required. -#if !defined(__LONG_DOUBLE_IBM128__) ASSERT_NOT_CONSTEXPR_CXX23(std::frexp(0.0L, &DummyInt) == 0.0L); -#endif ASSERT_NOT_CONSTEXPR_CXX23(std::frexpf(0.0f, &DummyInt) == 0.0f); -#if !defined(__LONG_DOUBLE_IBM128__) ASSERT_NOT_CONSTEXPR_CXX23(std::frexpl(0.0L, &DummyInt) == 0.0L); -#endif ASSERT_NOT_CONSTEXPR_CXX23(std::ilogb(1.0f) == 0); ASSERT_NOT_CONSTEXPR_CXX23(std::ilogb(1.0) == 0); >From 3065e1287b5be023e8e9bf85ff2b76d6c194f58c Mon Sep 17 00:00:00 2001 From: Lei Huang <l...@ca.ibm.com> Date: Thu, 14 Dec 2023 09:28:50 -0600 Subject: [PATCH 2/3] address Eli's review comments --- clang/lib/CodeGen/CGBuiltin.cpp | 15 ++++----------- clang/test/CodeGen/math-builtins-long.c | 2 +- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index e733bbf8be8b71..73df0ef99f853c 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -137,10 +137,6 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, {Builtin::BI__builtin_modfl, "modf"}, }; - static SmallDenseMap<unsigned, StringRef, 4> PPCDoubleDoubleBuiltins{ - {Builtin::BI__builtin_frexpl, "frexpl"}, - }; - // If the builtin has been declared explicitly with an assembler label, // use the mangled name. This differs from the plain label on platforms // that prefix labels. @@ -153,11 +149,6 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD, &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEquad() && F128Builtins.contains(BuiltinID)) Name = F128Builtins[BuiltinID]; - else if (getTriple().isPPC() && getTriple().isOSLinux() && - &getTarget().getLongDoubleFormat() == - &llvm::APFloat::PPCDoubleDouble() && - PPCDoubleDoubleBuiltins.contains(BuiltinID)) - Name = PPCDoubleDoubleBuiltins[BuiltinID]; else if (getTriple().isOSAIX() && &getTarget().getLongDoubleFormat() == &llvm::APFloat::IEEEdouble() && @@ -3420,8 +3411,10 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, return RValue::get(Builder.CreateCall(F, { Src0, Src1 })); } case Builtin::BI__builtin_frexpl: { - auto &Triple = getTarget().getTriple(); - if (Triple.isPPC() && Triple.isOSLinux() && + // Linux PPC will not be adding additional PPCDoubleDouble support. + // WIP to switch default to IEEE long double. Will emit libcall for + // frexpl instead of legalizing this type in the BE. + if (getTarget().getTriple().isPPC() && &getTarget().getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble()) break; LLVM_FALLTHROUGH; diff --git a/clang/test/CodeGen/math-builtins-long.c b/clang/test/CodeGen/math-builtins-long.c index f3c328dcbfcd7c..ad0d2122b597fa 100644 --- a/clang/test/CodeGen/math-builtins-long.c +++ b/clang/test/CodeGen/math-builtins-long.c @@ -35,7 +35,7 @@ void foo(long double f, long double *l, int *i, const char *c) { __builtin_fabsl(f); // F80: call { x86_fp80, i32 } @llvm.frexp.f80.i32(x86_fp80 %{{.+}}) - // PPC: call { ppc_fp128, i32 } @llvm.frexp.ppcf128.i32(ppc_fp128 %{{.+}}) + // PPC: call ppc_fp128 @frexpl(ppc_fp128 noundef %{{.+}}, ptr noundef %{{.+}}) // X86F128: call { fp128, i32 } @llvm.frexp.f128.i32(fp128 %{{.+}}) // PPCF128: call { fp128, i32 } @llvm.frexp.f128.i32(fp128 %{{.+}}) __builtin_frexpl(f,i); >From 763844026c622a1e94070d4448f5a1aa02173d92 Mon Sep 17 00:00:00 2001 From: Lei Huang <l...@ca.ibm.com> Date: Thu, 14 Dec 2023 11:38:59 -0600 Subject: [PATCH 3/3] fixup condition --- clang/lib/CodeGen/CGBuiltin.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 73df0ef99f853c..3327866d2b9623 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -3414,8 +3414,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, // Linux PPC will not be adding additional PPCDoubleDouble support. // WIP to switch default to IEEE long double. Will emit libcall for // frexpl instead of legalizing this type in the BE. - if (getTarget().getTriple().isPPC() && - &getTarget().getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble()) + if (&getTarget().getLongDoubleFormat() == &llvm::APFloat::PPCDoubleDouble()) break; LLVM_FALLTHROUGH; } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits