@@ -1419,9 +1419,12 @@ static void computeKnownBitsFromOperator(const Operator *I,
1419
1419
// If this is a shift recurrence, we know the bits being shifted in.
1420
1420
// We can combine that with information about the start value of the
1421
1421
// recurrence to conclude facts about the result.
1422
- if ((Opcode == Instruction::LShr || Opcode == Instruction::AShr ||
1423
- Opcode == Instruction::Shl) &&
1424
- BO->getOperand (0 ) == I) {
1422
+ switch (Opcode) {
1423
+ case Instruction::LShr:
1424
+ case Instruction::AShr:
1425
+ case Instruction::Shl: {
1426
+ if (BO->getOperand (0 ) != I)
1427
+ break ;
1425
1428
1426
1429
// We have matched a recurrence of the form:
1427
1430
// %iv = [R, %entry], [%iv.next, %backedge]
@@ -1449,17 +1452,18 @@ static void computeKnownBitsFromOperator(const Operator *I,
1449
1452
Known.Zero .setHighBits (Known2.countMinLeadingZeros ());
1450
1453
Known.One .setHighBits (Known2.countMinLeadingOnes ());
1451
1454
break ;
1452
- };
1455
+ }
1456
+ break ;
1453
1457
}
1454
1458
1455
1459
// Check for operations that have the property that if
1456
1460
// both their operands have low zero bits, the result
1457
1461
// will have low zero bits.
1458
- if (Opcode == Instruction::Add ||
1459
- Opcode == Instruction::Sub ||
1460
- Opcode == Instruction::And ||
1461
- Opcode == Instruction::Or ||
1462
- Opcode == Instruction::Mul) {
1462
+ case Instruction::Add:
1463
+ case Instruction::Sub:
1464
+ case Instruction::And:
1465
+ case Instruction::Or:
1466
+ case Instruction::Mul: {
1463
1467
// Change the context instruction to the "edge" that flows into the
1464
1468
// phi. This is important because that is where the value is actually
1465
1469
// "evaluated" even though it is used later somewhere else. (see also
@@ -1484,38 +1488,51 @@ static void computeKnownBitsFromOperator(const Operator *I,
1484
1488
Known3.countMinTrailingZeros ()));
1485
1489
1486
1490
auto *OverflowOp = dyn_cast<OverflowingBinaryOperator>(BO);
1487
- if (OverflowOp && Q.IIQ .hasNoSignedWrap (OverflowOp)) {
1488
- // If initial value of recurrence is nonnegative, and we are adding
1489
- // a nonnegative number with nsw, the result can only be nonnegative
1490
- // or poison value regardless of the number of times we execute the
1491
- // add in phi recurrence. If initial value is negative and we are
1492
- // adding a negative number with nsw, the result can only be
1493
- // negative or poison value. Similar arguments apply to sub and mul.
1494
- //
1495
- // (add non-negative, non-negative) --> non-negative
1496
- // (add negative, negative) --> negative
1497
- if (Opcode == Instruction::Add) {
1498
- if (Known2.isNonNegative () && Known3.isNonNegative ())
1499
- Known.makeNonNegative ();
1500
- else if (Known2.isNegative () && Known3.isNegative ())
1501
- Known.makeNegative ();
1502
- }
1491
+ if (!OverflowOp || !Q.IIQ .hasNoSignedWrap (OverflowOp))
1492
+ break ;
1503
1493
1504
- // (sub nsw non-negative, negative) --> non-negative
1505
- // (sub nsw negative, non-negative) --> negative
1506
- else if (Opcode == Instruction::Sub && BO->getOperand (0 ) == I) {
1507
- if (Known2.isNonNegative () && Known3.isNegative ())
1508
- Known.makeNonNegative ();
1509
- else if (Known2.isNegative () && Known3.isNonNegative ())
1510
- Known.makeNegative ();
1511
- }
1494
+ switch (Opcode) {
1495
+ // If initial value of recurrence is nonnegative, and we are adding
1496
+ // a nonnegative number with nsw, the result can only be nonnegative
1497
+ // or poison value regardless of the number of times we execute the
1498
+ // add in phi recurrence. If initial value is negative and we are
1499
+ // adding a negative number with nsw, the result can only be
1500
+ // negative or poison value. Similar arguments apply to sub and mul.
1501
+ //
1502
+ // (add non-negative, non-negative) --> non-negative
1503
+ // (add negative, negative) --> negative
1504
+ case Instruction::Add: {
1505
+ if (Known2.isNonNegative () && Known3.isNonNegative ())
1506
+ Known.makeNonNegative ();
1507
+ else if (Known2.isNegative () && Known3.isNegative ())
1508
+ Known.makeNegative ();
1509
+ break ;
1510
+ }
1512
1511
1513
- // (mul nsw non-negative, non-negative) --> non-negative
1514
- else if (Opcode == Instruction::Mul && Known2.isNonNegative () &&
1515
- Known3.isNonNegative ())
1512
+ // (sub nsw non-negative, negative) --> non-negative
1513
+ // (sub nsw negative, non-negative) --> negative
1514
+ case Instruction::Sub: {
1515
+ if (BO->getOperand (0 ) != I)
1516
+ break ;
1517
+ if (Known2.isNonNegative () && Known3.isNegative ())
1516
1518
Known.makeNonNegative ();
1519
+ else if (Known2.isNegative () && Known3.isNonNegative ())
1520
+ Known.makeNegative ();
1521
+ break ;
1517
1522
}
1518
1523
1524
+ // (mul nsw non-negative, non-negative) --> non-negative
1525
+ case Instruction::Mul:
1526
+ if (Known2.isNonNegative () && Known3.isNonNegative ())
1527
+ Known.makeNonNegative ();
1528
+ break ;
1529
+
1530
+ default :
1531
+ break ;
1532
+ }
1533
+ break ;
1534
+ }
1535
+ default :
1519
1536
break ;
1520
1537
}
1521
1538
}
0 commit comments