[llvm] [AMDGPU] Be more careful about using expandDivRem24 (PR #201186)

via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 5 05:34:11 PDT 2026


================
@@ -1353,7 +1364,17 @@ Value *AMDGPUCodeGenPrepareImpl::shrinkDivRem64(IRBuilder<> &Builder,
     return nullptr;
 
   Value *Narrowed = nullptr;
-  if (NumDivBits <= 24) {
+  // v_rcp_f32(float(X)) can have an error of 1 ulp.
+  // This can cause expandDivRem24Impl to sometimes calculate Y/X incorrectly
+  // when abs(Y)>0x800000.
+  // For example,
+  // (0xbf2758/0xbf2759) erroneously produces 1 instead of 0.
+  // (0xe3170d/0x000c32) erroneously produces 4767 instead of 4766.
+  //
+  // Note that for NumDivBits==24 && IsSigned, Y is in the range
+  // [-0x800000:0x7FFFFF]. abs(Y) is at most
+  // 0x800000 so it cannot hit this issue.
----------------
LU-JOHN wrote:

Updated PR description.

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


More information about the llvm-commits mailing list