This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] PresburgerSet subtraction: fix bug where the set `b` was not restored properly on return
ClosedPublic

Authored by arjunp on Dec 11 2021, 4:51 AM.

Details

Summary

When subtracting b \ c, when there are divisions in c, these division
constraints get added to b. b must be restored to its original state
when returning, but these added divisions constraints were not removed in
one of the return paths. This patch fixes this and deduplicates the
restoration logic by encapuslating it in a lambda restoreState. The patch
also includes a regression test for the bug fix.

Diff Detail

Event Timeline

arjunp created this revision.Dec 11 2021, 4:51 AM
arjunp requested review of this revision.Dec 11 2021, 4:51 AM
arjunp edited the summary of this revision. (Show Details)Dec 11 2021, 5:00 AM
Groverkss added inline comments.Dec 11 2021, 10:56 AM
mlir/lib/Analysis/PresburgerSet.cpp
208–209

Could you maybe remove the last x added divisions instead? The problem with this is, in case mergeLocalIds removes any duplicate inequalities (I plan to do that sometime), it will cause problems here. Removing the last x seems better to me.

mlir/unittests/Analysis/PresburgerSetTest.cpp
664

Could you maybe add a test case where division merging also takes place? Something that has maybe more divisions:

A: [x/5] [y/2] [x/5]
B: [y/2] [x/7] [y/2]

I think this will be useful in the future.

Not exactly sure what kind of test, but something that tests merging and has some duplicate divisions. (It's fine if they are two test cases checking duplicate and merging separately).

arjunp added inline comments.Dec 11 2021, 11:11 AM
mlir/lib/Analysis/PresburgerSet.cpp
208–209

Well, then we have to manually keep track of how many constraints we have added which is error-prone. What exactly do you mean by removing duplicate inequalities?

mlir/unittests/Analysis/PresburgerSetTest.cpp
664

Sure, we should definitely add such tests. But I suppose that would be a separate patch, since it's not really related to the bug of forgetting to rollback added constraints?

Groverkss accepted this revision.Dec 12 2021, 2:27 AM

LGTM.

mlir/lib/Analysis/PresburgerSet.cpp
208–209

I think explaining what I mean would be better when I actually push the changes. This looks fine to me for now.

mlir/unittests/Analysis/PresburgerSetTest.cpp
664

Sure, we can do this as a separate patch.

This revision is now accepted and ready to land.Dec 12 2021, 2:27 AM
mlir/lib/Analysis/PresburgerSet.cpp
204

this feels like you want an RAII llvm::scope_exit to handle all the branches for you automatically.

arjunp added inline comments.Dec 12 2021, 6:25 AM
mlir/lib/Analysis/PresburgerSet.cpp
204

Whoops, nice catch. This is an outdated comment. I eventually decided against it because only one of the return paths actually needs to restore at scope exit, the other one already restores earlier.