[Mlir-commits] [mlir] dbb2e74 - [MLIR] Simplex::normalizeRow: early exit when gcd is one

Arjun P llvmlistbot at llvm.org
Wed Jan 5 09:56:35 PST 2022


Author: Arjun P
Date: 2022-01-05T23:26:29+05:30
New Revision: dbb2e74da312489ffcf41fa59a268acf8afeba0e

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

LOG: [MLIR] Simplex::normalizeRow: early exit when gcd is one

Reviewed By: bondhugula

Differential Revision: https://reviews.llvm.org/D116672

Added: 
    

Modified: 
    mlir/lib/Analysis/Presburger/Simplex.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/lib/Analysis/Presburger/Simplex.cpp b/mlir/lib/Analysis/Presburger/Simplex.cpp
index 1e881aa018a2c..3d63ebdb0ca26 100644
--- a/mlir/lib/Analysis/Presburger/Simplex.cpp
+++ b/mlir/lib/Analysis/Presburger/Simplex.cpp
@@ -124,10 +124,14 @@ unsigned SimplexBase::addRow(ArrayRef<int64_t> coeffs) {
 void SimplexBase::normalizeRow(unsigned row) {
   int64_t gcd = 0;
   for (unsigned col = 0; col < nCol; ++col) {
-    if (gcd == 1)
-      break;
     gcd = llvm::greatestCommonDivisor(gcd, std::abs(tableau(row, col)));
+    // If the gcd becomes 1 then the row is already normalized.
+    if (gcd == 1)
+      return;
   }
+
+  // Note that the gcd can never become zero since the first element of the row,
+  // the denominator, is non-zero.
   for (unsigned col = 0; col < nCol; ++col)
     tableau(row, col) /= gcd;
 }


        


More information about the Mlir-commits mailing list