diff options
author | Matthew Devereau <matthew.devereau@arm.com> | 2024-04-18 10:19:01 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-18 10:19:01 +0100 |
commit | e90bc9cfd4d22c89dd993f62ede700ae25df49c5 (patch) | |
tree | 648e9fc005bddd1205464cbc11b5097be8ad9b86 /llvm/lib/Support/APFloat.cpp | |
parent | 63d8058ef50a3186b6b6a5db254f44673fea3d19 (diff) | |
download | llvm-e90bc9cfd4d22c89dd993f62ede700ae25df49c5.zip llvm-e90bc9cfd4d22c89dd993f62ede700ae25df49c5.tar.gz llvm-e90bc9cfd4d22c89dd993f62ede700ae25df49c5.tar.bz2 |
Constant Fold Logf128 calls (#84501)
This patch enables constant folding for 128 bit floating-point logf
calls. This is achieved by querying if the host system has the logf128()
symbol available with a CMake test. If so, replace the runtime call with
the compile time value returned from logf128.
Diffstat (limited to 'llvm/lib/Support/APFloat.cpp')
-rw-r--r-- | llvm/lib/Support/APFloat.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp index 0a4f5ac..30c85f5 100644 --- a/llvm/lib/Support/APFloat.cpp +++ b/llvm/lib/Support/APFloat.cpp @@ -3670,6 +3670,15 @@ double IEEEFloat::convertToDouble() const { return api.bitsToDouble(); } +#ifdef __FLOAT128__ +float128 IEEEFloat::convertToQuad() const { + assert(semantics == (const llvm::fltSemantics *)&semIEEEquad && + "Float semantics are not IEEEquads"); + APInt api = bitcastToAPInt(); + return api.bitsToQuad(); +} +#endif + /// Integer bit is explicit in this format. Intel hardware (387 and later) /// does not support these bit patterns: /// exponent = all 1's, integer bit 0, significand 0 ("pseudoinfinity") @@ -5265,6 +5274,21 @@ double APFloat::convertToDouble() const { return Temp.getIEEE().convertToDouble(); } +#ifdef __FLOAT128__ +float128 APFloat::convertToQuad() const { + if (&getSemantics() == (const llvm::fltSemantics *)&semIEEEquad) + return getIEEE().convertToQuad(); + assert(getSemantics().isRepresentableBy(semIEEEquad) && + "Float semantics is not representable by IEEEquad"); + APFloat Temp = *this; + bool LosesInfo; + opStatus St = Temp.convert(semIEEEquad, rmNearestTiesToEven, &LosesInfo); + assert(!(St & opInexact) && !LosesInfo && "Unexpected imprecision"); + (void)St; + return Temp.getIEEE().convertToQuad(); +} +#endif + float APFloat::convertToFloat() const { if (&getSemantics() == (const llvm::fltSemantics *)&semIEEEsingle) return getIEEE().convertToFloat(); |