[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:12:30 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:
(Though the assertion probably should be tweaked to `bitPosition **<=** BitWidth && (numBits + bitPosition) <= BitWidth`, to allow for extracting the zero high-order bits.)
https://github.com/llvm/llvm-project/pull/84254
More information about the llvm-commits
mailing list