[PATCH] D28986: [APInt] Remove calls to clearUnusedBits from XorSlowCase and operator^=

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 18:21:28 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL292873: [APInt] Remove calls to clearUnusedBits from XorSlowCase and operator^= (authored by ctopper).

Changed prior to commit:
  https://reviews.llvm.org/D28986?vs=85318&id=85510#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28986

Files:
  llvm/trunk/lib/Support/APInt.cpp
  llvm/trunk/unittests/ADT/APIntTest.cpp


Index: llvm/trunk/lib/Support/APInt.cpp
===================================================================
--- llvm/trunk/lib/Support/APInt.cpp
+++ llvm/trunk/lib/Support/APInt.cpp
@@ -440,13 +440,12 @@
   assert(BitWidth == RHS.BitWidth && "Bit widths must be the same");
   if (isSingleWord()) {
     VAL ^= RHS.VAL;
-    this->clearUnusedBits();
     return *this;
   }
   unsigned numWords = getNumWords();
   for (unsigned i = 0; i < numWords; ++i)
     pVal[i] ^= RHS.pVal[i];
-  return clearUnusedBits();
+  return *this;
 }
 
 APInt APInt::AndSlowCase(const APInt& RHS) const {
@@ -471,10 +470,7 @@
   for (unsigned i = 0; i < numWords; ++i)
     val[i] = pVal[i] ^ RHS.pVal[i];
 
-  APInt Result(val, getBitWidth());
-  // 0^0==1 so clear the high bits in case they got set.
-  Result.clearUnusedBits();
-  return Result;
+  return APInt(val, getBitWidth());
 }
 
 APInt APInt::operator*(const APInt& RHS) const {
Index: llvm/trunk/unittests/ADT/APIntTest.cpp
===================================================================
--- llvm/trunk/unittests/ADT/APIntTest.cpp
+++ llvm/trunk/unittests/ADT/APIntTest.cpp
@@ -158,6 +158,36 @@
   EXPECT_EQ(two, one - neg_one);
   EXPECT_EQ(zero, one - one);
 
+  // And
+  EXPECT_EQ(zero, zero & zero);
+  EXPECT_EQ(zero, one & zero);
+  EXPECT_EQ(zero, zero & one);
+  EXPECT_EQ(one, one & one);
+  EXPECT_EQ(zero, zero & zero);
+  EXPECT_EQ(zero, neg_one & zero);
+  EXPECT_EQ(zero, zero & neg_one);
+  EXPECT_EQ(neg_one, neg_one & neg_one);
+
+  // Or
+  EXPECT_EQ(zero, zero | zero);
+  EXPECT_EQ(one, one | zero);
+  EXPECT_EQ(one, zero | one);
+  EXPECT_EQ(one, one | one);
+  EXPECT_EQ(zero, zero | zero);
+  EXPECT_EQ(neg_one, neg_one | zero);
+  EXPECT_EQ(neg_one, zero | neg_one);
+  EXPECT_EQ(neg_one, neg_one | neg_one);
+
+  // Xor
+  EXPECT_EQ(zero, zero ^ zero);
+  EXPECT_EQ(one, one ^ zero);
+  EXPECT_EQ(one, zero ^ one);
+  EXPECT_EQ(zero, one ^ one);
+  EXPECT_EQ(zero, zero ^ zero);
+  EXPECT_EQ(neg_one, neg_one ^ zero);
+  EXPECT_EQ(neg_one, zero ^ neg_one);
+  EXPECT_EQ(zero, neg_one ^ neg_one);
+
   // Shifts.
   EXPECT_EQ(zero, one << one);
   EXPECT_EQ(one, one << zero);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28986.85510.patch
Type: text/x-patch
Size: 2153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170124/ed4c087d/attachment.bin>


More information about the llvm-commits mailing list