[Mlir-commits] [mlir] 4a2377a - Use std::gcd (NFC)

Kazu Hirata llvmlistbot at llvm.org
Sun Aug 28 10:42:10 PDT 2022


Author: Kazu Hirata
Date: 2022-08-28T10:41:53-07:00
New Revision: 4a2377afd69bcf014492cb665ee955eab3121c4c

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

LOG: Use std::gcd (NFC)

To avoid changing semantics inadvertently, this patch casts arguments
to uint64_t before calling std::gcd.

Added: 
    

Modified: 
    mlir/lib/Analysis/Presburger/IntegerRelation.cpp
    mlir/lib/Analysis/Presburger/Utils.cpp
    mlir/lib/IR/AffineExpr.cpp
    polly/lib/Analysis/ScopInfo.cpp

Removed: 
    


################################################################################
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<int64_t, 8> presburger::getDivLowerBound(ArrayRef<int64_t> dividend,
 int64_t presburger::gcdRange(ArrayRef<int64_t> 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 <numeric>
 
 using namespace mlir;
 using namespace mlir::detail;
@@ -235,9 +236,8 @@ int64_t AffineExpr::getLargestKnownDivisor() const {
     [[fallthrough]];
   case AffineExprKind::Mod: {
     binExpr = cast<AffineBinaryOpExpr>();
-    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<AffineBinaryOpExpr>();
-    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<int64_t, 8> 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 <cassert>
+#include <numeric>
 
 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);
   }
 }


        


More information about the Mlir-commits mailing list