[llvm] [AMDGPU] Be more careful about using expandDivRem24 (PR #201186)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 5 05:33:57 PDT 2026
================
@@ -1062,7 +1062,18 @@ Value *AMDGPUCodeGenPrepareImpl::expandDivRem24(IRBuilder<> &Builder,
Value *Den, bool IsDiv,
bool IsSigned) const {
unsigned DivBits = getDivNumBits(I, Num, Den, 24, IsSigned);
- if (DivBits > 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 DivBits==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