[PATCH] D115969: [Support] improve known bits analysis for leading zeros of multiply

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 19 05:50:59 PST 2021


spatel added a reviewer: craig.topper.
spatel added inline comments.


================
Comment at: llvm/lib/Support/KnownBits.cpp:433
+  unsigned LeadZ = std::max(UMaxLZ, BitWidth) - BitWidth;
   assert(LeadZ <= BitWidth && "More zeros than bits?");
 
----------------
RKSimon wrote:
> I'm not certain, but this assert (and the max() feeding it) doesn't look quite right - please can you double check it?
I think it's correct (otherwise, the exhaustive unit tests for mul should find an error).
As an example, try a 4-bit mul -- 0??? * 00?? :
1. Max wide product: 0000_0111 * 0000_0011 = 0001_0101 (7 * 3 = 21) 
2. Leading zeros of wide max product = 3
3. Leading zeros of actual result = max(3, 4) - 4 = 0 (there are no LZ in case of overflow)

But this does suggest a more efficient implementation (and possibly easier to read) - use "umul_ov" instead of widening. 
Let me update and see if that looks better.


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

https://reviews.llvm.org/D115969



More information about the llvm-commits mailing list