[llvm] [AMDGPU] Rework getDivNumBits API (PR #119768)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 6 01:18:22 PST 2025


jayfoad wrote:

> From debugging, I've observed that in shrinkDivRem64,
> 
> ```
> int NumDivBits = getDivNumBits(I, Num, Den, 32 /*AtLeast*/, IsSigned);
> if (NumDivBits == -1)                                                                                                                                                                                                     
>   return nullptr; 
> ```
> 
> It's rejecting the case where operands of Num or Den have <=32 DivNumBits but the SignNumBits are also <32. Such a case arises when i.e. Num or Den is ` %1 = ashr i48 %x, 24` or when source's number of scalar bits are in (64,32) since AtLeast logic only depends on number of sign bits.

Do I understand you correctly: the original code should have passed in `BitWidth - 32` instead of `32` for the `AtLeast` argument. And the name `shrinkDivRem64` is misleading since it is also used for (e.g.) 48-bit division.

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


More information about the llvm-commits mailing list