@@ -1430,9 +1430,12 @@ static void computeKnownBitsFromOperator(const Operator *I,
1430
1430
// If this is a shift recurrence, we know the bits being shifted in.
1431
1431
// We can combine that with information about the start value of the
1432
1432
// recurrence to conclude facts about the result.
1433
- if ((Opcode == Instruction::LShr || Opcode == Instruction::AShr ||
1434
- Opcode == Instruction::Shl) &&
1435
- BO->getOperand (0 ) == I) {
1433
+ switch (Opcode) {
1434
+ case Instruction::LShr:
1435
+ case Instruction::AShr:
1436
+ case Instruction::Shl: {
1437
+ if (BO->getOperand (0 ) != I)
1438
+ break ;
1436
1439
1437
1440
// We have matched a recurrence of the form:
1438
1441
// %iv = [R, %entry], [%iv.next, %backedge]
@@ -1460,17 +1463,18 @@ static void computeKnownBitsFromOperator(const Operator *I,
1460
1463
Known.Zero .setHighBits (Known2.countMinLeadingZeros ());
1461
1464
Known.One .setHighBits (Known2.countMinLeadingOnes ());
1462
1465
break ;
1463
- };
1466
+ }
1467
+ break ;
1464
1468
}
1465
1469
1466
1470
// Check for operations that have the property that if
1467
1471
// both their operands have low zero bits, the result
1468
1472
// will have low zero bits.
1469
- if (Opcode == Instruction::Add ||
1470
- Opcode == Instruction::Sub ||
1471
- Opcode == Instruction::And ||
1472
- Opcode == Instruction::Or ||
1473
- Opcode == Instruction::Mul) {
1473
+ case Instruction::Add:
1474
+ case Instruction::Sub:
1475
+ case Instruction::And:
1476
+ case Instruction::Or:
1477
+ case Instruction::Mul: {
1474
1478
// Change the context instruction to the "edge" that flows into the
1475
1479
// phi. This is important because that is where the value is actually
1476
1480
// "evaluated" even though it is used later somewhere else. (see also
@@ -1495,37 +1499,52 @@ static void computeKnownBitsFromOperator(const Operator *I,
1495
1499
Known3.countMinTrailingZeros ()));
1496
1500
1497
1501
auto *OverflowOp = dyn_cast<OverflowingBinaryOperator>(BO);
1498
- if (OverflowOp && Q.IIQ .hasNoSignedWrap (OverflowOp)) {
1499
- // If initial value of recurrence is nonnegative, and we are adding
1500
- // a nonnegative number with nsw, the result can only be nonnegative
1501
- // or poison value regardless of the number of times we execute the
1502
- // add in phi recurrence. If initial value is negative and we are
1503
- // adding a negative number with nsw, the result can only be
1504
- // negative or poison value. Similar arguments apply to sub and mul.
1505
- //
1506
- // (add non-negative, non-negative) --> non-negative
1507
- // (add negative, negative) --> negative
1508
- if (Opcode == Instruction::Add) {
1509
- if (Known2.isNonNegative () && Known3.isNonNegative ())
1510
- Known.makeNonNegative ();
1511
- else if (Known2.isNegative () && Known3.isNegative ())
1512
- Known.makeNegative ();
1513
- }
1502
+ if (!OverflowOp || !Q.IIQ .hasNoSignedWrap (OverflowOp))
1503
+ break ;
1514
1504
1515
- // (sub nsw non-negative, negative) --> non-negative
1516
- // (sub nsw negative, non-negative) --> negative
1517
- else if (Opcode == Instruction::Sub && BO->getOperand (0 ) == I) {
1518
- if (Known2.isNonNegative () && Known3.isNegative ())
1519
- Known.makeNonNegative ();
1520
- else if (Known2.isNegative () && Known3.isNonNegative ())
1521
- Known.makeNegative ();
1522
- }
1505
+ switch (Opcode) {
1506
+ // If initial value of recurrence is nonnegative, and we are adding
1507
+ // a nonnegative number with nsw, the result can only be nonnegative
1508
+ // or poison value regardless of the number of times we execute the
1509
+ // add in phi recurrence. If initial value is negative and we are
1510
+ // adding a negative number with nsw, the result can only be
1511
+ // negative or poison value. Similar arguments apply to sub and mul.
1512
+ //
1513
+ // (add non-negative, non-negative) --> non-negative
1514
+ // (add negative, negative) --> negative
1515
+ case Instruction::Add: {
1516
+ if (Known2.isNonNegative () && Known3.isNonNegative ())
1517
+ Known.makeNonNegative ();
1518
+ else if (Known2.isNegative () && Known3.isNegative ())
1519
+ Known.makeNegative ();
1520
+ break ;
1521
+ }
1523
1522
1524
- // (mul nsw non-negative, non-negative) --> non-negative
1525
- else if (Opcode == Instruction::Mul && Known2.isNonNegative () &&
1526
- Known3.isNonNegative ())
1523
+ // (sub nsw non-negative, negative) --> non-negative
1524
+ // (sub nsw negative, non-negative) --> negative
1525
+ case Instruction::Sub: {
1526
+ if (BO->getOperand (0 ) != I)
1527
+ break ;
1528
+ if (Known2.isNonNegative () && Known3.isNegative ())
1527
1529
Known.makeNonNegative ();
1530
+ else if (Known2.isNegative () && Known3.isNonNegative ())
1531
+ Known.makeNegative ();
1532
+ break ;
1528
1533
}
1534
+
1535
+ // (mul nsw non-negative, non-negative) --> non-negative
1536
+ case Instruction::Mul:
1537
+ if (Known2.isNonNegative () && Known3.isNonNegative ())
1538
+ Known.makeNonNegative ();
1539
+ break ;
1540
+
1541
+ default :
1542
+ break ;
1543
+ }
1544
+ break ;
1545
+ }
1546
+ default :
1547
+ break ;
1529
1548
}
1530
1549
}
1531
1550
0 commit comments