From a8129a11222249d5072c132927dbf9d402b5f9da Mon Sep 17 00:00:00 2001 From: Craig Topper Date: Thu, 20 Apr 2017 16:17:13 +0000 Subject: [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 --- llvm/lib/Support/APInt.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'llvm/lib/Support/APInt.cpp') 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) -- cgit v1.2.3