[PATCH] D151540: [KnownBits] Add fast-path for shl with unknown shift amount

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 26 04:13:52 PDT 2023


nikic marked 2 inline comments as done.
nikic added inline comments.


================
Comment at: llvm/lib/Support/KnownBits.cpp:178-202
     if (NUW) {
       if (ShiftedOutOne)
         // One bit has been shifted out.
         return std::nullopt;
       if (ShiftAmt != 0)
         // NUW means we can assume anything shifted out was a zero.
         ShiftedOutZero = true;
----------------
foad wrote:
> Do we still need all this logic now that you have determined the max shift amount in advance?
Indeed, we can drop the entire poison handling here now.


================
Comment at: llvm/lib/Support/KnownBits.cpp:223-225
+  if (isPowerOf2_32(BitWidth))
+    MaxValue &= APInt::getLowBitsSet(BitWidth, Log2_32(BitWidth));
+  unsigned MaxShiftAmount = MaxValue.getLimitedValue(BitWidth - 1);
----------------
foad wrote:
> Since power-of-2 is the normal case it might be faster to handle it without constructing another APInt.
Done. I've put it in a function, because I expect we'll want to adjust the other shift operators to match...


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151540/new/

https://reviews.llvm.org/D151540



More information about the llvm-commits mailing list