[NFC] Replace -1U{LL} expressions with appropriate *_MAX macros in Support library.
authorPavel Kopyl <pavelkopyl@gmail.com>
Fri, 10 Feb 2023 22:36:24 +0000 (23:36 +0100)
committerPavel Kopyl <pavelkopyl@gmail.com>
Tue, 14 Feb 2023 21:16:19 +0000 (22:16 +0100)
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

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

index 5f177f5..175713c 100644 (file)
@@ -27,7 +27,7 @@ public:
   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.
index 9c419c8..a5d3672 100644 (file)
@@ -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;
index 2e7926b..9cdd9b0 100644 (file)
@@ -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++;
index 9e0d906..857d400 100644 (file)
@@ -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