This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferization] Add DeallocationSimplification pass
ClosedPublic

Authored by maerhart on Aug 8 2023, 7:41 AM.

Details

Summary

Adds a pass that can be run after buffer deallocation to simplify the deallocation operations.
In particular, there are patterns that need alias information and thus cannot be added as a regular canonicalization pattern.
This initial commit moves an incorrect canonicalization pattern from over to this new pass and fixes it by querying the alias analysis for the additional information it needs to be correct (there must not by any potential aliasing memref in the retain list other than the currently mached one).
Also, improves this pattern by considering the extract_strided_metadata operation which is inserted by the deallocation pass by default.

Diff Detail

Event Timeline

maerhart created this revision.Aug 8 2023, 7:41 AM
Herald added a project: Restricted Project. · View Herald Transcript
maerhart requested review of this revision.Aug 8 2023, 7:41 AM
springerm added inline comments.Aug 9 2023, 6:23 AM
mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocationSimplification.cpp
58

The implementation is doing something with aliasing. Can we capture that in the description here.

67

Let's add an example that adds an arith.ori

97–99

Where is the NoAlias and where is the AlwaysAlias case in the code? There's just a single "if" check below, so it looks like both are handled the same way.

maerhart updated this revision to Diff 548897.Aug 10 2023, 12:20 AM
maerhart marked 3 inline comments as done.

Address comments. Thanks for reviewing!

mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocationSimplification.cpp
67

This example actually adds an arith.ori, it was just missing. Ultimately, it will be canonicalized away by the other patterns though and all that remains of this initial dealloc is %arg1 (the condition) or %cond0 in the updated code.

springerm accepted this revision.Aug 10 2023, 12:52 AM
springerm added inline comments.
mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocationSimplification.cpp
60–61

let's mention that this is needed to compute the result of the op

67

I think this op should have 3 return values?

72

same here

72

Can you add a comment in front of that: bufferization.dealloc without memrefs and conditions returns %true for every retained value.

This revision is now accepted and ready to land.Aug 10 2023, 12:52 AM
maerhart updated this revision to Diff 548918.Aug 10 2023, 1:34 AM
maerhart marked 4 inline comments as done.

Fix description.

mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocationSimplification.cpp
72

Sure! However, it returns %false in that case because that is the identity element of OR and composes nicely in the situations we use dealloc in.
Typically we add all memrefs that have to potentially be deallocated in a given basic block to a single dealloc operation at the end of the block. If we want to split them into multiple dealloc operations, we also need to compute the element-wise disjunction of the results where %false composes nicely because it is the identity element. This also allows us to remove memrefs from the list which have constant false as condition.

maerhart updated this revision to Diff 548922.Aug 10 2023, 1:50 AM

Rebase had messed up something.