summaryrefslogtreecommitdiffstats
path: root/llvm
diff options
context:
space:
mode:
authorCraig Topper <craig.topper@gmail.com>2017-04-20 02:11:27 +0000
committerCraig Topper <craig.topper@gmail.com>2017-04-20 02:11:27 +0000
commitbaa392e4e064d0cbaaf116f10e23c98a395c473a (patch)
tree3b36bc692be7128804879ff6c3793dd0ae09b1c0 /llvm
parente49252cea12515d059b9a62ac458826498638ea3 (diff)
downloadbcm5719-llvm-baa392e4e064d0cbaaf116f10e23c98a395c473a.tar.gz
bcm5719-llvm-baa392e4e064d0cbaaf116f10e23c98a395c473a.zip
[APInt] Implement APInt::intersects without creating a temporary APInt in the multiword case
Summary: This is a simple question we should be able to answer without creating a temporary to hold the AND result. We can also get an early out as soon as we find a word that intersects. Reviewers: RKSimon, hans, spatel, davide Reviewed By: hans, davide Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D32253 llvm-svn: 300812
Diffstat (limited to 'llvm')
-rw-r--r--llvm/include/llvm/ADT/APInt.h10
-rw-r--r--llvm/lib/Support/APInt.cpp8
2 files changed, 15 insertions, 3 deletions
diff --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index 2fafeafb6ad..5f87765a52d 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -209,6 +209,9 @@ private:
/// out-of-line slow case for countPopulation
unsigned countPopulationSlowCase() const LLVM_READONLY;
+ /// out-of-line slow case for intersects.
+ bool intersectsSlowCase(const APInt &RHS) const LLVM_READONLY;
+
/// out-of-line slow case for setBits.
void setBitsSlowCase(unsigned loBit, unsigned hiBit);
@@ -1206,9 +1209,10 @@ public:
/// This operation tests if there are any pairs of corresponding bits
/// between this APInt and RHS that are both set.
bool intersects(const APInt &RHS) const {
- APInt temp(*this);
- temp &= RHS;
- return temp != 0;
+ assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
+ if (isSingleWord())
+ return (VAL & RHS.VAL) != 0;
+ return intersectsSlowCase(RHS);
}
/// @}
diff --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 805a912501d..54ffc3c0274 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -722,6 +722,14 @@ unsigned APInt::countPopulationSlowCase() const {
return Count;
}
+bool APInt::intersectsSlowCase(const APInt &RHS) const {
+ for (unsigned i = 0, e = getNumWords(); i != e; ++i)
+ if ((pVal[i] & RHS.pVal[i]) != 0)
+ return true;
+
+ return false;
+}
+
APInt APInt::byteSwap() const {
assert(BitWidth >= 16 && BitWidth % 16 == 0 && "Cannot byteswap!");
if (BitWidth == 16)
OpenPOWER on IntegriCloud