[llvm] d43ad92 - [ADT, Support] Use std::min and std::max (NFC) (#164145)

via llvm-commits llvm-commits at lists.llvm.org
Sun Oct 19 12:37:47 PDT 2025


Author: Kazu Hirata
Date: 2025-10-19T12:37:43-07:00
New Revision: d43ad92e20072d648a61170acf354bc4eb473b3c

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

LOG: [ADT, Support] Use std::min and std::max (NFC) (#164145)

Added: 
    

Modified: 
    llvm/include/llvm/ADT/PagedVector.h
    llvm/include/llvm/Support/GraphWriter.h
    llvm/lib/Support/APFloat.cpp
    llvm/lib/Support/Unix/Signals.inc

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/PagedVector.h b/llvm/include/llvm/ADT/PagedVector.h
index 52ecd0bb0ba118..0a691f8889aa0c 100644
--- a/llvm/include/llvm/ADT/PagedVector.h
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -189,8 +189,7 @@ template <typename T, size_t PageSize = 1024 / sizeof(T)> class PagedVector {
         while (ElementIdx < PV->Size &&
                !PV->PageToDataPtrs[ElementIdx / PageSize])
           ElementIdx += PageSize;
-        if (ElementIdx > PV->Size)
-          ElementIdx = PV->Size;
+        ElementIdx = std::min(ElementIdx, PV->Size);
       }
 
       return *this;

diff  --git a/llvm/include/llvm/Support/GraphWriter.h b/llvm/include/llvm/Support/GraphWriter.h
index a8784edfcf8968..3bef75cc7e5085 100644
--- a/llvm/include/llvm/Support/GraphWriter.h
+++ b/llvm/include/llvm/Support/GraphWriter.h
@@ -343,7 +343,7 @@ template <typename GraphType, typename Derived> class GraphWriterBase {
                 const void *DestNodeID, int DestNodePort,
                 const std::string &Attrs) {
     if (SrcNodePort  > 64) return;             // Eminating from truncated part?
-    if (DestNodePort > 64) DestNodePort = 64;  // Targeting the truncated part?
+    DestNodePort = std::min(DestNodePort, 64); // Targeting the truncated part?
 
     O << "\tNode" << SrcNodeID;
     if (SrcNodePort >= 0)

diff  --git a/llvm/lib/Support/APFloat.cpp b/llvm/lib/Support/APFloat.cpp
index b4de79ab14baf2..47876042206a1f 100644
--- a/llvm/lib/Support/APFloat.cpp
+++ b/llvm/lib/Support/APFloat.cpp
@@ -2600,8 +2600,7 @@ APFloat::opStatus IEEEFloat::convert(const fltSemantics &toSemantics,
     int exponentChange = omsb - fromSemantics.precision;
     if (exponent + exponentChange < toSemantics.minExponent)
       exponentChange = toSemantics.minExponent - exponent;
-    if (exponentChange < shift)
-      exponentChange = shift;
+    exponentChange = std::max(exponentChange, shift);
     if (exponentChange < 0) {
       shift -= exponentChange;
       exponent += exponentChange;
@@ -3043,8 +3042,7 @@ IEEEFloat::roundSignificandWithExponent(const integerPart *decSigParts,
       if (decSig.exponent < semantics->minExponent) {
         excessPrecision += (semantics->minExponent - decSig.exponent);
         truncatedBits = excessPrecision;
-        if (excessPrecision > calcSemantics.precision)
-          excessPrecision = calcSemantics.precision;
+        excessPrecision = std::min(excessPrecision, calcSemantics.precision);
       }
       /* Extra half-ulp lost in reciprocal of exponent.  */
       powHUerr = (powStatus == opOK && calcLostFraction == lfExactlyZero) ? 0:2;
@@ -3441,8 +3439,7 @@ char *IEEEFloat::convertNormalToHexString(char *dst, unsigned int hexDigits,
     /* Convert as much of "part" to hexdigits as we can.  */
     unsigned int curDigits = integerPartWidth / 4;
 
-    if (curDigits > outputDigits)
-      curDigits = outputDigits;
+    curDigits = std::min(curDigits, outputDigits);
     dst += partAsHex (dst, part, curDigits, hexDigitChars);
     outputDigits -= curDigits;
   }

diff  --git a/llvm/lib/Support/Unix/Signals.inc b/llvm/lib/Support/Unix/Signals.inc
index 573ad82f2dea4e..78d6540db98a73 100644
--- a/llvm/lib/Support/Unix/Signals.inc
+++ b/llvm/lib/Support/Unix/Signals.inc
@@ -868,8 +868,7 @@ void llvm::sys::PrintStackTrace(raw_ostream &OS, int Depth) {
         nwidth = strlen(name) - 1;
     }
 
-    if (nwidth > width)
-      width = nwidth;
+    width = std::max(nwidth, width);
   }
 
   for (int i = 0; i < depth; ++i) {


        


More information about the llvm-commits mailing list