[Mlir-commits] [mlir] 86d73c1 - [MLIR][Presburger] SlowMPInt: gcd: assert that operands are non-negative

Arjun P llvmlistbot at llvm.org
Fri Jul 15 07:50:21 PDT 2022


Author: Arjun P
Date: 2022-07-15T15:45:53+01:00
New Revision: 86d73c11cff6acf071f8b04196ca98ea8304369d

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

LOG: [MLIR][Presburger] SlowMPInt: gcd: assert that operands are non-negative

Added: 
    

Modified: 
    mlir/include/mlir/Analysis/Presburger/SlowMPInt.h
    mlir/lib/Analysis/Presburger/SlowMPInt.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/Presburger/SlowMPInt.h b/mlir/include/mlir/Analysis/Presburger/SlowMPInt.h
index ce9df02b7ec9f..c70306761c549 100644
--- a/mlir/include/mlir/Analysis/Presburger/SlowMPInt.h
+++ b/mlir/include/mlir/Analysis/Presburger/SlowMPInt.h
@@ -66,6 +66,7 @@ class SlowMPInt {
   friend SlowMPInt abs(const SlowMPInt &x);
   friend SlowMPInt ceilDiv(const SlowMPInt &lhs, const SlowMPInt &rhs);
   friend SlowMPInt floorDiv(const SlowMPInt &lhs, const SlowMPInt &rhs);
+  /// The operands must be non-negative for gcd.
   friend SlowMPInt gcd(const SlowMPInt &a, const SlowMPInt &b);
 
   /// Overload to compute a hash_code for a SlowMPInt value.

diff  --git a/mlir/lib/Analysis/Presburger/SlowMPInt.cpp b/mlir/lib/Analysis/Presburger/SlowMPInt.cpp
index 31eecac99b7c0..daeaf09ddb857 100644
--- a/mlir/lib/Analysis/Presburger/SlowMPInt.cpp
+++ b/mlir/lib/Analysis/Presburger/SlowMPInt.cpp
@@ -218,8 +218,8 @@ SlowMPInt detail::mod(const SlowMPInt &lhs, const SlowMPInt &rhs) {
 }
 
 SlowMPInt detail::gcd(const SlowMPInt &a, const SlowMPInt &b) {
-  return SlowMPInt(
-      llvm::APIntOps::GreatestCommonDivisor(a.val.abs(), b.val.abs()));
+  assert(a >= 0 && b >= 0 && "operands must be non-negative!");
+  return SlowMPInt(llvm::APIntOps::GreatestCommonDivisor(a.val, b.val));
 }
 
 /// Returns the least common multiple of 'a' and 'b'.


        


More information about the Mlir-commits mailing list