Skip to content

Commit b68e78c

Browse files
committed
[MLIR][Prebsurger] Add IntegerRelation::intersect supporting locals properly
Reviewed By: Groverkss Differential Revision: https://reviews.llvm.org/D122149
1 parent 7f61124 commit b68e78c

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

mlir/include/mlir/Analysis/Presburger/IntegerRelation.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ class IntegerRelation : public PresburgerLocalSpace {
9595
/// intersection with no simplification of any sort attempted.
9696
void append(const IntegerRelation &other);
9797

98+
/// Return the intersection of the two sets.
99+
/// If there are locals, they will be merged.
100+
IntegerRelation intersect(IntegerRelation other) const;
101+
98102
/// Return whether `this` and `other` are equal. This is integer-exact
99103
/// and somewhat expensive, since it uses the integer emptiness check
100104
/// (see IntegerRelation::findIntegerSample()).

mlir/lib/Analysis/Presburger/IntegerRelation.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ void IntegerRelation::append(const IntegerRelation &other) {
5252
}
5353
}
5454

55+
IntegerRelation IntegerRelation::intersect(IntegerRelation other) const {
56+
IntegerRelation result = *this;
57+
result.mergeLocalIds(other);
58+
result.append(other);
59+
return result;
60+
}
61+
5562
bool IntegerRelation::isEqual(const IntegerRelation &other) const {
5663
assert(PresburgerLocalSpace::isEqual(other) && "Spaces must be equal.");
5764
return PresburgerRelation(*this).isEqual(PresburgerRelation(other));

mlir/lib/Analysis/Presburger/PresburgerRelation.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ PresburgerRelation::intersect(const PresburgerRelation &set) const {
9797
getNumSymbolIds());
9898
for (const IntegerRelation &csA : integerRelations) {
9999
for (const IntegerRelation &csB : set.integerRelations) {
100-
IntegerRelation csACopy = csA, csBCopy = csB;
101-
csACopy.mergeLocalIds(csBCopy);
102-
csACopy.append(csBCopy);
103-
if (!csACopy.isEmpty())
104-
result.unionInPlace(csACopy);
100+
IntegerRelation intersection = csA.intersect(csB);
101+
if (!intersection.isEmpty())
102+
result.unionInPlace(intersection);
105103
}
106104
}
107105
return result;

0 commit comments

Comments
 (0)