Author: Kazu Hirata Date: 2023-01-24T22:54:53-08:00 New Revision: b0daacf58f417634f7c7c9496589d723592a8f5a
URL: https://github.com/llvm/llvm-project/commit/b0daacf58f417634f7c7c9496589d723592a8f5a DIFF: https://github.com/llvm/llvm-project/commit/b0daacf58f417634f7c7c9496589d723592a8f5a.diff LOG: [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. Added: Modified: clang/lib/CodeGen/SwiftCallingConv.cpp Removed: ################################################################################ diff --git a/clang/lib/CodeGen/SwiftCallingConv.cpp b/clang/lib/CodeGen/SwiftCallingConv.cpp index 6b868fe84ca68..63d975193c027 100644 --- a/clang/lib/CodeGen/SwiftCallingConv.cpp +++ b/clang/lib/CodeGen/SwiftCallingConv.cpp @@ -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); } _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits