[llvm] 5d34621 - [X86] Use llvm::countr_zero instead of findFirstSet (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 24 23:26:14 PST 2023
Author: Kazu Hirata
Date: 2023-01-24T23:26:08-08:00
New Revision: 5d3462162e5a977dc0f6dacbcd227f47cfb1d884
URL: https://github.com/llvm/llvm-project/commit/5d3462162e5a977dc0f6dacbcd227f47cfb1d884
DIFF: https://github.com/llvm/llvm-project/commit/5d3462162e5a977dc0f6dacbcd227f47cfb1d884.diff
LOG: [X86] Use llvm::countr_zero instead of findFirstSet (NFC)
At the call site of findFirstSet, ZMask | (1 << DstIdx) always have
exactly 3 bits set, and they are all among the 4 least significant
bits, so (ZMask | (1 << DstIdx)) ^ 15 has exactly one bit set. Since
the argument to findFirstSet is nonzero, we can safely switch to
llvm::countr_zero.
Added:
Modified:
llvm/lib/Target/X86/X86InstrInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/X86/X86InstrInfo.cpp b/llvm/lib/Target/X86/X86InstrInfo.cpp
index e804122adae36..d650994350cb0 100644
--- a/llvm/lib/Target/X86/X86InstrInfo.cpp
+++ b/llvm/lib/Target/X86/X86InstrInfo.cpp
@@ -2096,7 +2096,7 @@ MachineInstr *X86InstrInfo::commuteInstructionImpl(MachineInstr &MI, bool NewMI,
// "inline" and we don't override the insertion with a zero.
if (DstIdx == SrcIdx && (ZMask & (1 << DstIdx)) == 0 &&
llvm::popcount(ZMask) == 2) {
- unsigned AltIdx = findFirstSet((ZMask | (1 << DstIdx)) ^ 15);
+ unsigned AltIdx = llvm::countr_zero((ZMask | (1 << DstIdx)) ^ 15);
assert(AltIdx < 4 && "Illegal insertion index");
unsigned AltImm = (AltIdx << 6) | (AltIdx << 4) | ZMask;
auto &WorkingMI = cloneIfNew(MI);
More information about the llvm-commits
mailing list