This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Presburger] Add simplify function
Needs ReviewPublic

Authored by gilsaia on Aug 2 2023, 6:16 AM.

Details

Reviewers
Groverkss
arjunp
Summary

Added the simplify function to reduce the size of the constraint system, referencing the ISL implementation.

Tested it on a simple Benchmark implemented by myself, calling SImplify before the operation and calling Simplify on the result after Subtract were tested, respectively.

The Benchmark can be found here: benchmark

For the case of calling Simplify before each operation, the overall result is shown in the following figure.

A comparison of the constraint system sizes and time for each operation is as follows

For the case of calling Simplify on the result after Subtract, the overall results are as follows

A comparison of the constraint system sizes and time for subtract is as follows

Diff Detail

Event Timeline

gilsaia created this revision.Aug 2 2023, 6:16 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2023, 6:16 AM
gilsaia requested review of this revision.Aug 2 2023, 6:16 AM
gilsaia edited the summary of this revision. (Show Details)Aug 2 2023, 6:24 AM
gilsaia added a reviewer: Groverkss.
gilsaia edited the summary of this revision. (Show Details)Aug 4 2023, 7:13 PM
gilsaia edited the summary of this revision. (Show Details)Aug 4 2023, 8:05 PM
gilsaia edited the summary of this revision. (Show Details)Aug 4 2023, 8:20 PM

Some initial comments.

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

markSetEmpty is a better name maybe.

338

If you are marking something as empty using this special constraint, could you add a check in isPlainEmpty which checks if the set is exactly this condition at start?

562

Do we have to return this "empty" thing here? Simplify should just simplify it and emptiness should be checked with "isPlainEmpty".

745

You don't need to specify this, I feel.

745
746

"Return value indicates if anything was modified"

780–781

Instead of number of constraints, its better if you say "If anything has changed", because you could be changing coefficient values also.

mlir/lib/Analysis/Presburger/IntegerRelation.cpp
450

Please avoid the use of auto unless needed.

451

Use SmallVector instead.

453

You don't need to do this. Just pass eqeff to addEquality.

1331
Groverkss added a subscriber: grosser.

Does this function some correspondence to isl?

mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
780–781

Also, I am not sure what redundant means here. The 'identical' seems to imply that you just drop syntactically identical constraints, but constraints might also be implied by others. Are these implied constraints also eliminated?

gilsaia updated this revision to Diff 548186.Aug 8 2023, 6:19 AM
  • [fix] change comment & add isplainempty
gilsaia marked 11 inline comments as done.Aug 8 2023, 6:24 AM
gilsaia added inline comments.
mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
338

I just added isPlainEmpty function to IntegerRelation.

780–781

In addition to the same inequality, it checks if there is a completely opposite inequality except for the constant term, and either discards or converts it to an equation based on the result of the constant term.

gilsaia marked an inline comment as done.Aug 8 2023, 6:28 AM
gilsaia added inline comments.
mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
780–781

Also, there is a function in ISL that does essentially the same thing called isl_basic_map_remove_duplicate_constraints.

gilsaia marked an inline comment as done.Aug 14 2023, 7:11 AM
arjunp added inline comments.Aug 18 2023, 12:02 AM
mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
338

I would prefer a getEmpty() like in PresburgerRelation and then *this = getEmpty(getSpace())

560–561

Maybe briefly describe the kind of simplifications and how long they take to run here.

mlir/include/mlir/Analysis/Presburger/PresburgerRelation.h
193

I prefer "Simplify each disjunct; see IntegerRelation::simplify for details."

mlir/lib/Analysis/Presburger/IntegerRelation.cpp
704

I prefer a name like isObviouslyEmpty. "plain" isn't very clear IMO (I know isl uses it)

mlir/lib/Analysis/Presburger/PresburgerRelation.cpp
966

Why does this function modify this as well as return a new relation. It should be one or the other.

967
gilsaia updated this revision to Diff 551545.Aug 18 2023, 9:15 AM
  • [fix] add comment & fix bug
gilsaia marked 5 inline comments as done.Aug 18 2023, 9:18 AM
gilsaia added inline comments.
mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
338

But I think that in IntegerRelation, empty means Universe, so markempty here actually adds an impossible constraint

mlir/lib/Analysis/Presburger/IntegerRelation.cpp
704

I think the naming here should be kept uniform with other similar functions, so do we need to change all the similar function names?

arjunp added inline comments.Aug 20 2023, 9:47 PM
mlir/include/mlir/Analysis/Presburger/IntegerRelation.h
338

It's true that an empty list of constraints in IntegerRelation corresponds to the universe, the set of all points. But "empty" doesn't refer to universe! It means the empty set. I would suggest making both getUniverse and getEmpty functions, so it's clear which is which.

mlir/lib/Analysis/Presburger/IntegerRelation.cpp
704

AFAIK there is no currently upstream function that uses it. Yes, I would suggest that for your functions.

gilsaia updated this revision to Diff 552016.Aug 21 2023, 7:43 AM
gilsaia marked an inline comment as done.
  • [fix] from plain to obviously & add getEmpty
gilsaia marked 3 inline comments as done.Aug 21 2023, 7:44 AM