mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 19:23:23 +01:00
[KnownBits] Add KnownBits::makeConstant helper. NFCI.
Helper for cases where we need to create a KnownBits from a (fully known) constant value.
This commit is contained in:
parent
27b1315bd4
commit
b22745774c
@ -250,6 +250,11 @@ public:
|
||||
return getBitWidth() - Zero.countPopulation();
|
||||
}
|
||||
|
||||
/// Create known bits from a known constant.
|
||||
static KnownBits makeConstant(const APInt &C) {
|
||||
return KnownBits(~C, C);
|
||||
}
|
||||
|
||||
/// Compute known bits common to LHS and RHS.
|
||||
static KnownBits commonBits(const KnownBits &LHS, const KnownBits &RHS) {
|
||||
return KnownBits(LHS.Zero & RHS.Zero, LHS.One & RHS.One);
|
||||
|
@ -1223,10 +1223,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
|
||||
case Instruction::Shl: {
|
||||
bool NSW = Q.IIQ.hasNoSignedWrap(cast<OverflowingBinaryOperator>(I));
|
||||
auto KF = [NSW](const KnownBits &KnownShiftVal, unsigned ShiftAmt) {
|
||||
APInt ShiftAmtV(KnownShiftVal.getBitWidth(), ShiftAmt);
|
||||
KnownBits KnownShiftAmt;
|
||||
KnownShiftAmt.One = ShiftAmtV;
|
||||
KnownShiftAmt.Zero = ~ShiftAmtV;
|
||||
KnownBits KnownShiftAmt = KnownBits::makeConstant(APInt(32, ShiftAmt));
|
||||
KnownBits Result = KnownBits::shl(KnownShiftVal, KnownShiftAmt);
|
||||
// If this shift has "nsw" keyword, then the result is either a poison
|
||||
// value or has the same sign bit as the first operand.
|
||||
@ -1244,10 +1241,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
|
||||
}
|
||||
case Instruction::LShr: {
|
||||
auto KF = [](const KnownBits &KnownShiftVal, unsigned ShiftAmt) {
|
||||
APInt ShiftAmtV(KnownShiftVal.getBitWidth(), ShiftAmt);
|
||||
KnownBits KnownShiftAmt;
|
||||
KnownShiftAmt.One = ShiftAmtV;
|
||||
KnownShiftAmt.Zero = ~ShiftAmtV;
|
||||
KnownBits KnownShiftAmt = KnownBits::makeConstant(APInt(32, ShiftAmt));
|
||||
return KnownBits::lshr(KnownShiftVal, KnownShiftAmt);
|
||||
};
|
||||
computeKnownBitsFromShiftOperator(I, DemandedElts, Known, Known2, Depth, Q,
|
||||
@ -1256,10 +1250,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
|
||||
}
|
||||
case Instruction::AShr: {
|
||||
auto KF = [](const KnownBits &KnownShiftVal, unsigned ShiftAmt) {
|
||||
APInt ShiftAmtV(KnownShiftVal.getBitWidth(), ShiftAmt);
|
||||
KnownBits KnownShiftAmt;
|
||||
KnownShiftAmt.One = ShiftAmtV;
|
||||
KnownShiftAmt.Zero = ~ShiftAmtV;
|
||||
KnownBits KnownShiftAmt = KnownBits::makeConstant(APInt(32, ShiftAmt));
|
||||
return KnownBits::ashr(KnownShiftVal, KnownShiftAmt);
|
||||
};
|
||||
computeKnownBitsFromShiftOperator(I, DemandedElts, Known, Known2, Depth, Q,
|
||||
|
@ -2624,15 +2624,11 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, const APInt &DemandedElts,
|
||||
|
||||
if (auto *C = dyn_cast<ConstantSDNode>(Op)) {
|
||||
// We know all of the bits for a constant!
|
||||
Known.One = C->getAPIntValue();
|
||||
Known.Zero = ~Known.One;
|
||||
return Known;
|
||||
return KnownBits::makeConstant(C->getAPIntValue());
|
||||
}
|
||||
if (auto *C = dyn_cast<ConstantFPSDNode>(Op)) {
|
||||
// We know all of the bits for a constant fp!
|
||||
Known.One = C->getValueAPF().bitcastToAPInt();
|
||||
Known.Zero = ~Known.One;
|
||||
return Known;
|
||||
return KnownBits::makeConstant(C->getValueAPF().bitcastToAPInt());
|
||||
}
|
||||
|
||||
if (Depth >= MaxRecursionDepth)
|
||||
|
Loading…
Reference in New Issue
Block a user