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

Jay Foad via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 26 01:32:20 PDT 2023


foad accepted this revision.
foad added a comment.
This revision is now accepted and ready to land.

Looks nice.



================
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;
----------------
Do we still need all this logic now that you have determined the max shift amount in advance?


================
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);
----------------
Since power-of-2 is the normal case it might be faster to handle it without constructing another APInt.


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

https://reviews.llvm.org/D151540



More information about the llvm-commits mailing list