@@ -1091,23 +1091,23 @@ static void computeKnownBitsFromOperator(const Operator *I,
1091
1091
break ;
1092
1092
}
1093
1093
case Instruction::UDiv: {
1094
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1095
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1094
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1095
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1096
1096
Known =
1097
1097
KnownBits::udiv (Known, Known2, Q.IIQ .isExact (cast<BinaryOperator>(I)));
1098
1098
break ;
1099
1099
}
1100
1100
case Instruction::SDiv: {
1101
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1102
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1101
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1102
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1103
1103
Known =
1104
1104
KnownBits::sdiv (Known, Known2, Q.IIQ .isExact (cast<BinaryOperator>(I)));
1105
1105
break ;
1106
1106
}
1107
1107
case Instruction::Select: {
1108
1108
auto ComputeForArm = [&](Value *Arm, bool Invert) {
1109
1109
KnownBits Res (Known.getBitWidth ());
1110
- computeKnownBits (Arm, Res, Depth + 1 , Q);
1110
+ computeKnownBits (Arm, DemandedElts, Res, Depth + 1 , Q);
1111
1111
adjustKnownBitsForSelectArm (Res, I->getOperand (0 ), Arm, Invert, Depth, Q);
1112
1112
return Res;
1113
1113
};
@@ -1142,7 +1142,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
1142
1142
1143
1143
assert (SrcBitWidth && " SrcBitWidth can't be zero" );
1144
1144
Known = Known.anyextOrTrunc (SrcBitWidth);
1145
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1145
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1146
1146
if (auto *Inst = dyn_cast<PossiblyNonNegInst>(I);
1147
1147
Inst && Inst->hasNonNeg () && !Known.isNegative ())
1148
1148
Known.makeNonNegative ();
@@ -1164,7 +1164,8 @@ static void computeKnownBitsFromOperator(const Operator *I,
1164
1164
if (match (I, m_ElementWiseBitCast (m_Value (V))) &&
1165
1165
V->getType ()->isFPOrFPVectorTy ()) {
1166
1166
Type *FPType = V->getType ()->getScalarType ();
1167
- KnownFPClass Result = computeKnownFPClass (V, fcAllFlags, Depth + 1 , Q);
1167
+ KnownFPClass Result =
1168
+ computeKnownFPClass (V, DemandedElts, fcAllFlags, Depth + 1 , Q);
1168
1169
FPClassTest FPClasses = Result.KnownFPClasses ;
1169
1170
1170
1171
// TODO: Treat it as zero/poison if the use of I is unreachable.
@@ -1245,7 +1246,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
1245
1246
unsigned SrcBitWidth = I->getOperand (0 )->getType ()->getScalarSizeInBits ();
1246
1247
1247
1248
Known = Known.trunc (SrcBitWidth);
1248
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1249
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1249
1250
// If the sign bit of the input is known set or clear, then we know the
1250
1251
// top bits of the result.
1251
1252
Known = Known.sext (BitWidth);
@@ -1305,14 +1306,14 @@ static void computeKnownBitsFromOperator(const Operator *I,
1305
1306
break ;
1306
1307
}
1307
1308
case Instruction::SRem:
1308
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1309
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1309
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1310
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1310
1311
Known = KnownBits::srem (Known, Known2);
1311
1312
break ;
1312
1313
1313
1314
case Instruction::URem:
1314
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1315
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1315
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1316
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1316
1317
Known = KnownBits::urem (Known, Known2);
1317
1318
break ;
1318
1319
case Instruction::Alloca:
@@ -1465,17 +1466,17 @@ static void computeKnownBitsFromOperator(const Operator *I,
1465
1466
1466
1467
unsigned OpNum = P->getOperand (0 ) == R ? 0 : 1 ;
1467
1468
Instruction *RInst = P->getIncomingBlock (OpNum)->getTerminator ();
1468
- Instruction *LInst = P->getIncomingBlock (1 - OpNum)->getTerminator ();
1469
+ Instruction *LInst = P->getIncomingBlock (1 - OpNum)->getTerminator ();
1469
1470
1470
1471
// Ok, we have a PHI of the form L op= R. Check for low
1471
1472
// zero bits.
1472
1473
RecQ.CxtI = RInst;
1473
- computeKnownBits (R, Known2, Depth + 1 , RecQ);
1474
+ computeKnownBits (R, DemandedElts, Known2, Depth + 1 , RecQ);
1474
1475
1475
1476
// We need to take the minimum number of known bits
1476
1477
KnownBits Known3 (BitWidth);
1477
1478
RecQ.CxtI = LInst;
1478
- computeKnownBits (L, Known3, Depth + 1 , RecQ);
1479
+ computeKnownBits (L, DemandedElts, Known3, Depth + 1 , RecQ);
1479
1480
1480
1481
Known.Zero .setLowBits (std::min (Known2.countMinTrailingZeros (),
1481
1482
Known3.countMinTrailingZeros ()));
@@ -1548,7 +1549,8 @@ static void computeKnownBitsFromOperator(const Operator *I,
1548
1549
// want to waste time spinning around in loops.
1549
1550
// TODO: See if we can base recursion limiter on number of incoming phi
1550
1551
// edges so we don't overly clamp analysis.
1551
- computeKnownBits (IncValue, Known2, MaxAnalysisRecursionDepth - 1 , RecQ);
1552
+ computeKnownBits (IncValue, DemandedElts, Known2,
1553
+ MaxAnalysisRecursionDepth - 1 , RecQ);
1552
1554
1553
1555
// See if we can further use a conditional branch into the phi
1554
1556
// to help us determine the range of the value.
@@ -1619,9 +1621,10 @@ static void computeKnownBitsFromOperator(const Operator *I,
1619
1621
}
1620
1622
if (const IntrinsicInst *II = dyn_cast<IntrinsicInst>(I)) {
1621
1623
switch (II->getIntrinsicID ()) {
1622
- default : break ;
1624
+ default :
1625
+ break ;
1623
1626
case Intrinsic::abs: {
1624
- computeKnownBits (I->getOperand (0 ), Known2, Depth + 1 , Q);
1627
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known2, Depth + 1 , Q);
1625
1628
bool IntMinIsPoison = match (II->getArgOperand (1 ), m_One ());
1626
1629
Known = Known2.abs (IntMinIsPoison);
1627
1630
break ;
@@ -1637,7 +1640,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
1637
1640
Known.One |= Known2.One .byteSwap ();
1638
1641
break ;
1639
1642
case Intrinsic::ctlz: {
1640
- computeKnownBits (I->getOperand (0 ), Known2, Depth + 1 , Q);
1643
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known2, Depth + 1 , Q);
1641
1644
// If we have a known 1, its position is our upper bound.
1642
1645
unsigned PossibleLZ = Known2.countMaxLeadingZeros ();
1643
1646
// If this call is poison for 0 input, the result will be less than 2^n.
@@ -1648,7 +1651,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
1648
1651
break ;
1649
1652
}
1650
1653
case Intrinsic::cttz: {
1651
- computeKnownBits (I->getOperand (0 ), Known2, Depth + 1 , Q);
1654
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known2, Depth + 1 , Q);
1652
1655
// If we have a known 1, its position is our upper bound.
1653
1656
unsigned PossibleTZ = Known2.countMaxTrailingZeros ();
1654
1657
// If this call is poison for 0 input, the result will be less than 2^n.
@@ -1659,7 +1662,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
1659
1662
break ;
1660
1663
}
1661
1664
case Intrinsic::ctpop: {
1662
- computeKnownBits (I->getOperand (0 ), Known2, Depth + 1 , Q);
1665
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known2, Depth + 1 , Q);
1663
1666
// We can bound the space the count needs. Also, bits known to be zero
1664
1667
// can't contribute to the population.
1665
1668
unsigned BitsPossiblySet = Known2.countMaxPopulation ();
@@ -1681,8 +1684,8 @@ static void computeKnownBitsFromOperator(const Operator *I,
1681
1684
ShiftAmt = BitWidth - ShiftAmt;
1682
1685
1683
1686
KnownBits Known3 (BitWidth);
1684
- computeKnownBits (I->getOperand (0 ), Known2, Depth + 1 , Q);
1685
- computeKnownBits (I->getOperand (1 ), Known3, Depth + 1 , Q);
1687
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known2, Depth + 1 , Q);
1688
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known3, Depth + 1 , Q);
1686
1689
1687
1690
Known.Zero =
1688
1691
Known2.Zero .shl (ShiftAmt) | Known3.Zero .lshr (BitWidth - ShiftAmt);
@@ -1691,27 +1694,30 @@ static void computeKnownBitsFromOperator(const Operator *I,
1691
1694
break ;
1692
1695
}
1693
1696
case Intrinsic::uadd_sat:
1694
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1695
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1697
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1698
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1696
1699
Known = KnownBits::uadd_sat (Known, Known2);
1697
1700
break ;
1698
1701
case Intrinsic::usub_sat:
1699
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1700
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1702
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1703
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1701
1704
Known = KnownBits::usub_sat (Known, Known2);
1702
1705
break ;
1703
1706
case Intrinsic::sadd_sat:
1704
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1705
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1707
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1708
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1706
1709
Known = KnownBits::sadd_sat (Known, Known2);
1707
1710
break ;
1708
1711
case Intrinsic::ssub_sat:
1709
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1710
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1712
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1713
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1711
1714
Known = KnownBits::ssub_sat (Known, Known2);
1712
1715
break ;
1713
1716
// Vec reverse preserves bits from input vec.
1714
1717
case Intrinsic::vector_reverse:
1718
+ computeKnownBits (I->getOperand (0 ), DemandedElts.reverseBits (), Known,
1719
+ Depth + 1 , Q);
1720
+ break ;
1715
1721
// for min/max/and/or reduce, any bit common to each element in the
1716
1722
// input vec is set in the output.
1717
1723
case Intrinsic::vector_reduce_and:
@@ -1738,31 +1744,31 @@ static void computeKnownBitsFromOperator(const Operator *I,
1738
1744
break ;
1739
1745
}
1740
1746
case Intrinsic::umin:
1741
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1742
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1747
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1748
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1743
1749
Known = KnownBits::umin (Known, Known2);
1744
1750
break ;
1745
1751
case Intrinsic::umax:
1746
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1747
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1752
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1753
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1748
1754
Known = KnownBits::umax (Known, Known2);
1749
1755
break ;
1750
1756
case Intrinsic::smin:
1751
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1752
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1757
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1758
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1753
1759
Known = KnownBits::smin (Known, Known2);
1754
1760
break ;
1755
1761
case Intrinsic::smax:
1756
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1757
- computeKnownBits (I->getOperand (1 ), Known2, Depth + 1 , Q);
1762
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1763
+ computeKnownBits (I->getOperand (1 ), DemandedElts, Known2, Depth + 1 , Q);
1758
1764
Known = KnownBits::smax (Known, Known2);
1759
1765
break ;
1760
1766
case Intrinsic::ptrmask: {
1761
- computeKnownBits (I->getOperand (0 ), Known, Depth + 1 , Q);
1767
+ computeKnownBits (I->getOperand (0 ), DemandedElts, Known, Depth + 1 , Q);
1762
1768
1763
1769
const Value *Mask = I->getOperand (1 );
1764
1770
Known2 = KnownBits (Mask->getType ()->getScalarSizeInBits ());
1765
- computeKnownBits (Mask, Known2, Depth + 1 , Q);
1771
+ computeKnownBits (Mask, DemandedElts, Known2, Depth + 1 , Q);
1766
1772
// TODO: 1-extend would be more precise.
1767
1773
Known &= Known2.anyextOrTrunc (BitWidth);
1768
1774
break ;
0 commit comments