Skip to content

Revert "[libc] Make FPUtils' rounding_mode.h functions constexpr." #150312

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

Closed
wants to merge 1 commit into from

Conversation

Kewen12
Copy link
Contributor

@Kewen12 Kewen12 commented Jul 23, 2025

Reverts #149167

The PR breaks some bots. Revert to unblock.

Our bot keeps failing: https://lab.llvm.org/buildbot/#/builders/10

@Kewen12 Kewen12 requested a review from lntue July 23, 2025 20:31
@llvmbot llvmbot added the libc label Jul 23, 2025
@llvmbot
Copy link
Member

llvmbot commented Jul 23, 2025

@llvm/pr-subscribers-libc

Author: None (Kewen12)

Changes

Reverts llvm/llvm-project#149167

The PR breaks some bots. Revert to unblock.

Our bot keeps failing: https://lab.llvm.org/buildbot/#/builders/10


Full diff: https://github.com/llvm/llvm-project/pull/150312.diff

2 Files Affected:

  • (modified) libc/src/__support/FPUtil/CMakeLists.txt (-1)
  • (modified) libc/src/__support/FPUtil/rounding_mode.h (+23-44)
diff --git a/libc/src/__support/FPUtil/CMakeLists.txt b/libc/src/__support/FPUtil/CMakeLists.txt
index 3024ac62b2951..372eba374d8eb 100644
--- a/libc/src/__support/FPUtil/CMakeLists.txt
+++ b/libc/src/__support/FPUtil/CMakeLists.txt
@@ -16,7 +16,6 @@ add_header_library(
     rounding_mode.h
   DEPENDS
     libc.hdr.fenv_macros
-    libc.src.__support.CPP.type_traits
     libc.src.__support.macros.attributes
     libc.src.__support.macros.properties.architectures
     libc.src.__support.macros.sanitizer
diff --git a/libc/src/__support/FPUtil/rounding_mode.h b/libc/src/__support/FPUtil/rounding_mode.h
index 4ee0a0b0490fc..bc66d09b94160 100644
--- a/libc/src/__support/FPUtil/rounding_mode.h
+++ b/libc/src/__support/FPUtil/rounding_mode.h
@@ -10,7 +10,6 @@
 #define LLVM_LIBC_SRC___SUPPORT_FPUTIL_ROUNDING_MODE_H
 
 #include "hdr/fenv_macros.h"
-#include "src/__support/CPP/type_traits.h"   // is_constant_evaluated
 #include "src/__support/macros/attributes.h" // LIBC_INLINE
 #include "src/__support/macros/config.h"
 
@@ -21,26 +20,18 @@ namespace fputil {
 // Using the following observation:
 //   1.0f + 2^-25 = 1.0f        for FE_TONEAREST, FE_DOWNWARD, FE_TOWARDZERO
 //                = 0x1.000002f for FE_UPWARD.
-LIBC_INLINE static constexpr bool fenv_is_round_up() {
-  if (cpp::is_constant_evaluated()) {
-    return false;
-  } else {
-    volatile float x = 0x1.0p-25f;
-    return (1.0f + x != 1.0f);
-  }
+LIBC_INLINE bool fenv_is_round_up() {
+  volatile float x = 0x1.0p-25f;
+  return (1.0f + x != 1.0f);
 }
 
 // Quick free-standing test whether fegetround() == FE_DOWNWARD.
 // Using the following observation:
 //   -1.0f - 2^-25 = -1.0f        for FE_TONEAREST, FE_UPWARD, FE_TOWARDZERO
 //                 = -0x1.000002f for FE_DOWNWARD.
-LIBC_INLINE static constexpr bool fenv_is_round_down() {
-  if (cpp::is_constant_evaluated()) {
-    return false;
-  } else {
-    volatile float x = 0x1.0p-25f;
-    return (-1.0f - x != -1.0f);
-  }
+LIBC_INLINE bool fenv_is_round_down() {
+  volatile float x = 0x1.0p-25f;
+  return (-1.0f - x != -1.0f);
 }
 
 // Quick free-standing test whether fegetround() == FE_TONEAREST.
@@ -49,14 +40,10 @@ LIBC_INLINE static constexpr bool fenv_is_round_down() {
 //                = 0x1.100002p0f  for FE_UPWARD,
 //   1.5f - 2^-24 = 1.5f           for FE_TONEAREST, FE_UPWARD
 //                = 0x1.0ffffep-1f for FE_DOWNWARD, FE_TOWARDZERO
-LIBC_INLINE static constexpr bool fenv_is_round_to_nearest() {
-  if (cpp::is_constant_evaluated()) {
-    return true;
-  } else {
-    volatile float x = 0x1.0p-24f;
-    float y = 1.5f + x;
-    return (y == 1.5f - x);
-  }
+LIBC_INLINE bool fenv_is_round_to_nearest() {
+  static volatile float x = 0x1.0p-24f;
+  float y = x;
+  return (1.5f + y == 1.5f - y);
 }
 
 // Quick free-standing test whether fegetround() == FE_TOWARDZERO.
@@ -69,31 +56,23 @@ LIBC_INLINE static constexpr bool fenv_is_round_to_nearest() {
 // (0x1.000002p0f + 2^-24) + (-1.0f - 2^-24) = 2^-23 for FE_TOWARDZERO
 //                                           = 2^-22 for FE_TONEAREST, FE_UPWARD
 //                                           = 0 for FE_DOWNWARD
-LIBC_INLINE static constexpr bool fenv_is_round_to_zero() {
-  if (cpp::is_constant_evaluated()) {
-    return false;
-  } else {
-    volatile float x = 0x1.0p-24f;
-    volatile float y = 0x1.000002p0f + x;
-    return (y + (-1.0f - x) == 0x1.0p-23f);
-  }
+LIBC_INLINE bool fenv_is_round_to_zero() {
+  static volatile float x = 0x1.0p-24f;
+  float y = x;
+  return ((0x1.000002p0f + y) + (-1.0f - y) == 0x1.0p-23f);
 }
 
 // Quick free standing get rounding mode based on the above observations.
-LIBC_INLINE static constexpr int quick_get_round() {
-  if (cpp::is_constant_evaluated()) {
-    return FE_TONEAREST;
-  } else {
-    volatile float x = 0x1.0p-24f;
-    volatile float y = 0x1.000002p0f + x;
-    float z = y + (-1.0f - x);
+LIBC_INLINE int quick_get_round() {
+  static volatile float x = 0x1.0p-24f;
+  float y = x;
+  float z = (0x1.000002p0f + y) + (-1.0f - y);
 
-    if (z == 0.0f)
-      return FE_DOWNWARD;
-    if (z == 0x1.0p-23f)
-      return FE_TOWARDZERO;
-    return (2.0f + x == 2.0f) ? FE_TONEAREST : FE_UPWARD;
-  }
+  if (z == 0.0f)
+    return FE_DOWNWARD;
+  if (z == 0x1.0p-23f)
+    return FE_TOWARDZERO;
+  return (2.0f + y == 2.0f) ? FE_TONEAREST : FE_UPWARD;
 }
 
 } // namespace fputil

@jhuber6
Copy link
Contributor

jhuber6 commented Jul 23, 2025

So #150264 didn't fix this?

@Kewen12
Copy link
Contributor Author

Kewen12 commented Jul 23, 2025

So #150264 didn't fix this?

Seems not. Still seeing the same error (rounding_mode.h) in the latest build. https://lab.llvm.org/buildbot/#/builders/10/builds/10053

@jhuber6
Copy link
Contributor

jhuber6 commented Jul 23, 2025

Pretty sure the issue with that one is it using an old GCC, it's supposed to work with other gcc, but that's why it didn't break the other bot AFAIK.

@Kewen12
Copy link
Contributor Author

Kewen12 commented Jul 23, 2025

Pretty sure the issue with that one is it using an old GCC, it's supposed to work with other gcc, but that's why it didn't break the other bot AFAIK.

I see. Any suggestions on how to fix this if we don't have to revert this pr.

@lntue
Copy link
Contributor

lntue commented Jul 23, 2025

Pretty sure the issue with that one is it using an old GCC, it's supposed to work with other gcc, but that's why it didn't break the other bot AFAIK.

I see. Any suggestions on how to fix this if we don't have to revert this pr.

Can you see if #150322 fixes the issue?

@Kewen12
Copy link
Contributor Author

Kewen12 commented Jul 23, 2025

Pretty sure the issue with that one is it using an old GCC, it's supposed to work with other gcc, but that's why it didn't break the other bot AFAIK.

I see. Any suggestions on how to fix this if we don't have to revert this pr.

Can you see if #150322 fixes the issue?

Thanks! let me try it locally.

@Kewen12
Copy link
Contributor Author

Kewen12 commented Jul 23, 2025

Issue has been resolved. Close this.

@Kewen12 Kewen12 closed this Jul 23, 2025
@lntue lntue deleted the revert-149167-rounding_mode branch July 24, 2025 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants