[llvm] [KnownBits] Add KnownBits::makeConstantRange to determine the known bits from a pair of unsigned lo/hi bound values (PR #107080)

via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 3 09:32:20 PDT 2024


================
@@ -750,6 +750,21 @@ static KnownBits computeForSatAddSub(bool Add, bool Signed,
   return Res;
 }
 
+KnownBits KnownBits::makeInclusiveRange(const APInt &Lower,
+                                        const APInt &Upper) {
+  assert(Lower.getBitWidth() == Upper.getBitWidth() && "Bitwidth mismatch");
+  assert(Lower.ule(Upper) && "Constant range mismatch");
+
+  KnownBits Known = KnownBits::makeConstant(Lower);
+  if (std::optional<unsigned> DifferentBit =
+          APIntOps::GetMostSignificantDifferentBit(Lower, Upper)) {
+    Known.Zero.clearLowBits(*DifferentBit + 1);
+    Known.One.clearLowBits(*DifferentBit + 1);
+  }
----------------
goldsteinn wrote:

Can this be implemented as just: `KnownBits::makeConstant(Lower).intersectWith(KnownBits::makeConstant(Upper))?`

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


More information about the llvm-commits mailing list