@@ -1426,16 +1426,23 @@ static void computeKnownBitsFromOperator(const Operator *I,
1426
1426
// this is sufficient to catch some interesting cases.
1427
1427
unsigned Opcode = BO->getOpcode ();
1428
1428
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.
1432
1429
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.
1433
1435
case Instruction::LShr:
1434
1436
case Instruction::AShr:
1435
- case Instruction::Shl: {
1437
+ case Instruction::Shl:
1438
+ case Instruction::UDiv:
1436
1439
if (BO->getOperand (0 ) != I)
1437
1440
break ;
1441
+ [[fallthrough]];
1438
1442
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: {
1439
1446
// We have matched a recurrence of the form:
1440
1447
// %iv = [R, %entry], [%iv.next, %backedge]
1441
1448
// %iv.next = shift_op %iv, L
@@ -1453,8 +1460,10 @@ static void computeKnownBitsFromOperator(const Operator *I,
1453
1460
Known.Zero .setLowBits (Known2.countMinTrailingZeros ());
1454
1461
break ;
1455
1462
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.
1458
1467
Known.Zero .setHighBits (Known2.countMinLeadingZeros ());
1459
1468
break ;
1460
1469
case Instruction::AShr:
@@ -1543,27 +1552,6 @@ static void computeKnownBitsFromOperator(const Operator *I,
1543
1552
break ;
1544
1553
}
1545
1554
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
-
1567
1555
default :
1568
1556
break ;
1569
1557
}
0 commit comments