From 4a2377afd69bcf014492cb665ee955eab3121c4c Mon Sep 17 00:00:00 2001 From: Kazu Hirata Date: Sun, 28 Aug 2022 10:41:53 -0700 Subject: [PATCH] Use std::gcd (NFC) To avoid changing semantics inadvertently, this patch casts arguments to uint64_t before calling std::gcd. --- mlir/lib/Analysis/Presburger/IntegerRelation.cpp | 2 +- mlir/lib/Analysis/Presburger/Utils.cpp | 2 +- mlir/lib/IR/AffineExpr.cpp | 15 +++++++-------- polly/lib/Analysis/ScopInfo.cpp | 3 ++- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp index e0c0acdd8f8df..18b48b5cdc8e2 100644 --- a/mlir/lib/Analysis/Presburger/IntegerRelation.cpp +++ b/mlir/lib/Analysis/Presburger/IntegerRelation.cpp @@ -659,7 +659,7 @@ bool IntegerRelation::isEmptyByGCDTest() const { for (unsigned i = 0, e = getNumEqualities(); i < e; ++i) { uint64_t gcd = std::abs(atEq(i, 0)); for (unsigned j = 1; j < numCols - 1; ++j) { - gcd = llvm::GreatestCommonDivisor64(gcd, std::abs(atEq(i, j))); + gcd = std::gcd(gcd, (uint64_t)std::abs(atEq(i, j))); } int64_t v = std::abs(atEq(i, numCols - 1)); if (gcd > 0 && (v % gcd != 0)) { diff --git a/mlir/lib/Analysis/Presburger/Utils.cpp b/mlir/lib/Analysis/Presburger/Utils.cpp index ccb9ef71fa3dd..c3ac8232c6ec5 100644 --- a/mlir/lib/Analysis/Presburger/Utils.cpp +++ b/mlir/lib/Analysis/Presburger/Utils.cpp @@ -316,7 +316,7 @@ SmallVector presburger::getDivLowerBound(ArrayRef dividend, int64_t presburger::gcdRange(ArrayRef range) { int64_t gcd = 0; for (int64_t elem : range) { - gcd = llvm::GreatestCommonDivisor64(gcd, std::abs(elem)); + gcd = std::gcd((uint64_t)gcd, (uint64_t)std::abs(elem)); if (gcd == 1) return gcd; } diff --git a/mlir/lib/IR/AffineExpr.cpp b/mlir/lib/IR/AffineExpr.cpp index 38db97be2a7db..991a644d9d8f1 100644 --- a/mlir/lib/IR/AffineExpr.cpp +++ b/mlir/lib/IR/AffineExpr.cpp @@ -16,6 +16,7 @@ #include "mlir/Support/MathExtras.h" #include "mlir/Support/TypeID.h" #include "llvm/ADT/STLExtras.h" +#include using namespace mlir; using namespace mlir::detail; @@ -235,9 +236,8 @@ int64_t AffineExpr::getLargestKnownDivisor() const { [[fallthrough]]; case AffineExprKind::Mod: { binExpr = cast(); - return llvm::GreatestCommonDivisor64( - binExpr.getLHS().getLargestKnownDivisor(), - binExpr.getRHS().getLargestKnownDivisor()); + return std::gcd((uint64_t)binExpr.getLHS().getLargestKnownDivisor(), + (uint64_t)binExpr.getRHS().getLargestKnownDivisor()); } } llvm_unreachable("Unknown AffineExpr"); @@ -267,9 +267,8 @@ bool AffineExpr::isMultipleOf(int64_t factor) const { case AffineExprKind::CeilDiv: case AffineExprKind::Mod: { binExpr = cast(); - return llvm::GreatestCommonDivisor64( - binExpr.getLHS().getLargestKnownDivisor(), - binExpr.getRHS().getLargestKnownDivisor()) % + return std::gcd((uint64_t)binExpr.getLHS().getLargestKnownDivisor(), + (uint64_t)binExpr.getRHS().getLargestKnownDivisor()) % factor == 0; } @@ -1201,7 +1200,7 @@ void SimpleAffineExprFlattener::visitModExpr(AffineBinaryOpExpr expr) { SmallVector floorDividend(lhs); uint64_t gcd = rhsConst; for (unsigned i = 0, e = lhs.size(); i < e; i++) - gcd = llvm::GreatestCommonDivisor64(gcd, std::abs(lhs[i])); + gcd = std::gcd(gcd, (uint64_t)std::abs(lhs[i])); // Simplify the numerator and the denominator. if (gcd != 1) { for (unsigned i = 0, e = floorDividend.size(); i < e; i++) @@ -1313,7 +1312,7 @@ void SimpleAffineExprFlattener::visitDivExpr(AffineBinaryOpExpr expr, // common divisors of the numerator and denominator. uint64_t gcd = std::abs(rhsConst); for (unsigned i = 0, e = lhs.size(); i < e; i++) - gcd = llvm::GreatestCommonDivisor64(gcd, std::abs(lhs[i])); + gcd = std::gcd(gcd, (uint64_t)std::abs(lhs[i])); // Simplify the numerator and the denominator. if (gcd != 1) { for (unsigned i = 0, e = lhs.size(); i < e; i++) diff --git a/polly/lib/Analysis/ScopInfo.cpp b/polly/lib/Analysis/ScopInfo.cpp index d8196c34a051d..bbbb17714ea10 100644 --- a/polly/lib/Analysis/ScopInfo.cpp +++ b/polly/lib/Analysis/ScopInfo.cpp @@ -67,6 +67,7 @@ #include "isl/options.h" #include "isl/set.h" #include +#include using namespace llvm; using namespace polly; @@ -292,7 +293,7 @@ void ScopArrayInfo::updateElementType(Type *NewElementType) { if (NewElementSize % OldElementSize == 0 && NewElementSize < OldElementSize) { ElementType = NewElementType; } else { - auto GCD = GreatestCommonDivisor64(NewElementSize, OldElementSize); + auto GCD = std::gcd((uint64_t)NewElementSize, (uint64_t)OldElementSize); ElementType = IntegerType::get(ElementType->getContext(), GCD); } }