[llvm] [KnownBits] Add reduceUMin/reduceUMax support (PR #211310)

via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 23 07:32:12 PDT 2026


================
@@ -873,6 +873,50 @@ KnownBits KnownBits::reduceAdd(unsigned NumElts) const {
   return Result;
 }
 
+KnownBits KnownBits::reduceUMin(unsigned NumElts) const {
+  if (NumElts == 0)
+    return KnownBits(getBitWidth());
+
+  unsigned BitWidth = getBitWidth();
+  KnownBits Result(BitWidth);
+
+  if (isConstant())
+    // If all elements are the same constant, the result is that constant.
+    return KnownBits::makeConstant(getConstant());
+
+  // Selects one element, so any leading 0s or 1s shared by all
+  // elements stay in the result.
+  if (isNonNegative()) {
+    Result.Zero.setHighBits(countMinLeadingZeros());
+  } else if (isNegative()) {
+    Result.One.setHighBits(countMinLeadingOnes());
+  }
+
+  return Result;
+}
+
+KnownBits KnownBits::reduceUMax(unsigned NumElts) const {
+  if (NumElts == 0)
+    return KnownBits(getBitWidth());
+
+  unsigned BitWidth = getBitWidth();
+  KnownBits Result(BitWidth);
----------------
MohamedAbdullahi14 wrote:

Done

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


More information about the llvm-commits mailing list