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.
// 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
// 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.
}
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++;
}
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;