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

This commit is contained in:
Arjun P 2022-07-15 15:32:15 +01:00
parent 07022e6cf9
commit 86d73c11cf
2 changed files with 3 additions and 2 deletions

View 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.

View 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'.