[llvm] [AMDGPU] Use correct number of bits needed for div/rem shrinking (PR #80622)

via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 05:03:06 PST 2024


================
@@ -1213,7 +1213,10 @@ Value *AMDGPUCodeGenPrepareImpl::expandDivRem24(IRBuilder<> &Builder,
                                                 BinaryOperator &I, Value *Num,
                                                 Value *Den, bool IsDiv,
                                                 bool IsSigned) const {
-  int DivBits = getDivNumBits(I, Num, Den, 9, IsSigned);
+  unsigned SSBits = Num->getType()->getScalarSizeInBits();
+  // If Num bits <= 24, assume 0 signbits.
+  unsigned AtLeast = (SSBits <= 24) ? 0 : (SSBits - 24);
----------------
choikwa wrote:

It depends on the type of Num. The faulty path arose from Num being i64 and AtLeast being 9, which meant that it permit integer dividend with up to 55 used bits to fall into path which assumed only 24. After this change, AtLeast should get 64-24=40 bits for i64 as Num's type, meaning only 24 used bits should now fall into expandDivRem24.

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


More information about the llvm-commits mailing list