[Mlir-commits] [mlir] 867c7b5 - [MLIR][Presburger] Optimize for intersect
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Jul 11 07:14:04 PDT 2023
Author: gilsaia
Date: 2023-07-11T19:35:48+05:30
New Revision: 867c7b5cc061c78a6c2387812cbe5b8bf1c84e0b
URL: https://github.com/llvm/llvm-project/commit/867c7b5cc061c78a6c2387812cbe5b8bf1c84e0b
DIFF: https://github.com/llvm/llvm-project/commit/867c7b5cc061c78a6c2387812cbe5b8bf1c84e0b.diff
LOG: [MLIR][Presburger] Optimize for intersect
Added a series of optimizations to the Intersect function of PresburgerRelation, referring to the ISL implementation.
Tested it on a simple Benchmark implemented by myself to see that it can speed up the Intersect operation
The Benchmark can be found here:https://github.com/gilsaia/llvm-project-test-fpl/blob/develop_benchmark/mlir/benchmark/presburger/Benchmark.cpp
The overall results for Intersect are as follows
{F28191553}
The results for each case are as follows
{F28191556}
Reviewed By: Groverkss
Differential Revision: https://reviews.llvm.org/D154771
Added:
Modified:
mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
Removed:
################################################################################
diff --git a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
index 278d70a12c22bc..adcab9ba2a4ab6 100644
--- a/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
+++ b/mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
@@ -131,6 +131,17 @@ class PresburgerRelation {
/// 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<MPInt> &sample);
diff --git a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
index 440de3c12faf3b..4fe63a682dda10 100644
--- a/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
+++ b/mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
@@ -98,6 +98,14 @@ PresburgerRelation
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 @@ bool PresburgerRelation::isEqual(const PresburgerRelation &set) const {
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 {
More information about the Mlir-commits
mailing list