Skip to content

Commit 7e6e636

Browse files
Use llvm::has_single_bit<uint32_t> (NFC)
This patch replaces isPowerOf2_32 with llvm::has_single_bit<uint32_t> where the argument is wider than uint32_t.
1 parent 68e81d7 commit 7e6e636

20 files changed

+50
-39
lines changed

clang/lib/CodeGen/CGNonTrivialStruct.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,8 @@ struct GenBinaryFunc : CopyStructVisitor<Derived, IsMove>,
522522
Address SrcAddr = this->getAddrWithOffset(Addrs[SrcIdx], this->Start);
523523

524524
// Emit memcpy.
525-
if (Size.getQuantity() >= 16 || !llvm::isPowerOf2_32(Size.getQuantity())) {
525+
if (Size.getQuantity() >= 16 ||
526+
!llvm::has_single_bit<uint32_t>(Size.getQuantity())) {
526527
llvm::Value *SizeVal =
527528
llvm::ConstantInt::get(this->CGF->SizeTy, Size.getQuantity());
528529
DstAddr =

llvm/lib/CodeGen/GlobalISel/CombinerHelper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ bool CombinerHelper::matchCombineExtendingLoads(MachineInstr &MI,
535535

536536
// For non power-of-2 types, they will very likely be legalized into multiple
537537
// loads. Don't bother trying to match them into extending loads.
538-
if (!isPowerOf2_32(LoadValueTy.getSizeInBits()))
538+
if (!llvm::has_single_bit<uint32_t>(LoadValueTy.getSizeInBits()))
539539
return false;
540540

541541
// Find the preferred type aside from the any-extends (unless it's the only

llvm/lib/CodeGen/GlobalISel/IRTranslator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,7 @@ void IRTranslator::emitBitTestHeader(SwitchCG::BitTestBlock &B,
10181018

10191019
LLT MaskTy = SwitchOpTy;
10201020
if (MaskTy.getSizeInBits() > PtrTy.getSizeInBits() ||
1021-
!isPowerOf2_32(MaskTy.getSizeInBits()))
1021+
!llvm::has_single_bit<uint32_t>(MaskTy.getSizeInBits()))
10221022
MaskTy = LLT::scalar(PtrTy.getSizeInBits());
10231023
else {
10241024
// Ensure that the type will fit the mask value.

llvm/lib/CodeGen/GlobalISel/LegalityPredicates.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ LegalityPredicate LegalityPredicates::sizeNotMultipleOf(unsigned TypeIdx,
164164
LegalityPredicate LegalityPredicates::sizeNotPow2(unsigned TypeIdx) {
165165
return [=](const LegalityQuery &Query) {
166166
const LLT QueryTy = Query.Types[TypeIdx];
167-
return QueryTy.isScalar() && !isPowerOf2_32(QueryTy.getSizeInBits());
167+
return QueryTy.isScalar() &&
168+
!llvm::has_single_bit<uint32_t>(QueryTy.getSizeInBits());
168169
};
169170
}
170171

@@ -184,14 +185,16 @@ LegalityPredicate LegalityPredicates::sameSize(unsigned TypeIdx0,
184185

185186
LegalityPredicate LegalityPredicates::memSizeInBytesNotPow2(unsigned MMOIdx) {
186187
return [=](const LegalityQuery &Query) {
187-
return !isPowerOf2_32(Query.MMODescrs[MMOIdx].MemoryTy.getSizeInBytes());
188+
return !llvm::has_single_bit<uint32_t>(
189+
Query.MMODescrs[MMOIdx].MemoryTy.getSizeInBytes());
188190
};
189191
}
190192

191193
LegalityPredicate LegalityPredicates::memSizeNotByteSizePow2(unsigned MMOIdx) {
192194
return [=](const LegalityQuery &Query) {
193195
const LLT MemTy = Query.MMODescrs[MMOIdx].MemoryTy;
194-
return !MemTy.isByteSized() || !isPowerOf2_32(MemTy.getSizeInBytes());
196+
return !MemTy.isByteSized() ||
197+
!llvm::has_single_bit<uint32_t>(MemTy.getSizeInBytes());
195198
};
196199
}
197200

llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21526,9 +21526,10 @@ SDValue DAGCombiner::reduceBuildVecExtToExtBuildVec(SDNode *N) {
2152621526
// same source type and all of the inputs must be any or zero extend.
2152721527
// Scalar sizes must be a power of two.
2152821528
EVT OutScalarTy = VT.getScalarType();
21529-
bool ValidTypes = SourceType != MVT::Other &&
21530-
isPowerOf2_32(OutScalarTy.getSizeInBits()) &&
21531-
isPowerOf2_32(SourceType.getSizeInBits());
21529+
bool ValidTypes =
21530+
SourceType != MVT::Other &&
21531+
llvm::has_single_bit<uint32_t>(OutScalarTy.getSizeInBits()) &&
21532+
llvm::has_single_bit<uint32_t>(SourceType.getSizeInBits());
2153221533

2153321534
// Create a new simpler BUILD_VECTOR sequence which other optimizations can
2153421535
// turn into a single shuffle instruction.

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4272,7 +4272,7 @@ SDValue TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
42724272
// zero.
42734273
if (N0.getOpcode() == ISD::SRL && (C1.isZero() || C1.isOne()) &&
42744274
N0.getOperand(0).getOpcode() == ISD::CTLZ &&
4275-
isPowerOf2_32(N0.getScalarValueSizeInBits())) {
4275+
llvm::has_single_bit<uint32_t>(N0.getScalarValueSizeInBits())) {
42764276
if (ConstantSDNode *ShAmt = isConstOrConstSplat(N0.getOperand(1))) {
42774277
if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) &&
42784278
ShAmt->getAPIntValue() == Log2_32(N0.getScalarValueSizeInBits())) {

llvm/lib/CodeGen/TargetLoweringBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1626,7 +1626,7 @@ unsigned TargetLoweringBase::getVectorTypeBreakdown(LLVMContext &Context,
16261626
if (EVT(DestVT).bitsLT(NewVT)) { // Value is expanded, e.g. i64 -> i16.
16271627
TypeSize NewVTSize = NewVT.getSizeInBits();
16281628
// Convert sizes such as i33 to i64.
1629-
if (!isPowerOf2_32(NewVTSize.getKnownMinValue()))
1629+
if (!llvm::has_single_bit<uint32_t>(NewVTSize.getKnownMinValue()))
16301630
NewVTSize = NewVTSize.coefficientNextPowerOf2();
16311631
return NumVectorRegs*(NewVTSize/DestVT.getSizeInBits());
16321632
}

llvm/lib/Target/AArch64/GISel/AArch64InstructionSelector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6164,7 +6164,7 @@ AArch64InstructionSelector::selectExtendedSHL(
61646164
// Since we're going to pull this into a shift, the constant value must be
61656165
// a power of 2. If we got a multiply, then we need to check this.
61666166
if (OffsetOpc == TargetOpcode::G_MUL) {
6167-
if (!isPowerOf2_32(ImmVal))
6167+
if (!llvm::has_single_bit<uint32_t>(ImmVal))
61686168
return std::nullopt;
61696169

61706170
// Got a power of 2. So, the amount we'll shift is the log base-2 of that.

llvm/lib/Target/AArch64/GISel/AArch64LegalizerInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -981,8 +981,8 @@ bool AArch64LegalizerInfo::legalizeVectorTrunc(
981981
Register SrcReg = MI.getOperand(1).getReg();
982982
LLT DstTy = MRI.getType(DstReg);
983983
LLT SrcTy = MRI.getType(SrcReg);
984-
assert(isPowerOf2_32(DstTy.getSizeInBits()) &&
985-
isPowerOf2_32(SrcTy.getSizeInBits()));
984+
assert(llvm::has_single_bit<uint32_t>(DstTy.getSizeInBits()) &&
985+
llvm::has_single_bit<uint32_t>(SrcTy.getSizeInBits()));
986986

987987
// Split input type.
988988
LLT SplitSrcTy =

llvm/lib/Target/AMDGPU/AMDGPULegalizerInfo.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_,
15801580
const LLT &EltTy = Ty.getElementType();
15811581
if (EltTy.getSizeInBits() < 8 || EltTy.getSizeInBits() > 512)
15821582
return true;
1583-
if (!isPowerOf2_32(EltTy.getSizeInBits()))
1583+
if (!llvm::has_single_bit<uint32_t>(EltTy.getSizeInBits()))
15841584
return true;
15851585
}
15861586
return false;
@@ -1628,8 +1628,8 @@ AMDGPULegalizerInfo::AMDGPULegalizerInfo(const GCNSubtarget &ST_,
16281628
Builder.widenScalarIf(
16291629
[=](const LegalityQuery &Query) {
16301630
const LLT Ty = Query.Types[BigTyIdx];
1631-
return !isPowerOf2_32(Ty.getSizeInBits()) &&
1632-
Ty.getSizeInBits() % 16 != 0;
1631+
return !llvm::has_single_bit<uint32_t>(Ty.getSizeInBits()) &&
1632+
Ty.getSizeInBits() % 16 != 0;
16331633
},
16341634
[=](const LegalityQuery &Query) {
16351635
// Pick the next power of 2, or a multiple of 64 over 128.

0 commit comments

Comments
 (0)