This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Presburger] support a heuristic for the "cut case" in coalesce
ClosedPublic

Authored by webmiche on Feb 26 2022, 2:57 AM.

Details

Summary

This patch introduces the cut case. If one polytope has only cutting and
redundant inequalities for the other and the facet of the cutting
inequalities are contained within the other polytope, then the polytopes are
be combined into a polytope consisting only of their respective
redundant constraints.

Diff Detail

Event Timeline

webmiche created this revision.Feb 26 2022, 2:57 AM
webmiche requested review of this revision.Feb 26 2022, 2:57 AM
Groverkss added inline comments.Feb 26 2022, 4:30 AM
mlir/lib/Analysis/Presburger/PresburgerSet.cpp
382–384
397–399

I think if i != j, it is already implied that the size of the arrays is at least 2.

400–402

Please add an assert to check that i != j.

417–422
445–446

You should copy number of local ids too.

448–452

You can use range based for loop here.

588–598

Could you write a comment when this case is taken?

webmiche updated this revision to Diff 411607.Feb 26 2022, 6:49 AM

addressed comments

webmiche marked 7 inline comments as done.Feb 26 2022, 6:49 AM
Groverkss added inline comments.Feb 26 2022, 8:29 AM
mlir/lib/Analysis/Presburger/PresburgerSet.cpp
440–441
588–589

Please make all the free functions static.

mlir/lib/Analysis/Presburger/PresburgerSet.cpp
385

I think this should return a bool, it's not really a success/failure result.

387

Pass the cached simp instead of constructin from scratch? You can snapshot, add the equality, check redundancy, then rollback and return

389–393

!isRedundantInequality would be shorter

389–393

can use std::all_of

439–445

drop braces for single-line bodies

456–460

++k

bondhugula added inline comments.
mlir/lib/Analysis/Presburger/PresburgerSet.cpp
389–393

Please drop trivial braces. Please use llvm::all_of.

439–444

Rewrite to use llvm::any_of/all_of.

webmiche updated this revision to Diff 412332.Mar 2 2022, 12:25 AM

Addressed comments and rewrote handling of equalities after finding a case that was impossible to handle currently. The new version types both inequalities that make an equality and considers their types as well.

Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 12:25 AM
webmiche marked 9 inline comments as done.Mar 2 2022, 12:26 AM
webmiche updated this revision to Diff 412335.Mar 2 2022, 12:30 AM

address a minor comment I missed previously

webmiche marked an inline comment as done.Mar 2 2022, 12:30 AM
webmiche updated this revision to Diff 412615.Mar 3 2022, 12:00 AM

In the earlier version, the negated inequality vector was freed before being used. This patch introduces a fix that tracks all negated equalities in a vector throughout coalescePair. In this way, they don't get freed before the new polytope is constructed.

arjunp added inline comments.Mar 3 2022, 4:12 AM
mlir/lib/Analysis/Presburger/PresburgerSet.cpp
391

Why this cast?

433

I feel this name can be more descriptive. What about just calling it coalescePairCutCase?

447

Please capture by reference.

448–449

Why these copies?

503–508

This section is repeated three times in this patch. IMO, you can simply rename typeInequalities to typeInequality, make it take an ArrayRef to an ineq instead of an integer polyhedron, and move the rest of the logic into cutCase directly.

510–513

You can use the static function getComplementIneq

webmiche updated this revision to Diff 412715.Mar 3 2022, 7:27 AM

Address further comments. In particular, made free functions static, refactor typing of inequalities and equalities.

webmiche marked 6 inline comments as done.Mar 3 2022, 7:30 AM
webmiche added inline comments.
mlir/lib/Analysis/Presburger/PresburgerSet.cpp
391

When not capturing by reference, the captured variables are implicitly const. That's why I needed this cast (and the copies further down). Capturing by reference solved the problem.

510–513

Not quite. For t(x), getComplementIneq returns -t(x) - 1, whereas I require -t(x). I guess I can use getComplementIneq and then change the constant, but that seems wasteful IMO.

arjunp added inline comments.Mar 3 2022, 7:46 AM
mlir/lib/Analysis/Presburger/PresburgerSet.cpp
480
498
501

Can this copy be removed?

510–513

Oops, my bad. You can use the function getNegatedCoeffs instead.

531
546–562

You can use poly here

webmiche updated this revision to Diff 412724.Mar 3 2022, 7:56 AM
webmiche marked 2 inline comments as done.

addressed remaining comments.

webmiche marked 6 inline comments as done.Mar 3 2022, 7:56 AM
arjunp accepted this revision.Mar 3 2022, 7:59 AM

LGTM. Please update the documentation too for the variable name change:

mlir/lib/Analysis/Presburger/PresburgerSet.cpp
475
This revision is now accepted and ready to land.Mar 3 2022, 7:59 AM
arjunp retitled this revision from [MLIR][Presburger] cut case in coalesce to [MLIR][Presburger] support a heuristic for the "cut case" in coalesce.Mar 3 2022, 8:01 AM
arjunp edited the summary of this revision. (Show Details)
webmiche updated this revision to Diff 412732.Mar 3 2022, 8:12 AM

addressed last comment

webmiche marked an inline comment as done.Mar 3 2022, 8:12 AM
This revision was landed with ongoing or failed builds.Mar 3 2022, 11:33 PM
This revision was automatically updated to reflect the committed changes.