[Mlir-commits] [mlir] ec5f18e - [MLIR][Presburger] MPInt: gcd: assert that operands are non-negative

Arjun P llvmlistbot at llvm.org
Fri Jul 15 06:14:35 PDT 2022


Author: Arjun P
Date: 2022-07-15T14:13:41+01:00
New Revision: ec5f18e38afa93f238456f56e5d8b9a1bd44ec12

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

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

Added: 
    

Modified: 
    mlir/include/mlir/Analysis/Presburger/MPInt.h

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Analysis/Presburger/MPInt.h b/mlir/include/mlir/Analysis/Presburger/MPInt.h
index 8098192a96746..85288f82cd090 100644
--- a/mlir/include/mlir/Analysis/Presburger/MPInt.h
+++ b/mlir/include/mlir/Analysis/Presburger/MPInt.h
@@ -195,6 +195,7 @@ class MPInt {
   friend MPInt gcdRange(ArrayRef<MPInt> range);
   friend MPInt ceilDiv(const MPInt &lhs, const MPInt &rhs);
   friend MPInt floorDiv(const MPInt &lhs, const MPInt &rhs);
+  // The operands must be non-negative for gcd.
   friend MPInt gcd(const MPInt &a, const MPInt &b);
   friend MPInt lcm(const MPInt &a, const MPInt &b);
   friend MPInt mod(const MPInt &lhs, const MPInt &rhs);
@@ -382,6 +383,7 @@ LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt mod(const MPInt &lhs, const MPInt &rhs) {
 }
 
 LLVM_ATTRIBUTE_ALWAYS_INLINE MPInt gcd(const MPInt &a, const MPInt &b) {
+  assert(a >= 0 && b >= 0 && "operands must be non-negative!");
   if (LLVM_LIKELY(a.isSmall() && b.isSmall()))
     return MPInt(llvm::greatestCommonDivisor(a.getSmall(), b.getSmall()));
   return MPInt(gcd(detail::SlowMPInt(a), detail::SlowMPInt(b)));


        


More information about the Mlir-commits mailing list