[llvm] e377430 - [Support] Use APInt::udivrem in DivisionByConstantInfo. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 23 13:33:55 PST 2022
Author: Craig Topper
Date: 2022-12-23T13:33:40-08:00
New Revision: e3774304a2ead0ff2b6478fc30bf47d8e80de66d
URL: https://github.com/llvm/llvm-project/commit/e3774304a2ead0ff2b6478fc30bf47d8e80de66d
DIFF: https://github.com/llvm/llvm-project/commit/e3774304a2ead0ff2b6478fc30bf47d8e80de66d.diff
LOG: [Support] Use APInt::udivrem in DivisionByConstantInfo. NFC
Added:
Modified:
llvm/lib/Support/DivisionByConstantInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/DivisionByConstantInfo.cpp b/llvm/lib/Support/DivisionByConstantInfo.cpp
index 0a483ac2fd685..989f1f2ed219c 100644
--- a/llvm/lib/Support/DivisionByConstantInfo.cpp
+++ b/llvm/lib/Support/DivisionByConstantInfo.cpp
@@ -27,10 +27,11 @@ SignedDivisionByConstantInfo SignedDivisionByConstantInfo::get(const APInt &D) {
APInt T = SignedMin + (D.lshr(D.getBitWidth() - 1));
APInt ANC = T - 1 - T.urem(AD); // absolute value of NC
unsigned P = D.getBitWidth() - 1; // initialize P
- APInt Q1 = SignedMin.udiv(ANC); // initialize Q1 = 2P/abs(NC)
- APInt R1 = SignedMin - Q1 * ANC; // initialize R1 = rem(2P,abs(NC))
- APInt Q2 = SignedMin.udiv(AD); // initialize Q2 = 2P/abs(D)
- APInt R2 = SignedMin - Q2 * AD; // initialize R2 = rem(2P,abs(D))
+ APInt Q1, R1, Q2, R2;
+ // initialize Q1 = 2P/abs(NC); R1 = rem(2P,abs(NC))
+ APInt::udivrem(SignedMin, ANC, Q1, R1);
+ // initialize Q2 = 2P/abs(D); R2 = rem(2P,abs(D))
+ APInt::udivrem(SignedMin, AD, Q2, R2);
do {
P = P + 1;
Q1 <<= 1; // update Q1 = 2P/abs(NC)
@@ -75,10 +76,11 @@ UnsignedDivisionByConstantInfo::get(const APInt &D, unsigned LeadingZeros) {
APInt NC = AllOnes - (AllOnes - D).urem(D);
unsigned P = D.getBitWidth() - 1; // initialize P
- APInt Q1 = SignedMin.udiv(NC); // initialize Q1 = 2P/NC
- APInt R1 = SignedMin - Q1 * NC; // initialize R1 = rem(2P,NC)
- APInt Q2 = SignedMax.udiv(D); // initialize Q2 = (2P-1)/D
- APInt R2 = SignedMax - Q2 * D; // initialize R2 = rem((2P-1),D)
+ APInt Q1, R1, Q2, R2;
+ // initialize Q1 = 2P/NC; R1 = rem(2P,NC)
+ APInt::udivrem(SignedMin, NC, Q1, R1);
+ // initialize Q2 = (2P-1)/D; R2 = rem((2P-1),D)
+ APInt::udivrem(SignedMax, D, Q2, R2);
do {
P = P + 1;
if (R1.uge(NC - R1)) {
More information about the llvm-commits
mailing list