This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Add functionality to remove redundant local variables
ClosedPublic

Authored by Groverkss on Sep 20 2021, 2:40 AM.

Details

Summary

This patch adds functionality to FlatAffineConstraints to remove local
variables using equalities. This helps in keeping output representation of
FlatAffineConstraints smaller.

This patch is part of a series of patches aimed at generalizing affine
dependence analysis.

Diff Detail

Event Timeline

Groverkss created this revision.Sep 20 2021, 2:40 AM
Groverkss requested review of this revision.Sep 20 2021, 2:40 AM
bondhugula requested changes to this revision.Sep 20 2021, 10:42 PM
bondhugula added inline comments.
mlir/include/mlir/Analysis/AffineStructures.h
480

variables -> variable

mlir/lib/Analysis/AffineStructures.cpp
1794

In the form this is being added, this would be dead code as it isn't being used anywhere. Please update a path to use it so that this gets tested if there is no separate test case just for this.

1798

unsigned

1798

Use i = 0, e = ... form.

This revision now requires changes to proceed.Sep 20 2021, 10:42 PM
Groverkss updated this revision to Diff 373872.Sep 21 2021, 5:22 AM
Groverkss marked 3 inline comments as done.
  • Addressed bondhugula's comments

Used removeRedundantLocalVars to improve isEmpty coverage. Added a test that
would not work without simplification.

Groverkss marked an inline comment as done.Sep 21 2021, 5:23 AM

Addressed comments

mlir/lib/Analysis/AffineStructures.cpp
1798

The reason for not using unsigned is that there is a --i inside the loop. If i = 0 and i is unsigned, it will overflow.

1798

The reason for not using this form is that an equality may be removed inside the loop.

bondhugula added inline comments.Sep 21 2021, 12:53 PM
mlir/lib/Analysis/AffineStructures.cpp
1791

variables -> variable

1821–1822

Why do you need to decrement here if you are going to anyway break out below.

bondhugula requested changes to this revision.Sep 21 2021, 1:13 PM
bondhugula added inline comments.
mlir/lib/Analysis/AffineStructures.cpp
1799–1821

This whole loop's logic can be simplified/broken apart for better readability.

For eg., invert the check:

for ...
  if (foundOne)
    break;

Then, have a block below outside of the for loop.

if (i < getNumEqualities()) {
  ...
}

getNumEqualities() in the for loop header isn't changing at all. You are breaking out when you need to remove an equality.

This revision now requires changes to proceed.Sep 21 2021, 1:13 PM
Groverkss updated this revision to Diff 374023.Sep 21 2021, 1:48 PM
Groverkss marked 3 inline comments as done.
  • Simplified loop in removeRedundantLocalVars

Addressed comments.

mlir/lib/Analysis/AffineStructures.cpp
1799–1821

Oh, Sorry. I misunderstood something. Thanks.

bondhugula added inline comments.Sep 21 2021, 8:42 PM
mlir/lib/Analysis/AffineStructures.cpp
1803

Please terminate all comments with a full stop - here and above. They should all be properly punctuated per LLVM/MLIR style.

1808

This is again confusing. i can't be greater than e. i == e here.

1808

Code comment here.

Groverkss updated this revision to Diff 374172.Sep 22 2021, 3:26 AM
Groverkss marked 3 inline comments as done.
  • Addressed bondhugula's comments

Addressed comments.

bondhugula added inline comments.Sep 23 2021, 12:45 AM
mlir/lib/Analysis/AffineStructures.cpp
945

Missing period at the end.

950

Reflow: wse the width.

1821

Do we need this normalization here? If yes, can you check the call sites to make sure it's not being redundantly called? This is doing some more basic simplification beyond just removing local vars -- it's fine to do as long as it's trivial and inexpensive to be considered more like a cleanup. Best to add a comment here or on the function.

mlir/unittests/Analysis/AffineStructuresTest.cpp
772–778

It'd be good to a couple more test cases to exercise it better.

773

Full stop at the end.

bondhugula requested changes to this revision.Sep 24 2021, 2:06 AM
This revision now requires changes to proceed.Sep 24 2021, 2:06 AM
Groverkss updated this revision to Diff 374937.Sep 24 2021, 1:00 PM
Groverkss marked 5 inline comments as done.
  • Addressed comments

Addressed @bondhugula's comments.

Groverkss updated this revision to Diff 374944.Sep 24 2021, 1:23 PM
  • Fix incomplete comment
Groverkss updated this revision to Diff 374946.Sep 24 2021, 1:27 PM
  • Fix comment typos
bondhugula accepted this revision.Sep 24 2021, 5:56 PM
This revision is now accepted and ready to land.Sep 24 2021, 5:56 PM
This revision was automatically updated to reflect the committed changes.