[PATCH] D140636: [Support] Fix what I think is an off by 1 bug in UnsignedDivisionByConstantInfo.
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 29 09:43:02 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rG1490796dd28c: [Support] Fix what I think is an off by 1 bug in UnsignedDivisionByConstantInfo. (authored by craig.topper).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D140636/new/
https://reviews.llvm.org/D140636
Files:
llvm/lib/Support/DivisionByConstantInfo.cpp
Index: llvm/lib/Support/DivisionByConstantInfo.cpp
===================================================================
--- llvm/lib/Support/DivisionByConstantInfo.cpp
+++ llvm/lib/Support/DivisionByConstantInfo.cpp
@@ -82,7 +82,9 @@
APInt SignedMin = APInt::getSignedMinValue(D.getBitWidth());
APInt SignedMax = APInt::getSignedMaxValue(D.getBitWidth());
- APInt NC = AllOnes - (AllOnes - D).urem(D);
+ // Calculate NC, the largest dividend such that NC.urem(D) == D-1.
+ APInt NC = AllOnes - (AllOnes + 1 - D).urem(D);
+ assert(NC.urem(D) == D - 1 && "Unexpected NC value");
unsigned P = D.getBitWidth() - 1; // initialize P
APInt Q1, R1, Q2, R2;
// initialize Q1 = 2P/NC; R1 = rem(2P,NC)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140636.485623.patch
Type: text/x-patch
Size: 711 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221229/68bc4743/attachment.bin>
More information about the llvm-commits
mailing list