Skip to content

Commit b0daacf

Browse files
[CodeGen] Use llvm::bit_ceil (NFC)
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.
1 parent d5248a4 commit b0daacf

File tree

1 file changed

+1
-3
lines changed

1 file changed

+1
-3
lines changed

clang/lib/CodeGen/SwiftCallingConv.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -659,9 +659,7 @@ CharUnits swiftcall::getNaturalAlignment(CodeGenModule &CGM, llvm::Type *type) {
659659
// For Swift's purposes, this is always just the store size of the type
660660
// rounded up to a power of 2.
661661
auto size = (unsigned long long) getTypeStoreSize(CGM, type).getQuantity();
662-
if (!isPowerOf2(size)) {
663-
size = 1ULL << (llvm::findLastSet(size, llvm::ZB_Undefined) + 1);
664-
}
662+
size = llvm::bit_ceil(size);
665663
assert(CGM.getDataLayout().getABITypeAlign(type) <= size);
666664
return CharUnits::fromQuantity(size);
667665
}

0 commit comments

Comments
 (0)