|
54 | 54 | #include "llvm/Support/ErrorHandling.h" |
55 | 55 | #include "llvm/Support/KnownBits.h" |
56 | 56 | #include "llvm/Support/MathExtras.h" |
57 | | -#include "llvm/Support/float128.h" |
58 | 57 | #include <cassert> |
59 | 58 | #include <cerrno> |
60 | 59 | #include <cfenv> |
@@ -1742,7 +1741,7 @@ Constant *GetConstantFoldFPValue(double V, Type *Ty) { |
1742 | 1741 | llvm_unreachable("Can only constant fold half/float/double"); |
1743 | 1742 | } |
1744 | 1743 |
|
1745 | | -#if defined(HAS_IEE754_FLOAT128) |
| 1744 | +#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128) |
1746 | 1745 | Constant *GetConstantFoldFPValue128(float128 V, Type *Ty) { |
1747 | 1746 | if (Ty->isFP128Ty()) |
1748 | 1747 | return ConstantFP::get(Ty, V); |
@@ -1782,25 +1781,11 @@ Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V, |
1782 | 1781 | return GetConstantFoldFPValue(Result, Ty); |
1783 | 1782 | } |
1784 | 1783 |
|
1785 | | -#if defined(HAS_IEE754_FLOAT128) |
1786 | | -float128 ConvertToQuad(const APFloat &Apf) { |
1787 | | - APInt Api = Apf.bitcastToAPInt(); |
1788 | | - __uint128_t Uint128 = |
1789 | | - ((__uint128_t)Api.extractBitsAsZExtValue(64, 64) << 64) + |
1790 | | - Api.extractBitsAsZExtValue(64, 0); |
1791 | | - return llvm::bit_cast<float128>(Uint128); |
1792 | | -} |
1793 | | -#endif |
1794 | | - |
1795 | | -#if defined(HAS_IEE754_FLOAT128) |
| 1784 | +#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128) |
1796 | 1785 | Constant *ConstantFoldFP128(float128 (*NativeFP)(float128), const APFloat &V, |
1797 | 1786 | Type *Ty) { |
1798 | 1787 | llvm_fenv_clearexcept(); |
1799 | | - if (!V.isValidIEEEQuad()) |
1800 | | - return nullptr; |
1801 | | - |
1802 | | - float128 Result = NativeFP(ConvertToQuad(V)); |
1803 | | - |
| 1788 | + float128 Result = NativeFP(V.convertToQuad()); |
1804 | 1789 | if (llvm_fenv_testexcept()) { |
1805 | 1790 | llvm_fenv_clearexcept(); |
1806 | 1791 | return nullptr; |
@@ -2129,16 +2114,13 @@ static Constant *ConstantFoldScalarCall1(StringRef Name, |
2129 | 2114 | if (IntrinsicID == Intrinsic::canonicalize) |
2130 | 2115 | return constantFoldCanonicalize(Ty, Call, U); |
2131 | 2116 |
|
2132 | | -#if defined(HAS_IEE754_FLOAT128) |
| 2117 | +#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128) |
2133 | 2118 | if (Ty->isFP128Ty()) { |
2134 | 2119 | if (IntrinsicID == Intrinsic::log) { |
2135 | | - APFloat Value = Op->getValueAPF(); |
2136 | | - if (!Value.isValidIEEEQuad()) |
2137 | | - return nullptr; |
2138 | | - |
2139 | | - float128 Result = logf128(ConvertToQuad(Value)); |
| 2120 | + float128 Result = logf128(Op->getValueAPF().convertToQuad()); |
2140 | 2121 | return GetConstantFoldFPValue128(Result, Ty); |
2141 | 2122 | } |
| 2123 | + |
2142 | 2124 | LibFunc Fp128Func = NotLibFunc; |
2143 | 2125 | if (TLI && TLI->getLibFunc(Name, Fp128Func) && TLI->has(Fp128Func) && |
2144 | 2126 | Fp128Func == LibFunc_logl) |
|
0 commit comments