[PATCH] D32253: [APInt] Implement APInt::intersects without creating a temporary APInt in the multiword case

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 19 19:24:33 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL300812: [APInt] Implement APInt::intersects without creating a temporary APInt in theā€¦ (authored by ctopper).

Changed prior to commit:
  https://reviews.llvm.org/D32253?vs=95842&id=95873#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32253

Files:
  llvm/trunk/include/llvm/ADT/APInt.h
  llvm/trunk/lib/Support/APInt.cpp


Index: llvm/trunk/include/llvm/ADT/APInt.h
===================================================================
--- llvm/trunk/include/llvm/ADT/APInt.h
+++ llvm/trunk/include/llvm/ADT/APInt.h
@@ -209,6 +209,9 @@
   /// 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 @@
   /// 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);
   }
 
   /// @}
Index: llvm/trunk/lib/Support/APInt.cpp
===================================================================
--- llvm/trunk/lib/Support/APInt.cpp
+++ llvm/trunk/lib/Support/APInt.cpp
@@ -722,6 +722,14 @@
   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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32253.95873.patch
Type: text/x-patch
Size: 1530 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170420/d856f828/attachment.bin>


More information about the llvm-commits mailing list