[MLIR][Presburger] SlowMPInt: gcd: assert that operands are non-negative
authorArjun P <arjunpitchanathan@gmail.com>
Fri, 15 Jul 2022 14:32:15 +0000 (15:32 +0100)
committerArjun P <arjunpitchanathan@gmail.com>
Fri, 15 Jul 2022 14:45:53 +0000 (15:45 +0100)
mlir/include/mlir/Analysis/Presburger/SlowMPInt.h
mlir/lib/Analysis/Presburger/SlowMPInt.cpp

index ce9df02..c703067 100644 (file)
@@ -66,6 +66,7 @@ public:
   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.
index 31eecac..daeaf09 100644 (file)
@@ -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'.