llvm.org GIT mirror
[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).
 1564 1564 } 1565 1565 1566 1566 // 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); 1568 1570 assert(rhsWords && "Divided by zero???"); 1569 unsigned lhsWords = getNumWords(getActiveBits()); 1570 1571 1571 1572 // Deal with some degenerate cases 1572 1573 if (!lhsWords) 1573 1574 // 0 / X ===> 0 1574 1575 return APInt(BitWidth, 0); 1576 if (rhsBits == 1) 1577 // X / 1 ===> X 1578 return *this; 1575 1579 if (lhsWords < rhsWords || this->ult(RHS)) 1576 1580 // X / Y ===> 0, iff X < Y 1577 1581 return APInt(BitWidth, 0); 1610 1614 unsigned lhsWords = getNumWords(getActiveBits()); 1611 1615 1612 1616 // Get some facts about the RHS 1613 unsigned rhsWords = getNumWords(RHS.getActiveBits());⏎ 1617 unsigned rhsBits = RHS.getActiveBits();⏎ 1618 unsigned rhsWords = getNumWords(rhsBits); 1614 1619 assert(rhsWords && "Performing remainder operation by zero ???"); 1615 1620 1616 1621 // Check the degenerate cases 1617 1622 if (lhsWords == 0) 1618 1623 // 0 % Y ===> 0 1624 return APInt(BitWidth, 0); 1625 if (rhsBits == 1) 1626 // X % 1 ===> 0 1619 1627 return APInt(BitWidth, 0); 1620 1628 if (lhsWords < rhsWords || this->ult(RHS)) 1621 1629 // X % Y ===> X, iff X < Y 1661 1669 1662 1670 // Get some size facts about the dividend and divisor 1663 1671 unsigned lhsWords = getNumWords(LHS.getActiveBits()); 1664 unsigned rhsWords = getNumWords(RHS.getActiveBits());⏎ 1672 unsigned rhsBits = RHS.getActiveBits();⏎ 1673 unsigned rhsWords = getNumWords(rhsBits); 1665 1674 assert(rhsWords && "Performing divrem operation by zero ???"); 1666 1675 1667 1676 // Check the degenerate cases 1669 1678 Quotient = 0; // 0 / Y ===> 0 1670 1679 Remainder = 0; // 0 % Y ===> 0 1671 1680 return; 1681 } 1682 1683 if (rhsBits == 1) { 1684 Quotient = LHS; // X / 1 ===> X 1685 Remainder = 0; // X % 1 ===> 0 1672 1686 } 1673 1687 1674 1688 if (lhsWords < rhsWords || LHS.ult(RHS)) {