[llvm] [ADT] Simplify SparseBitVectorElement::unionWith and friends. NFC. (PR #143775)

via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 11 12:46:18 PDT 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-adt

Author: Jay Foad (jayfoad)

<details>
<summary>Changes</summary>



---
Full diff: https://github.com/llvm/llvm-project/pull/143775.diff


1 Files Affected:

- (modified) llvm/include/llvm/ADT/SparseBitVector.h (+6-6) 


``````````diff
diff --git a/llvm/include/llvm/ADT/SparseBitVector.h b/llvm/include/llvm/ADT/SparseBitVector.h
index 7151af6146e6e..1e6f8b22ca997 100644
--- a/llvm/include/llvm/ADT/SparseBitVector.h
+++ b/llvm/include/llvm/ADT/SparseBitVector.h
@@ -172,10 +172,10 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {
   bool unionWith(const SparseBitVectorElement &RHS) {
     bool changed = false;
     for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i) {
-      BitWord old = changed ? 0 : Bits[i];
+      BitWord old = Bits[i];
 
       Bits[i] |= RHS.Bits[i];
-      if (!changed && old != Bits[i])
+      if (old != Bits[i])
         changed = true;
     }
     return changed;
@@ -199,13 +199,13 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {
 
     BecameZero = false;
     for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i) {
-      BitWord old = changed ? 0 : Bits[i];
+      BitWord old = Bits[i];
 
       Bits[i] &= RHS.Bits[i];
       if (Bits[i] != 0)
         allzero = false;
 
-      if (!changed && old != Bits[i])
+      if (old != Bits[i])
         changed = true;
     }
     BecameZero = allzero;
@@ -222,13 +222,13 @@ template <unsigned ElementSize = 128> struct SparseBitVectorElement {
 
     BecameZero = false;
     for (unsigned i = 0; i < BITWORDS_PER_ELEMENT; ++i) {
-      BitWord old = changed ? 0 : Bits[i];
+      BitWord old = Bits[i];
 
       Bits[i] &= ~RHS.Bits[i];
       if (Bits[i] != 0)
         allzero = false;
 
-      if (!changed && old != Bits[i])
+      if (old != Bits[i])
         changed = true;
     }
     BecameZero = allzero;

``````````

</details>


https://github.com/llvm/llvm-project/pull/143775


More information about the llvm-commits mailing list