diff options
author | Craig Topper <craig.topper@gmail.com> | 2017-04-20 16:17:13 +0000 |
---|---|---|
committer | Craig Topper <craig.topper@gmail.com> | 2017-04-20 16:17:13 +0000 |
commit | a8129a11222249d5072c132927dbf9d402b5f9da (patch) | |
tree | 5a449591a98fa76421c1dd0297c2a5a074f94091 /llvm/lib/Support/APInt.cpp | |
parent | b7701bc9af13662f9658cf6a9db50daad3affd90 (diff) | |
download | bcm5719-llvm-a8129a11222249d5072c132927dbf9d402b5f9da.tar.gz bcm5719-llvm-a8129a11222249d5072c132927dbf9d402b5f9da.zip |
[APInt] Add isSubsetOf method that can check if one APInt is a subset of another without creating temporary APInts
This question comes up in many places in SimplifyDemandedBits. This makes it easy to ask without allocating additional temporary APInts.
The BitVector class provides a similar functionality through its (IMHO badly named) test(const BitVector&) method. Though its output polarity is reversed.
I've provided one example use case in this patch. I plan to do more as a follow up.
Differential Revision: https://reviews.llvm.org/D32258
llvm-svn: 300851
Diffstat (limited to 'llvm/lib/Support/APInt.cpp')
-rw-r--r-- | llvm/lib/Support/APInt.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp index 54ffc3c0274..2d049a1cff8 100644 --- a/llvm/lib/Support/APInt.cpp +++ b/llvm/lib/Support/APInt.cpp @@ -730,6 +730,14 @@ bool APInt::intersectsSlowCase(const APInt &RHS) const { return false; } +bool APInt::isSubsetOfSlowCase(const APInt &RHS) const { + for (unsigned i = 0, e = getNumWords(); i != e; ++i) + if ((pVal[i] & ~RHS.pVal[i]) != 0) + return false; + + return true; +} + APInt APInt::byteSwap() const { assert(BitWidth >= 16 && BitWidth % 16 == 0 && "Cannot byteswap!"); if (BitWidth == 16) |