Skip to content

Commit

Permalink
[NFC][SupportTests] Adjust UnsignedDivideUsingMagic() for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
LebedevRI committed Dec 25, 2022
1 parent 2656572 commit 012afbb
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions llvm/unittests/Support/DivisionByConstantTest.cpp
Expand Up @@ -102,9 +102,7 @@ APInt UnsignedDivideUsingMagic(APInt Numerator, APInt Divisor,
UnsignedDivisionByConstantInfo Magics) {
unsigned Bits = Numerator.getBitWidth();

bool UseNPQ = false;
unsigned PreShift = 0, PostShift = 0;

unsigned PreShift = 0;
if (AllowEvenDivisorOptimization) {
// If the divisor is even, we can avoid using the expensive fixup by
// shifting the divided value upfront.
Expand All @@ -117,18 +115,22 @@ APInt UnsignedDivideUsingMagic(APInt Numerator, APInt Divisor,
}
}

unsigned PostShift = 0;
bool UseNPQ = false;
if (!Magics.IsAdd || Divisor.isOne()) {
assert(Magics.ShiftAmount < Divisor.getBitWidth() &&
"We shouldn't generate an undefined shift!");
PostShift = Magics.ShiftAmount;
UseNPQ = false;
} else {
PostShift = Magics.ShiftAmount - 1;
assert(PostShift < Divisor.getBitWidth() &&
"We shouldn't generate an undefined shift!");
UseNPQ = true;
}

APInt NPQFactor =
UseNPQ ? APInt::getOneBitSet(Bits, Bits - 1) : APInt::getZero(Bits);
UseNPQ ? APInt::getSignedMinValue(Bits) : APInt::getZero(Bits);

APInt Q = Numerator.lshr(PreShift);

Expand Down

0 comments on commit 012afbb

Please sign in to comment.