[llvm] [llvm] `APFloat`: Query `hasNanOrInf` from semantics (PR #116158)

Matthias Springer via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 02:41:33 PST 2024


================
@@ -1127,19 +1129,11 @@ class APFloat : public APFloatBase {
   /// \param Semantics - type float semantics
   static APFloat getAllOnesValue(const fltSemantics &Semantics);
 
-  /// Returns true if the given semantics supports either NaN or Infinity.
+  /// Returns true if the given semantics supports NaN or Infinity.
   ///
   /// \param Sem - type float semantics
   static bool hasNanOrInf(const fltSemantics &Sem) {
-    switch (SemanticsToEnum(Sem)) {
-    default:
-      return true;
-    // Below Semantics do not support {NaN or Inf}
-    case APFloat::S_Float6E3M2FN:
-    case APFloat::S_Float6E2M3FN:
-    case APFloat::S_Float4E2M1FN:
-      return false;
-    }
----------------
matthias-springer wrote:

Or maybe even remove it entirely? Users can call `semanticsHasNan` and `semanticsHasInf` instead. The only usage that I see in MLIR is in `APFloatTest.cpp`.

Do you know if the test is actually correct? (I think you wrote that code initially.)
```c++
if (APFloat::hasNanOrInf(Semantics)) {
  EXPECT_FALSE(APFloat::getInf(Semantics, false).isSmallestNormalized());
  EXPECT_FALSE(APFloat::getInf(Semantics, true).isSmallestNormalized());

  EXPECT_FALSE(APFloat::getQNaN(Semantics).isSmallestNormalized());
  EXPECT_FALSE(APFloat::getSNaN(Semantics).isSmallestNormalized());
}
```

https://github.com/llvm/llvm-project/pull/116158


More information about the llvm-commits mailing list