-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[libc] Prevent constant propagation for atanf(+-Inf) in gcc. #85733
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
Conversation
@llvm/pr-subscribers-libc Author: None (lntue) Changesgcc bot failures with Full diff: https://github.com/llvm/llvm-project/pull/85733.diff 1 Files Affected:
diff --git a/libc/src/math/generic/atanf.cpp b/libc/src/math/generic/atanf.cpp
index 69fd45ddd767e5..5f66ea52d0d7ae 100644
--- a/libc/src/math/generic/atanf.cpp
+++ b/libc/src/math/generic/atanf.cpp
@@ -37,8 +37,10 @@ LLVM_LIBC_FUNCTION(float, atanf, (float x)) {
double const_term = 0.0;
if (LIBC_UNLIKELY(x_abs >= 0x4180'0000)) {
// atan(+-Inf) = +-pi/2.
- if (x_bits.is_inf())
- return static_cast<float>(SIGNED_PI_OVER_2[sign.is_neg()]);
+ if (x_bits.is_inf()) {
+ volatile double sign_pi_over_2 = SIGNED_PI_OVER_2[sign.is_neg()];
+ return static_cast<float>(sign_pi_over_2);
+ }
if (x_bits.is_nan())
return x;
// x >= 16
|
A side question, what should be the best way to mark a value as nondeterministic (non constant)? |
So far I found using |
Is there something pertaining to rounding modes at runtime resulting in different values than the rounding used during constant propagation? |
As an example in this patch, casting double precision |
https://lemire.me/blog/2022/11/16/a-fast-function-to-check-your-floating-point-rounding-mode/ also recommends the use of Looks like Hans Boehm wrote a paper on this issue (C++26): https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2023/p2746r0.pdf There's an old clang PR that never landed for a pragma to adjust this behavior at compile time: https://reviews.llvm.org/D125625 You might want to speak with Hans and ask him what the current state of that proposal is. Another approach, would it be possible to have another array similar to |
Yes, we have similar utilities implemented for free-standing rounding mode detection: https://github.com/llvm/llvm-project/blob/main/libc/src/__support/FPUtil/rounding_mode.h
From my understanding, Hans proposed to have a set of directed-rounding operations, and migrating people to use that instead of manipulating the rounding environment. Then
Yes, I saw that pragma is used in many places, but unfortunately it's not portable to clang.
+1
To have an array of pre-rounded results, we still need to access the current rounding mode at runtime, which leads to either Another way to do it is to use |
) gcc bot failures with `atanf(+-Inf)`: https://lab.llvm.org/buildbot/#/builders/250/builds/20331/steps/8/logs/stdio
gcc bot failures with
atanf(+-Inf)
: https://lab.llvm.org/buildbot/#/builders/250/builds/20331/steps/8/logs/stdio