@@ -1426,16 +1426,23 @@ static void computeKnownBitsFromOperator(const Operator *I,
14261426 // this is sufficient to catch some interesting cases.
14271427 unsigned Opcode = BO->getOpcode ();
14281428
1429- // If this is a shift recurrence, we know the bits being shifted in.
1430- // We can combine that with information about the start value of the
1431- // recurrence to conclude facts about the result.
14321429 switch (Opcode) {
1430+ // If this is a shift recurrence, we know the bits being shifted in. We
1431+ // can combine that with information about the start value of the
1432+ // recurrence to conclude facts about the result. If this is a udiv
1433+ // recurrence, we know that the result can never exceed either the
1434+ // numerator or the start value, whichever is greater.
14331435 case Instruction::LShr:
14341436 case Instruction::AShr:
1435- case Instruction::Shl: {
1437+ case Instruction::Shl:
1438+ case Instruction::UDiv:
14361439 if (BO->getOperand (0 ) != I)
14371440 break ;
1441+ [[fallthrough]];
14381442
1443+ // For a urem recurrence, the result can never exceed the start value. The
1444+ // start value could either be the numerator or the denominator.
1445+ case Instruction::URem: {
14391446 // We have matched a recurrence of the form:
14401447 // %iv = [R, %entry], [%iv.next, %backedge]
14411448 // %iv.next = shift_op %iv, L
@@ -1453,8 +1460,10 @@ static void computeKnownBitsFromOperator(const Operator *I,
14531460 Known.Zero .setLowBits (Known2.countMinTrailingZeros ());
14541461 break ;
14551462 case Instruction::LShr:
1456- // A lshr recurrence will preserve the leading zeros of the
1457- // start value
1463+ case Instruction::UDiv:
1464+ case Instruction::URem:
1465+ // lshr, udiv, and urem recurrences will preserve the leading zeros of
1466+ // the start value.
14581467 Known.Zero .setHighBits (Known2.countMinLeadingZeros ());
14591468 break ;
14601469 case Instruction::AShr:
@@ -1543,27 +1552,6 @@ static void computeKnownBitsFromOperator(const Operator *I,
15431552 break ;
15441553 }
15451554
1546- case Instruction::UDiv:
1547- // For UDiv, the result can never exceed either the numerator, or the
1548- // start value, whichever is greater. The case where the PHI is not
1549- // the numerator of the UDiv is already handled by other code.
1550- if (BO->getOperand (0 ) != P)
1551- break ;
1552- [[fallthrough]];
1553-
1554- case Instruction::URem: {
1555- // For URem, the result can never exceed the start value.
1556- SimplifyQuery RecQ = Q.getWithoutCondContext ();
1557-
1558- unsigned OpNum = P->getOperand (0 ) == R ? 0 : 1 ;
1559- Instruction *RInst = P->getIncomingBlock (OpNum)->getTerminator ();
1560-
1561- RecQ.CxtI = RInst;
1562- computeKnownBits (R, DemandedElts, Known2, Depth + 1 , RecQ);
1563- Known.Zero .setHighBits (Known2.countMinLeadingZeros ());
1564- break ;
1565- }
1566-
15671555 default :
15681556 break ;
15691557 }
0 commit comments