[PATCH] D33154: [APInt] Add early outs for a division by 1 to udiv/urem/udivrem
Phabricator via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 12 14:59:10 PDT 2017
This revision was automatically updated to reflect the committed changes.
Closed by commit rL302953: [APInt] Add early outs for a division by 1 to udiv/urem/udivrem (authored by ctopper).
Changed prior to commit:
https://reviews.llvm.org/D33154?vs=98844&id=98852#toc
Repository:
rL LLVM
https://reviews.llvm.org/D33154
Files:
llvm/trunk/lib/Support/APInt.cpp
Index: llvm/trunk/lib/Support/APInt.cpp
===================================================================
--- llvm/trunk/lib/Support/APInt.cpp
+++ llvm/trunk/lib/Support/APInt.cpp
@@ -1565,14 +1565,18 @@
}
// Get some facts about the LHS and RHS number of bits and words
- unsigned rhsWords = getNumWords(RHS.getActiveBits());
- assert(rhsWords && "Divided by zero???");
unsigned lhsWords = getNumWords(getActiveBits());
+ unsigned rhsBits = RHS.getActiveBits();
+ unsigned rhsWords = getNumWords(rhsBits);
+ assert(rhsWords && "Divided by zero???");
// Deal with some degenerate cases
if (!lhsWords)
// 0 / X ===> 0
return APInt(BitWidth, 0);
+ if (rhsBits == 1)
+ // X / 1 ===> X
+ return *this;
if (lhsWords < rhsWords || this->ult(RHS))
// X / Y ===> 0, iff X < Y
return APInt(BitWidth, 0);
@@ -1611,13 +1615,17 @@
unsigned lhsWords = getNumWords(getActiveBits());
// Get some facts about the RHS
- unsigned rhsWords = getNumWords(RHS.getActiveBits());
+ unsigned rhsBits = RHS.getActiveBits();
+ unsigned rhsWords = getNumWords(rhsBits);
assert(rhsWords && "Performing remainder operation by zero ???");
// Check the degenerate cases
if (lhsWords == 0)
// 0 % Y ===> 0
return APInt(BitWidth, 0);
+ if (rhsBits == 1)
+ // X % 1 ===> 0
+ return APInt(BitWidth, 0);
if (lhsWords < rhsWords || this->ult(RHS))
// X % Y ===> X, iff X < Y
return *this;
@@ -1662,7 +1670,8 @@
// Get some size facts about the dividend and divisor
unsigned lhsWords = getNumWords(LHS.getActiveBits());
- unsigned rhsWords = getNumWords(RHS.getActiveBits());
+ unsigned rhsBits = RHS.getActiveBits();
+ unsigned rhsWords = getNumWords(rhsBits);
assert(rhsWords && "Performing divrem operation by zero ???");
// Check the degenerate cases
@@ -1672,6 +1681,11 @@
return;
}
+ if (rhsBits == 1) {
+ Quotient = LHS; // X / 1 ===> X
+ Remainder = 0; // X % 1 ===> 0
+ }
+
if (lhsWords < rhsWords || LHS.ult(RHS)) {
Remainder = LHS; // X % Y ===> X, iff X < Y
Quotient = 0; // X / Y ===> 0, iff X < Y
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33154.98852.patch
Type: text/x-patch
Size: 2183 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170512/b5ec9add/attachment-0001.bin>
More information about the llvm-commits
mailing list