[llvm] Use compiler intrinsics to compute PowerOf2Ceil (PR #67580)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 27 10:41:50 PDT 2023
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
<details>
<summary>Changes</summary>
Instead of calling NextPowerOf2, we can use compiler intrinsics to do this faster.
---
Full diff: https://github.com/llvm/llvm-project/pull/67580.diff
1 Files Affected:
- (modified) llvm/include/llvm/Support/MathExtras.h (+4)
``````````diff
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index dc095941fdc8a9f..f592beee5ccffc2 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -361,7 +361,11 @@ constexpr inline uint64_t NextPowerOf2(uint64_t A) {
inline uint64_t PowerOf2Ceil(uint64_t A) {
if (!A)
return 0;
+#if __has_builtin(__builtin_clzl)
+ return 1ULL << (64 - __builtin_clzl(A - 1));
+#else
return NextPowerOf2(A - 1);
+#endif
}
/// Returns the next integer (mod 2**64) that is greater than or equal to
``````````
</details>
https://github.com/llvm/llvm-project/pull/67580
More information about the llvm-commits
mailing list