[llvm] [Valuetracking] Use all FPClasses ordering information for min/max (PR #199651)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 10 09:06:29 PDT 2026


================
@@ -173,3 +173,41 @@ bool llvm::cannotOrderStrictlyLessEq(FPClassTest LHS, FPClassTest RHS,
                                      bool OrderedZeroSign) {
   return cannotOrderStrictlyGreaterImpl(RHS, LHS, true, OrderedZeroSign);
 }
+
+FPClassTest llvm::orderedStrictlyLess(FPClassTest Mask, bool OrderedZeroSign) {
+  // Ignores NaN
+  Mask &= ~fcNan;
+  // Since the classes are ordered bits, we can get all classes which are
+  // smaller than all classes in Known by setting all trailing 0 bits to 1,
+  // and setting the other bits to 0.
+  // This is done by counting the number of trailing 0 bits and creating a
+  // mask based on that.
+  // For example: 0b1111000000 = fcPositive
+  //           -> 0b0000111111 = fcNegative | fcNan
+  FPClassTest NewMask = static_cast<FPClassTest>(
+      maskTrailingOnes<unsigned>(countr_zero<unsigned>(Mask)) & fcAllFlags);
+  // Remove NaNs
+  NewMask &= ~fcNan;
----------------
arsenm wrote:

```suggestion
  FPClassTest NewMask = static_cast<FPClassTest>(
      maskTrailingOnes<unsigned>(countr_zero<unsigned>(Mask)) & ~fcNan);
```
I think this works 

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


More information about the llvm-commits mailing list