llvm.org GIT mirror llvm / 5a71fb6
[APInt] Add early outs for a division by 1 to udiv/urem/udivrem We already counted the number of bits in the RHS so its pretty cheap to just check if the RHS is 1. Differential Revision: https://reviews.llvm.org/D33154 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302953 91177308-0d34-0410-b5e6-96231b3b80d8 Craig Topper 3 years ago
1 changed file(s) with 18 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
15641564 }
15651565
15661566 // Get some facts about the LHS and RHS number of bits and words
1567 unsigned rhsWords = getNumWords(RHS.getActiveBits());
1567 unsigned lhsWords = getNumWords(getActiveBits());
1568 unsigned rhsBits = RHS.getActiveBits();
1569 unsigned rhsWords = getNumWords(rhsBits);
15681570 assert(rhsWords && "Divided by zero???");
1569 unsigned lhsWords = getNumWords(getActiveBits());
15701571
15711572 // Deal with some degenerate cases
15721573 if (!lhsWords)
15731574 // 0 / X ===> 0
15741575 return APInt(BitWidth, 0);
1576 if (rhsBits == 1)
1577 // X / 1 ===> X
1578 return *this;
15751579 if (lhsWords < rhsWords || this->ult(RHS))
15761580 // X / Y ===> 0, iff X < Y
15771581 return APInt(BitWidth, 0);
16101614 unsigned lhsWords = getNumWords(getActiveBits());
16111615
16121616 // Get some facts about the RHS
1613 unsigned rhsWords = getNumWords(RHS.getActiveBits());
1617 unsigned rhsBits = RHS.getActiveBits();
1618 unsigned rhsWords = getNumWords(rhsBits);
16141619 assert(rhsWords && "Performing remainder operation by zero ???");
16151620
16161621 // Check the degenerate cases
16171622 if (lhsWords == 0)
16181623 // 0 % Y ===> 0
1624 return APInt(BitWidth, 0);
1625 if (rhsBits == 1)
1626 // X % 1 ===> 0
16191627 return APInt(BitWidth, 0);
16201628 if (lhsWords < rhsWords || this->ult(RHS))
16211629 // X % Y ===> X, iff X < Y
16611669
16621670 // Get some size facts about the dividend and divisor
16631671 unsigned lhsWords = getNumWords(LHS.getActiveBits());
1664 unsigned rhsWords = getNumWords(RHS.getActiveBits());
1672 unsigned rhsBits = RHS.getActiveBits();
1673 unsigned rhsWords = getNumWords(rhsBits);
16651674 assert(rhsWords && "Performing divrem operation by zero ???");
16661675
16671676 // Check the degenerate cases
16691678 Quotient = 0; // 0 / Y ===> 0
16701679 Remainder = 0; // 0 % Y ===> 0
16711680 return;
1681 }
1682
1683 if (rhsBits == 1) {
1684 Quotient = LHS; // X / 1 ===> X
1685 Remainder = 0; // X % 1 ===> 0
16721686 }
16731687
16741688 if (lhsWords < rhsWords || LHS.ult(RHS)) {