[llvm] 7a617fd - Use std::gcd (NFC)
Kazu Hirata via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 27 21:21:26 PDT 2022
Author: Kazu Hirata
Date: 2022-08-27T21:20:59-07:00
New Revision: 7a617fdf39dad656e08001fb2dfa31cc42fd30e2
URL: https://github.com/llvm/llvm-project/commit/7a617fdf39dad656e08001fb2dfa31cc42fd30e2
DIFF: https://github.com/llvm/llvm-project/commit/7a617fdf39dad656e08001fb2dfa31cc42fd30e2.diff
LOG: Use std::gcd (NFC)
This patch replaces calls to GreatestCommonDivisor64 with std::gcd
where both arguments are known to be of unsigned types no larger than
64 bits in size.
Added:
Modified:
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/MCA/Support.cpp
llvm/lib/Transforms/Utils/LoopUnroll.cpp
mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/ScalarEvolution.cpp b/llvm/lib/Analysis/ScalarEvolution.cpp
index 6a180f1675cd7..e447345339716 100644
--- a/llvm/lib/Analysis/ScalarEvolution.cpp
+++ b/llvm/lib/Analysis/ScalarEvolution.cpp
@@ -126,6 +126,7 @@
#include <cstdlib>
#include <map>
#include <memory>
+#include <numeric>
#include <tuple>
#include <utility>
#include <vector>
@@ -8091,7 +8092,7 @@ unsigned ScalarEvolution::getSmallConstantTripMultiple(const Loop *L) {
unsigned Multiple = getSmallConstantTripMultiple(L, ExitingBB);
if (!Res)
Res = Multiple;
- Res = (unsigned)GreatestCommonDivisor64(*Res, Multiple);
+ Res = (unsigned)std::gcd(*Res, Multiple);
}
return Res.value_or(1);
}
diff --git a/llvm/lib/MCA/Support.cpp b/llvm/lib/MCA/Support.cpp
index ce1f0f6f211b5..517738c959fc7 100644
--- a/llvm/lib/MCA/Support.cpp
+++ b/llvm/lib/MCA/Support.cpp
@@ -14,6 +14,7 @@
#include "llvm/MCA/Support.h"
#include "llvm/MC/MCSchedule.h"
+#include <numeric>
namespace llvm {
namespace mca {
@@ -26,7 +27,7 @@ ResourceCycles &ResourceCycles::operator+=(const ResourceCycles &RHS) {
else {
// Create a common denominator for LHS and RHS by calculating the least
// common multiple from the GCD.
- unsigned GCD = GreatestCommonDivisor64(Denominator, RHS.Denominator);
+ unsigned GCD = std::gcd(Denominator, RHS.Denominator);
unsigned LCM = (Denominator * RHS.Denominator) / GCD;
unsigned LHSNumerator = Numerator * (LCM / Denominator);
unsigned RHSNumerator = RHS.Numerator * (LCM / RHS.Denominator);
diff --git a/llvm/lib/Transforms/Utils/LoopUnroll.cpp b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
index 1be1082002fc8..75961a1d898c1 100644
--- a/llvm/lib/Transforms/Utils/LoopUnroll.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUnroll.cpp
@@ -66,6 +66,7 @@
#include "llvm/Transforms/Utils/ValueMapper.h"
#include <algorithm>
#include <assert.h>
+#include <numeric>
#include <type_traits>
#include <vector>
@@ -341,7 +342,7 @@ LoopUnrollResult llvm::UnrollLoop(Loop *L, UnrollLoopOptions ULO, LoopInfo *LI,
Info.TripMultiple = 0;
} else {
Info.BreakoutTrip = Info.TripMultiple =
- (unsigned)GreatestCommonDivisor64(ULO.Count, Info.TripMultiple);
+ (unsigned)std::gcd(ULO.Count, Info.TripMultiple);
}
Info.ExitOnTrue = !L->contains(BI->getSuccessor(0));
Info.ExitingBlocks.push_back(ExitingBlock);
diff --git a/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp b/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
index 7a39b3a89921d..db89d93040fa1 100644
--- a/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
+++ b/mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
@@ -23,6 +23,7 @@
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
+#include <numeric>
#include <type_traits>
using namespace mlir;
@@ -133,7 +134,7 @@ uint64_t mlir::getLargestDivisorOfTripCount(AffineForOp forOp) {
thisGcd = resultExpr.getLargestKnownDivisor();
}
if (gcd.has_value())
- gcd = llvm::GreatestCommonDivisor64(gcd.value(), thisGcd);
+ gcd = std::gcd(gcd.value(), thisGcd);
else
gcd = thisGcd;
}
More information about the llvm-commits
mailing list