From: Arjun P Date: Fri, 15 Jul 2022 14:32:15 +0000 (+0100) Subject: [MLIR][Presburger] SlowMPInt: gcd: assert that operands are non-negative X-Git-Tag: upstream/15.0.7~1568 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=86d73c11cff6acf071f8b04196ca98ea8304369d;p=platform%2Fupstream%2Fllvm.git [MLIR][Presburger] SlowMPInt: gcd: assert that operands are non-negative --- diff --git a/mlir/include/mlir/Analysis/Presburger/SlowMPInt.h b/mlir/include/mlir/Analysis/Presburger/SlowMPInt.h index ce9df02..c703067 100644 --- a/mlir/include/mlir/Analysis/Presburger/SlowMPInt.h +++ b/mlir/include/mlir/Analysis/Presburger/SlowMPInt.h @@ -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. diff --git a/mlir/lib/Analysis/Presburger/SlowMPInt.cpp b/mlir/lib/Analysis/Presburger/SlowMPInt.cpp index 31eecac..daeaf09 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'.