diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h --- a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h +++ b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h @@ -131,6 +131,17 @@ /// false otherwise. bool isIntegerEmpty() const; + /// Return true if there is no disjunct, false otherwise. + bool isPlainEmpty() const; + + /// Return true if the set is known to have one unconstrained disjunct, false + /// otherwise. + bool isPlainUniverse() const; + + /// Return true if the set is consist of a single disjunct, without any local + /// variables, false otherwise. + bool isConvexNoLocals() const; + /// Find an integer sample from the given set. This should not be called if /// any of the disjuncts in the union are unbounded. bool findIntegerSample(SmallVectorImpl &sample); diff --git a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp --- a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp +++ b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp @@ -98,6 +98,14 @@ PresburgerRelation::intersect(const PresburgerRelation &set) const { assert(space.isCompatible(set.getSpace()) && "Spaces should match"); + // If the set is empty or the other set is universe, + // directly return the set + if (isPlainEmpty() || set.isPlainUniverse()) + return *this; + + if (set.isPlainEmpty() || isPlainUniverse()) + return set; + PresburgerRelation result(getSpace()); for (const IntegerRelation &csA : disjuncts) { for (const IntegerRelation &csB : set.disjuncts) { @@ -495,6 +503,27 @@ return this->isSubsetOf(set) && set.isSubsetOf(*this); } +/// Return true if the Presburger relation represents the universe set, false +/// otherwise. It is a simple check that only check if the relation has at least +/// one unconstrained disjunct, indicating the absence of constraints or +/// conditions. +bool PresburgerRelation::isPlainUniverse() const { + for (auto &disjunct : getAllDisjuncts()) { + if (disjunct.getNumConstraints() == 0) + return true; + } + return false; +} + +bool PresburgerRelation::isConvexNoLocals() const { + if (getNumDisjuncts() == 1 && getSpace().getNumLocalVars() == 0) + return true; + return false; +} + +/// Return true if there is no disjunct, false otherwise. +bool PresburgerRelation::isPlainEmpty() const { return getNumDisjuncts() == 0; } + /// Return true if all the sets in the union are known to be integer empty, /// false otherwise. bool PresburgerRelation::isIntegerEmpty() const {