[PATCH] D32302: [BitVector] Add find_last() and find_last_unset()

Chandler Carruth via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 20 17:48:43 PDT 2017


chandlerc added inline comments.


================
Comment at: llvm/include/llvm/ADT/BitVector.h:170-173
+    for (auto Word : enumerate(reverse(Words))) {
+      if (Word.value() == BitWord(0))
+        continue;
+      unsigned Idx = NumBitWords(size()) - Word.index();
----------------
The for loop above seems simpler?

If you really want, you can use:

  for (unsigned i : llvm::reverse(llvm::seq(0, NumBitWords(size())))


================
Comment at: llvm/include/llvm/ADT/BitVector.h:196-202
+      if (Word.index() == 0) {
+        // If this is the last word in the BitVector, it has some unused bits.
+        // Set them all to 1 so that the countLeadingOnes check works.
+        unsigned UnusedCount = BITWORD_SIZE - size() % BITWORD_SIZE;
+        BitWord Mask = maskLeadingOnes<BitWord>(UnusedCount);
+        Val |= Mask;
+      }
----------------
Rather than this, what about just handling the last word outside the loop?


https://reviews.llvm.org/D32302





More information about the llvm-commits mailing list