[llvm] [Support] Simplify isUInt (NFC) (PR #155976)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 28 22:18:55 PDT 2025


https://github.com/kazutakahirata created https://github.com/llvm/llvm-project/pull/155976

None

>From f2e6a899a87e06b4f46170b3bb8397d953999189 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Tue, 26 Aug 2025 23:29:28 -0700
Subject: [PATCH] [Support] Simplify isUInt (NFC)

---
 llvm/include/llvm/Support/MathExtras.h | 10 +---------
 1 file changed, 1 insertion(+), 9 deletions(-)

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;
 }



More information about the llvm-commits mailing list