From b3af04f880018ece856dbb2bfafc95873c08a434 Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Mon, 23 Jan 2023 23:07:41 -0800 Subject: [PATCH] [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. --- llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp | 4 ++-- llvm/utils/TableGen/CodeGenDAGPatterns.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp b/llvm/lib/Target/RISCV/MCTargetDesc/RISCVMatInt.cpp index 65e6d941..0c2bf9d 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 63e2e4d..ec35e66 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(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; -- 2.7.4