[llvm] [Support] Simplify minIntN and isUIntN (NFC) (PR #166506)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 4 22:36:40 PST 2025


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

None

>From 81cd702718bf4db2006cee4c27bb4375386a9692 Mon Sep 17 00:00:00 2001
From: Kazu Hirata <kazu at google.com>
Date: Wed, 10 Sep 2025 19:54:03 -0700
Subject: [PATCH] [Support] Simplify minIntN and isUIntN (NFC)

---
 llvm/include/llvm/Support/MathExtras.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index 9bbb8a2a30541..0a253efc2abcb 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -225,7 +225,7 @@ inline constexpr int64_t minIntN(int64_t N) {
 
   if (N == 0)
     return 0;
-  return UINT64_C(1) + ~(UINT64_C(1) << (N - 1));
+  return UINT64_MAX << (N - 1);
 }
 
 /// Gets the maximum value for a N-bit signed integer.
@@ -241,7 +241,7 @@ inline constexpr int64_t maxIntN(int64_t N) {
 
 /// Checks if an unsigned integer fits into the given (dynamic) bit width.
 inline constexpr bool isUIntN(unsigned N, uint64_t x) {
-  return N >= 64 || x <= maxUIntN(N);
+  return N >= 64 || (x >> N) == 0;
 }
 
 /// Checks if an signed integer fits into the given (dynamic) bit width.



More information about the llvm-commits mailing list