[llvm] 36606cf - [NFC] Replace -1U{LL} expressions with appropriate *_MAX macros in Support library.

Pavel Kopyl via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 14 13:16:51 PST 2023


Author: Pavel Kopyl
Date: 2023-02-14T22:16:19+01:00
New Revision: 36606cf07080a44a1a9157f80112f9512bd6a3bf

URL: https://github.com/llvm/llvm-project/commit/36606cf07080a44a1a9157f80112f9512bd6a3bf
DIFF: https://github.com/llvm/llvm-project/commit/36606cf07080a44a1a9157f80112f9512bd6a3bf.diff

LOG: [NFC] Replace -1U{LL} expressions with appropriate *_MAX macros in Support library.

This makes a code a bit more clear and also gets rid of C4146 warning
on MSVC compiler:
 'unary minus operator applied to unsigned type, result still unsigned'.

In case uint64_t variable is initialized or compared against -1U expression,
which corresponds to 32-bit constant, UINT_MAX macro is used to preserve
NFC semantics; -1ULL is replaced with UINT64_MAX.

Reviewed By: dblaikie, craig.topper

Differential Revision: https://reviews.llvm.org/D143942

Added: 
    

Modified: 
    llvm/include/llvm/Support/BlockFrequency.h
    llvm/include/llvm/Support/LEB128.h
    llvm/lib/Support/APFloat.cpp
    llvm/lib/Support/APInt.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/BlockFrequency.h b/llvm/include/llvm/Support/BlockFrequency.h
index 5f177f59d07e9..175713c09e029 100644
--- a/llvm/include/llvm/Support/BlockFrequency.h
+++ b/llvm/include/llvm/Support/BlockFrequency.h
@@ -27,7 +27,7 @@ class BlockFrequency {
   BlockFrequency(uint64_t Freq = 0) : Frequency(Freq) { }
 
   /// Returns the maximum possible frequency, the saturation value.
-  static uint64_t getMaxFrequency() { return -1ULL; }
+  static uint64_t getMaxFrequency() { return UINT64_MAX; }
 
   /// Returns the frequency as a fixpoint number scaled by the entry
   /// frequency.

diff  --git a/llvm/include/llvm/Support/LEB128.h b/llvm/include/llvm/Support/LEB128.h
index 9c419c82a19e4..a5d367279aefe 100644
--- a/llvm/include/llvm/Support/LEB128.h
+++ b/llvm/include/llvm/Support/LEB128.h
@@ -191,7 +191,7 @@ inline int64_t decodeSLEB128(const uint8_t *p, unsigned *n = nullptr,
   } while (Byte >= 128);
   // Sign extend negative numbers if needed.
   if (Shift < 64 && (Byte & 0x40))
-    Value |= (-1ULL) << Shift;
+    Value |= UINT64_MAX << Shift;
   if (n)
     *n = (unsigned)(p - orig_p);
   return Value;

diff  --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index 2e7926b4aa7ac..9cdd9b0a35296 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -568,7 +568,7 @@ trailingHexadecimalFraction(StringRef::iterator p, StringRef::iterator end,
 
   /* If we ran off the end it is exactly zero or one-half, otherwise
      a little more.  */
-  if (hexDigit == -1U)
+  if (hexDigit == UINT_MAX)
     return digitValue == 0 ? lfExactlyZero: lfExactlyHalf;
   else
     return digitValue == 0 ? lfLessThanHalf: lfMoreThanHalf;
@@ -585,7 +585,7 @@ lostFractionThroughTruncation(const APFloatBase::integerPart *parts,
 
   lsb = APInt::tcLSB(parts, partCount);
 
-  /* Note this is guaranteed true if bits == 0, or LSB == -1U.  */
+  /* Note this is guaranteed true if bits == 0, or LSB == UINT_MAX.  */
   if (bits <= lsb)
     return lfExactlyZero;
   if (bits == lsb + 1)
@@ -2815,7 +2815,7 @@ IEEEFloat::convertFromHexadecimalString(StringRef s,
     }
 
     hex_value = hexDigitValue(*p);
-    if (hex_value == -1U)
+    if (hex_value == UINT_MAX)
       break;
 
     p++;

diff  --git a/llvm/lib/Support/APInt.cpp b/llvm/lib/Support/APInt.cpp
index 9e0d9064b6435..857d400596b11 100644
--- a/llvm/lib/Support/APInt.cpp
+++ b/llvm/lib/Support/APInt.cpp
@@ -68,7 +68,7 @@ inline static unsigned getDigit(char cdigit, uint8_t radix) {
   if (r < radix)
     return r;
 
-  return -1U;
+  return UINT_MAX;
 }
 
 
@@ -2330,7 +2330,7 @@ void APInt::tcClearBit(WordType *parts, unsigned bit) {
 }
 
 /// Returns the bit number of the least significant set bit of a number.  If the
-/// input number has no bits set -1U is returned.
+/// input number has no bits set UINT_MAX is returned.
 unsigned APInt::tcLSB(const WordType *parts, unsigned n) {
   for (unsigned i = 0; i < n; i++) {
     if (parts[i] != 0) {
@@ -2339,11 +2339,11 @@ unsigned APInt::tcLSB(const WordType *parts, unsigned n) {
     }
   }
 
-  return -1U;
+  return UINT_MAX;
 }
 
 /// Returns the bit number of the most significant set bit of a number.
-/// If the input number has no bits set -1U is returned.
+/// If the input number has no bits set UINT_MAX is returned.
 unsigned APInt::tcMSB(const WordType *parts, unsigned n) {
   do {
     --n;
@@ -2356,7 +2356,7 @@ unsigned APInt::tcMSB(const WordType *parts, unsigned n) {
     }
   } while (n);
 
-  return -1U;
+  return UINT_MAX;
 }
 
 /// Copy the bit vector of width srcBITS from SRC, starting at bit srcLSB, to


        


More information about the llvm-commits mailing list