[llvm] b3af04f - [llvm] Use llvm::countr_zero instead of findFirstSet (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 23 23:07:48 PST 2023


Author: Kazu Hirata
Date: 2023-01-23T23:07:41-08:00
New Revision: b3af04f880018ece856dbb2bfafc95873c08a434

URL: https://github.com/llvm/llvm-project/commit/b3af04f880018ece856dbb2bfafc95873c08a434
DIFF: https://github.com/llvm/llvm-project/commit/b3af04f880018ece856dbb2bfafc95873c08a434.diff

LOG: [llvm] Use llvm::countr_zero instead of findFirstSet (NFC)

At each call to findFirstSet in this patch, the argument is known to
be nonzero, so we can safely switch to llvm::countr_zero, which will
become std::countr_zero once C++20 is available.

Added: 
    

Modified: 
    llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
    llvm/utils/TableGen/CodeGenDAGPatterns.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
index 65e6d941fc535..0c2bf9dad7954 100644
--- a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
+++ b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp
@@ -111,7 +111,7 @@ static void generateInstSeqImpl(int64_t Val,
 
   // Val might now be valid for LUI without needing a shift.
   if (!isInt<32>(Val)) {
-    ShiftAmount = findFirstSet((uint64_t)Val, ZB_Undefined);
+    ShiftAmount = llvm::countr_zero((uint64_t)Val);
     Val >>= ShiftAmount;
 
     // If the remaining bits don't fit in 12 bits, we might be able to reduce the
@@ -288,7 +288,7 @@ InstSeq generateInstSeq(int64_t Val, const FeatureBitset &ActiveFeatures) {
     // Search for each bit and build corresponding BCLRI/BSETI.
     if (Opc > 0) {
       while (Hi != 0) {
-        unsigned Bit = findFirstSet(Hi, ZB_Undefined);
+        unsigned Bit = llvm::countr_zero(Hi);
         TmpSeq.emplace_back(Opc, Bit + 32);
         Hi &= (Hi - 1); // Clear lowest set bit.
       }

diff  --git a/llvm/utils/TableGen/CodeGenDAGPatterns.h b/llvm/utils/TableGen/CodeGenDAGPatterns.h
index 63e2e4db2dd50..ec35e66800886 100644
--- a/llvm/utils/TableGen/CodeGenDAGPatterns.h
+++ b/llvm/utils/TableGen/CodeGenDAGPatterns.h
@@ -150,7 +150,7 @@ struct MachineValueTypeSet {
         WordType W = Set->Words[SkipWords];
         W &= maskLeadingOnes<WordType>(WordWidth-SkipBits);
         if (W != 0)
-          return Count + findFirstSet(W);
+          return Count + llvm::countr_zero(W);
         Count += WordWidth;
         SkipWords++;
       }
@@ -158,7 +158,7 @@ struct MachineValueTypeSet {
       for (unsigned i = SkipWords; i != NumWords; ++i) {
         WordType W = Set->Words[i];
         if (W != 0)
-          return Count + findFirstSet(W);
+          return Count + llvm::countr_zero(W);
         Count += WordWidth;
       }
       return Capacity;


        


More information about the llvm-commits mailing list