-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable logf128 constant folding for hosts with 128bit long double #104929
Merged
+42
−75
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
#include "llvm/Support/ErrorHandling.h" | ||
#include "llvm/Support/KnownBits.h" | ||
#include "llvm/Support/MathExtras.h" | ||
#include "llvm/Support/float128.h" | ||
#include <cassert> | ||
#include <cerrno> | ||
#include <cfenv> | ||
|
@@ -1741,7 +1742,7 @@ Constant *GetConstantFoldFPValue(double V, Type *Ty) { | |
llvm_unreachable("Can only constant fold half/float/double"); | ||
} | ||
|
||
#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128) | ||
#if defined(HAS_IEE754_FLOAT128) | ||
Constant *GetConstantFoldFPValue128(float128 V, Type *Ty) { | ||
if (Ty->isFP128Ty()) | ||
return ConstantFP::get(Ty, V); | ||
|
@@ -1781,11 +1782,25 @@ Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V, | |
return GetConstantFoldFPValue(Result, Ty); | ||
} | ||
|
||
#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128) | ||
#if defined(HAS_IEE754_FLOAT128) | ||
float128 ConvertToQuad(const APFloat &Apf) { | ||
APInt Api = Apf.bitcastToAPInt(); | ||
__uint128_t Uint128 = | ||
((__uint128_t)Api.extractBitsAsZExtValue(64, 64) << 64) + | ||
Api.extractBitsAsZExtValue(64, 0); | ||
return llvm::bit_cast<float128>(Uint128); | ||
} | ||
#endif | ||
|
||
#if defined(HAS_IEE754_FLOAT128) | ||
Constant *ConstantFoldFP128(float128 (*NativeFP)(float128), const APFloat &V, | ||
Type *Ty) { | ||
llvm_fenv_clearexcept(); | ||
float128 Result = NativeFP(V.convertToQuad()); | ||
if (!V.isValidIEEEQuad()) | ||
return nullptr; | ||
|
||
float128 Result = NativeFP(ConvertToQuad(V)); | ||
|
||
if (llvm_fenv_testexcept()) { | ||
llvm_fenv_clearexcept(); | ||
return nullptr; | ||
|
@@ -2114,13 +2129,16 @@ static Constant *ConstantFoldScalarCall1(StringRef Name, | |
if (IntrinsicID == Intrinsic::canonicalize) | ||
return constantFoldCanonicalize(Ty, Call, U); | ||
|
||
#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128) | ||
#if defined(HAS_IEE754_FLOAT128) | ||
if (Ty->isFP128Ty()) { | ||
if (IntrinsicID == Intrinsic::log) { | ||
float128 Result = logf128(Op->getValueAPF().convertToQuad()); | ||
APFloat Value = Op->getValueAPF(); | ||
if (!Value.isValidIEEEQuad()) | ||
return nullptr; | ||
|
||
float128 Result = logf128(ConvertToQuad(Value)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return GetConstantFoldFPValue128(Result, Ty); | ||
} | ||
|
||
LibFunc Fp128Func = NotLibFunc; | ||
if (TLI->getLibFunc(Name, Fp128Func) && TLI->has(Fp128Func) && | ||
Fp128Func == LibFunc_logl) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this have a cmakedefine entry in llvm/Config/config.h.cmake instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was meant to always be enabled if available, and thus cmake would do a test and define the cmake variable LLVM_HAS_LOGF128 if the test passed. This patch has been reverted now, but what is likely to happen is this behaviour will be enabled by default, but be eligible to opt-out via a cmake definition which will have an entry in
llvm/Config/config.h.cmake