Skip to content

Commit

Permalink
[CodeGen] Use llvm::bit_ceil (NFC)
Browse files Browse the repository at this point in the history
If we know that x is nonzero and not a power of 2, then
llvm::findLastSet(x) + 1 is the index of the bit just above the
highest set bit in x.  That is, 1 << (llvm::findLastSet(x) + 1) is the
same as llvm::bit_ceil(x).

Since llvm::bit_ceil is a nop on a power of 2, we can unconditionally
call llvm::bit_ceil.  The end result actually matches the comment.
  • Loading branch information
kazutakahirata committed Jan 25, 2023
1 parent d5248a4 commit b0daacf
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions clang/lib/CodeGen/SwiftCallingConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,7 @@ CharUnits swiftcall::getNaturalAlignment(CodeGenModule &CGM, llvm::Type *type) {
// For Swift's purposes, this is always just the store size of the type
// rounded up to a power of 2.
auto size = (unsigned long long) getTypeStoreSize(CGM, type).getQuantity();
if (!isPowerOf2(size)) {
size = 1ULL << (llvm::findLastSet(size, llvm::ZB_Undefined) + 1);
}
size = llvm::bit_ceil(size);
assert(CGM.getDataLayout().getABITypeAlign(type) <= size);
return CharUnits::fromQuantity(size);
}
Expand Down

0 comments on commit b0daacf

Please sign in to comment.