[llvm] [KnownBits] Implement knownbits lshr/ashr with exact flag (PR #84254)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 7 09:10:06 PST 2024


================
@@ -516,6 +532,19 @@ TEST(KnownBitsTest, BinaryExhaustive) {
         return N1.lshr(N2);
       },
       checkOptimalityBinary, /* RefinePoisonToZero */ true);
+  testBinaryOpExhaustive(
+      [](const KnownBits &Known1, const KnownBits &Known2) {
+        return KnownBits::lshr(Known1, Known2, /*ShAmtNonZero=*/false,
+                               /*Exact=*/true);
+      },
+      [](const APInt &N1, const APInt &N2) -> std::optional<APInt> {
+        if (N2.uge(N2.getBitWidth()))
+          return std::nullopt;
+        if (!N2.isZero() && !N1.extractBits(N2.getZExtValue(), 0).isZero())
----------------
jayfoad wrote:

@goldsteinn huh? How does that assertion prevent calling it with `numBits == 0`?

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


More information about the llvm-commits mailing list