[llvm] Use llvm::countr_zero instead of findFirstSet (NFC)
authorKazu Hirata <kazu@google.com>
Tue, 24 Jan 2023 07:07:41 +0000 (23:07 -0800)
committerKazu Hirata <kazu@google.com>
Tue, 24 Jan 2023 07:07:41 +0000 (23:07 -0800)
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.

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

index 65e6d94..0c2bf9d 100644 (file)
@@ -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.
       }
index 63e2e4d..ec35e66 100644 (file)
@@ -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;