[llvm] 7510b7e - [SystemZ] Use llvm::countl_zero and llvm::countr_zero (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 25 22:05:13 PST 2023
Author: Kazu Hirata
Date: 2023-01-25T22:05:06-08:00
New Revision: 7510b7ec4a662b050a41b399fcd3720e0e5afd82
URL: https://github.com/llvm/llvm-project/commit/7510b7ec4a662b050a41b399fcd3720e0e5afd82
DIFF: https://github.com/llvm/llvm-project/commit/7510b7ec4a662b050a41b399fcd3720e0e5afd82.diff
LOG: [SystemZ] Use llvm::countl_zero and llvm::countr_zero (NFC)
isVectorConstantLegal calls findFirstSet and findLastSet, but we don't
rely on their ability to return std::numeric_limits<T>::max() on input
0.
This patch replaces those calls with calls to llvm::countl_zero and
llvm::countr_zero.
Due to an off-by-one error in the original code, the value of Upper
could change at bit N, where N is the index of the highest set bit in
SplatBitsZ, but the difference doesn't matter at the end. Without
this patch, Upper could have bit N set. With this patch, Upper never
has bit N set. Either way, both calls to tryValue have this bit set
because the argument is ORed with SplatBitsZ.
Added:
Modified:
llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
index 5dca792dc89a2..7590befa1a1b8 100644
--- a/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZISelLowering.cpp
@@ -781,10 +781,10 @@ bool SystemZVectorConstantInfo::isVectorConstantLegal(
// IMMEDIATE or a wraparound mask in VECTOR GENERATE MASK.
uint64_t SplatBitsZ = SplatBits.getZExtValue();
uint64_t SplatUndefZ = SplatUndef.getZExtValue();
- uint64_t Lower =
- (SplatUndefZ & ((uint64_t(1) << findFirstSet(SplatBitsZ)) - 1));
- uint64_t Upper =
- (SplatUndefZ & ~((uint64_t(1) << findLastSet(SplatBitsZ)) - 1));
+ unsigned LowerBits = llvm::countr_zero(SplatBitsZ);
+ unsigned UpperBits = llvm::countl_zero(SplatBitsZ);
+ uint64_t Lower = SplatUndefZ & maskTrailingOnes<uint64_t>(LowerBits);
+ uint64_t Upper = SplatUndefZ & maskLeadingOnes<uint64_t>(UpperBits);
if (tryValue(SplatBitsZ | Upper | Lower))
return true;
More information about the llvm-commits
mailing list