@@ -1427,16 +1427,23 @@ static void computeKnownBitsFromOperator(const Operator *I,
1427
1427
// this is sufficient to catch some interesting cases.
1428
1428
unsigned Opcode = BO->getOpcode ();
1429
1429
1430
- // If this is a shift recurrence, we know the bits being shifted in.
1431
- // We can combine that with information about the start value of the
1432
- // recurrence to conclude facts about the result.
1433
1430
switch (Opcode) {
1431
+ // If this is a shift recurrence, we know the bits being shifted in. We
1432
+ // can combine that with information about the start value of the
1433
+ // recurrence to conclude facts about the result. If this is a udiv
1434
+ // recurrence, we know that the result can never exceed either the
1435
+ // numerator or the start value, whichever is greater.
1434
1436
case Instruction::LShr:
1435
1437
case Instruction::AShr:
1436
- case Instruction::Shl: {
1438
+ case Instruction::Shl:
1439
+ case Instruction::UDiv:
1437
1440
if (BO->getOperand (0 ) != I)
1438
1441
break ;
1442
+ [[fallthrough]];
1439
1443
1444
+ // For a urem recurrence, the result can never exceed the start value. The
1445
+ // start value could either be the numerator or the denominator.
1446
+ case Instruction::URem: {
1440
1447
// We have matched a recurrence of the form:
1441
1448
// %iv = [R, %entry], [%iv.next, %backedge]
1442
1449
// %iv.next = shift_op %iv, L
@@ -1454,8 +1461,10 @@ static void computeKnownBitsFromOperator(const Operator *I,
1454
1461
Known.Zero .setLowBits (Known2.countMinTrailingZeros ());
1455
1462
break ;
1456
1463
case Instruction::LShr:
1457
- // A lshr recurrence will preserve the leading zeros of the
1458
- // start value
1464
+ case Instruction::UDiv:
1465
+ case Instruction::URem:
1466
+ // lshr, udiv, and urem recurrences will preserve the leading zeros of
1467
+ // the start value.
1459
1468
Known.Zero .setHighBits (Known2.countMinLeadingZeros ());
1460
1469
break ;
1461
1470
case Instruction::AShr:
@@ -1544,27 +1553,6 @@ static void computeKnownBitsFromOperator(const Operator *I,
1544
1553
break ;
1545
1554
}
1546
1555
1547
- case Instruction::UDiv:
1548
- // For UDiv, the result can never exceed either the numerator, or the
1549
- // start value, whichever is greater. The case where the PHI is not
1550
- // the numerator of the UDiv is already handled by other code.
1551
- if (BO->getOperand (0 ) != P)
1552
- break ;
1553
- [[fallthrough]];
1554
-
1555
- case Instruction::URem: {
1556
- // For URem, the result can never exceed the start value.
1557
- SimplifyQuery RecQ = Q.getWithoutCondContext ();
1558
-
1559
- unsigned OpNum = P->getOperand (0 ) == R ? 0 : 1 ;
1560
- Instruction *RInst = P->getIncomingBlock (OpNum)->getTerminator ();
1561
-
1562
- RecQ.CxtI = RInst;
1563
- computeKnownBits (R, DemandedElts, Known2, Depth + 1 , RecQ);
1564
- Known.Zero .setHighBits (Known2.countMinLeadingZeros ());
1565
- break ;
1566
- }
1567
-
1568
1556
default :
1569
1557
break ;
1570
1558
}
0 commit comments