[llvm] 0b36a33 - Reland "[Support] Don't include <algorithm> in MathExtras.h"

Nico Weber via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 16 11:07:56 PDT 2021


Author: Nico Weber
Date: 2021-04-16T14:07:45-04:00
New Revision: 0b36a33ab89488a631d5ee9580904a36898c7954

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

LOG: Reland "[Support] Don't include <algorithm> in MathExtras.h"

This reverts commit af2a93fd6e9f9e037d2e2d67b879fe85d7e1cbed.
This time, add the include to APInt.h, which apparently relied
on getting this include transitively.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/APInt.h
    llvm/include/llvm/Support/MathExtras.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/APInt.h b/llvm/include/llvm/ADT/APInt.h
index b97ea2cd9aeef..0fca6bac43fd9 100644
--- a/llvm/include/llvm/ADT/APInt.h
+++ b/llvm/include/llvm/ADT/APInt.h
@@ -17,6 +17,7 @@
 
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/MathExtras.h"
+#include <algorithm>
 #include <cassert>
 #include <climits>
 #include <cstring>

diff  --git a/llvm/include/llvm/Support/MathExtras.h b/llvm/include/llvm/Support/MathExtras.h
index 640b3a11ce6c2..10d4260a7eb15 100644
--- a/llvm/include/llvm/Support/MathExtras.h
+++ b/llvm/include/llvm/Support/MathExtras.h
@@ -14,7 +14,6 @@
 #define LLVM_SUPPORT_MATHEXTRAS_H
 
 #include "llvm/Support/Compiler.h"
-#include <algorithm>
 #include <cassert>
 #include <climits>
 #include <cmath>
@@ -793,7 +792,7 @@ inline int64_t SignExtend64(uint64_t X, unsigned B) {
 /// value of the result.
 template <typename T>
 std::enable_if_t<std::is_unsigned<T>::value, T> AbsoluteDifference(T X, T Y) {
-  return std::max(X, Y) - std::min(X, Y);
+  return X > Y ? X - Y : Y - X;
 }
 
 /// Add two unsigned integers, X and Y, of type T.  Clamp the result to the


        


More information about the llvm-commits mailing list