1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 02:33:06 +01:00

[KnownBits] Add KnownBits::haveNoCommonBitsSet helper. NFCI.

Include exhaustive test coverage.
This commit is contained in:
Simon Pilgrim 2021-04-02 19:33:18 +01:00
parent 96cc3dc1e4
commit cad94dd97b
4 changed files with 24 additions and 2 deletions

View File

@ -285,6 +285,11 @@ public:
return KnownBits(LHS.Zero & RHS.Zero, LHS.One & RHS.One);
}
/// Return true if LHS and RHS have no common bits set.
static bool haveNoCommonBitsSet(const KnownBits &LHS, const KnownBits &RHS) {
return (LHS.Zero | RHS.Zero).isAllOnesValue();
}
/// Compute known bits resulting from adding LHS, RHS and a 1-bit Carry.
static KnownBits computeForAddCarry(
const KnownBits &LHS, const KnownBits &RHS, const KnownBits &Carry);

View File

@ -301,7 +301,7 @@ bool llvm::haveNoCommonBitsSet(const Value *LHS, const Value *RHS,
KnownBits RHSKnown(IT->getBitWidth());
computeKnownBits(LHS, LHSKnown, DL, 0, AC, CxtI, DT, nullptr, UseInstrInfo);
computeKnownBits(RHS, RHSKnown, DL, 0, AC, CxtI, DT, nullptr, UseInstrInfo);
return (LHSKnown.Zero | RHSKnown.Zero).isAllOnesValue();
return KnownBits::haveNoCommonBitsSet(LHSKnown, RHSKnown);
}
bool llvm::isOnlyUsedInZeroEqualityComparison(const Instruction *CxtI) {

View File

@ -4351,7 +4351,8 @@ bool SelectionDAG::isEqualTo(SDValue A, SDValue B) const {
bool SelectionDAG::haveNoCommonBitsSet(SDValue A, SDValue B) const {
assert(A.getValueType() == B.getValueType() &&
"Values must have the same type");
return (computeKnownBits(A).Zero | computeKnownBits(B).Zero).isAllOnesValue();
return KnownBits::haveNoCommonBitsSet(computeKnownBits(A),
computeKnownBits(B));
}
static SDValue FoldSTEP_VECTOR(const SDLoc &DL, EVT VT, SDValue Step,

View File

@ -463,4 +463,20 @@ TEST(KnownBitsTest, SExtInReg) {
}
}
TEST(KnownBitsTest, CommonBitsSet) {
unsigned Bits = 4;
ForeachKnownBits(Bits, [&](const KnownBits &Known1) {
ForeachKnownBits(Bits, [&](const KnownBits &Known2) {
bool HasCommonBitsSet = false;
ForeachNumInKnownBits(Known1, [&](const APInt &N1) {
ForeachNumInKnownBits(Known2, [&](const APInt &N2) {
HasCommonBitsSet |= N1.intersects(N2);
});
});
EXPECT_EQ(!HasCommonBitsSet,
KnownBits::haveNoCommonBitsSet(Known1, Known2));
});
});
}
} // end anonymous namespace