@@ -1678,9 +1678,9 @@ bool llvm::canConstantFoldCallTo(const CallBase *Call, const Function *F) {
1678
1678
Name == " floor" || Name == " floorf" ||
1679
1679
Name == " fmod" || Name == " fmodf" ;
1680
1680
case ' l' :
1681
- return Name == " log" || Name == " logf" ||
1682
- Name == " log2 " || Name == " log2f " ||
1683
- Name == " log10 " || Name == " log10f " ;
1681
+ return Name == " log" || Name == " logf" || Name == " log2 " ||
1682
+ Name == " log2f " || Name == " log10 " || Name == " log10f " ||
1683
+ Name == " logl " ;
1684
1684
case ' n' :
1685
1685
return Name == " nearbyint" || Name == " nearbyintf" ;
1686
1686
case ' p' :
@@ -1743,6 +1743,14 @@ Constant *GetConstantFoldFPValue(double V, Type *Ty) {
1743
1743
llvm_unreachable (" Can only constant fold half/float/double" );
1744
1744
}
1745
1745
1746
+ #if defined(HAS_IEE754_FLOAT128)
1747
+ Constant *GetConstantFoldFPValue128 (__float128 V, Type *Ty) {
1748
+ if (Ty->isFP128Ty ())
1749
+ return ConstantFP::get (Ty, V);
1750
+ llvm_unreachable (" Can only constant fold fp128" );
1751
+ }
1752
+ #endif
1753
+
1746
1754
// / Clear the floating-point exception state.
1747
1755
inline void llvm_fenv_clearexcept () {
1748
1756
#if defined(HAVE_FENV_H) && HAVE_DECL_FE_ALL_EXCEPT
@@ -1775,6 +1783,20 @@ Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V,
1775
1783
return GetConstantFoldFPValue (Result, Ty);
1776
1784
}
1777
1785
1786
+ #if defined(HAS_IEE754_FLOAT128)
1787
+ Constant *ConstantFoldFP128 (long double (*NativeFP)(long double ),
1788
+ const APFloat &V, Type *Ty) {
1789
+ llvm_fenv_clearexcept ();
1790
+ __float128 Result = NativeFP (V.convertToQuad ());
1791
+ if (llvm_fenv_testexcept ()) {
1792
+ llvm_fenv_clearexcept ();
1793
+ return nullptr ;
1794
+ }
1795
+
1796
+ return GetConstantFoldFPValue128 (Result, Ty);
1797
+ }
1798
+ #endif
1799
+
1778
1800
Constant *ConstantFoldBinaryFP (double (*NativeFP)(double , double ),
1779
1801
const APFloat &V, const APFloat &W, Type *Ty) {
1780
1802
llvm_fenv_clearexcept ();
@@ -2096,12 +2118,15 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
2096
2118
2097
2119
#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128)
2098
2120
if (Ty->isFP128Ty ()) {
2099
- switch (IntrinsicID) {
2100
- default :
2101
- return nullptr ;
2102
- case Intrinsic::log :
2103
- return ConstantFP::get (Ty, logf128 (Op->getValueAPF ().convertToQuad ()));
2121
+ if (IntrinsicID == Intrinsic::log ) {
2122
+ __float128 Result = logf128 (Op->getValueAPF ().convertToQuad ());
2123
+ return GetConstantFoldFPValue128 (Result, Ty);
2104
2124
}
2125
+
2126
+ LibFunc Fp128Func = NotLibFunc;
2127
+ if (TLI->getLibFunc (Name, Fp128Func) && TLI->has (Fp128Func) &&
2128
+ Fp128Func == LibFunc_logl)
2129
+ return ConstantFoldFP128 (logf128, Op->getValueAPF (), Ty);
2105
2130
}
2106
2131
#endif
2107
2132
@@ -2365,6 +2390,8 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
2365
2390
// TODO: What about hosts that lack a C99 library?
2366
2391
return ConstantFoldFP (log10 , APF, Ty);
2367
2392
break ;
2393
+ case LibFunc_logl:
2394
+ return nullptr ;
2368
2395
case LibFunc_nearbyint:
2369
2396
case LibFunc_nearbyintf:
2370
2397
case LibFunc_rint:
0 commit comments