[llvm] 32ce06b - [Support] Use llvm::bit_floor in PowerOf2Floor (NFC)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Sun Jan 22 14:34:50 PST 2023


Author: Kazu Hirata
Date: 2023-01-22T14:34:43-08:00
New Revision: 32ce06bbf2cf0392fd5f3d147b6640f76f864230

URL: https://github.com/llvm/llvm-project/commit/32ce06bbf2cf0392fd5f3d147b6640f76f864230
DIFF: https://github.com/llvm/llvm-project/commit/32ce06bbf2cf0392fd5f3d147b6640f76f864230.diff

LOG: [Support] Use llvm::bit_floor in PowerOf2Floor (NFC)

Added: 
    

Modified: 
    llvm/include/llvm/Support/MathExtras.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index b2b2721d0331..ff136ba2a884 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -483,8 +483,7 @@ constexpr inline uint64_t NextPowerOf2(uint64_t A) {
 /// Returns the power of two which is less than or equal to the given value.
 /// Essentially, it is a floor operation across the domain of powers of two.
 inline uint64_t PowerOf2Floor(uint64_t A) {
-  if (!A) return 0;
-  return 1ull << (63 - llvm::countl_zero(A));
+  return llvm::bit_floor(A);
 }
 
 /// Returns the power of two which is greater than or equal to the given value.


        


More information about the llvm-commits mailing list