[llvm] [Support] Simplify isUInt (NFC) (PR #155976)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 28 22:19:26 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
Author: Kazu Hirata (kazutakahirata)
<details>
<summary>Changes</summary>
---
Full diff: https://github.com/llvm/llvm-project/pull/155976.diff
1 Files Affected:
- (modified) llvm/include/llvm/Support/MathExtras.h (+1-9)
``````````diff
diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index c9dae7ae7346d..96ebbd61e367c 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -196,16 +196,8 @@ constexpr bool isShiftedInt(int64_t x) {
/// Checks if an unsigned integer fits into the given bit width.
template <unsigned N> constexpr bool isUInt(uint64_t x) {
- if constexpr (N == 0)
- return 0 == x;
- if constexpr (N == 8)
- return static_cast<uint8_t>(x) == x;
- if constexpr (N == 16)
- return static_cast<uint16_t>(x) == x;
- if constexpr (N == 32)
- return static_cast<uint32_t>(x) == x;
if constexpr (N < 64)
- return x < (UINT64_C(1) << (N));
+ return (x >> N) == 0;
(void)x; // MSVC v19.25 warns that x is unused.
return true;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/155976
More information about the llvm-commits
mailing list