This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferization] Add pattern to BufferDeallocationSimplification pass
ClosedPublic

Authored by maerhart on Aug 9 2023, 7:34 AM.

Details

Summary

Add a pattern that splits one dealloc operation into multiple dealloc operation
depending on static aliasing information of the values in the memref operand
list. This reduces the total number of aliasing checks required at runtime and
can enable futher canonicalizations of the new and simplified dealloc
operations.

Depends on D157407

Diff Detail

Event Timeline

maerhart created this revision.Aug 9 2023, 7:34 AM
Herald added a project: Restricted Project. · View Herald Transcript
maerhart requested review of this revision.Aug 9 2023, 7:34 AM
springerm added inline comments.Aug 14 2023, 3:14 AM
mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocationSimplification.cpp
51

Add comment. Also describe why allowSelfAlias is useful.

213

does it matter?

mlir/test/Dialect/Bufferization/Transforms/buffer-deallocation-simplification.mlir
62

Does the analysis make any assumptions about the aliasing of two function bbArgs?

71

Can you describe in the comment why the retain list has only one element.

maerhart added inline comments.Aug 14 2023, 3:31 AM
mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocationSimplification.cpp
213

No, just thought it makes it easier to understand that this adds additional dealloc operations, but I can also remove it.

mlir/test/Dialect/Bufferization/Transforms/buffer-deallocation-simplification.mlir
62

It's may-alias by default (even if the types don't match). There is a restricted attribute that can be added to functions though, which indicates that no aliasing should be assumed.

71

This is the result of another pattern which removes unnecessary retained memrefs and because of that I did not add this simplification to the example above the pattern in the CPP file. I can add a comment to the test here though to make maintenance easier.
Might be worth it though to split the file first, then have a separate run command for each pattern such that adding a new pattern does not affect already present patterns.

springerm accepted this revision.Aug 14 2023, 3:33 AM
springerm added inline comments.
mlir/test/Dialect/Bufferization/Transforms/buffer-deallocation-simplification.mlir
71

Just add a comment to the test case that describes the two optimizations that are happening here. That's good enough.

This revision is now accepted and ready to land.Aug 14 2023, 3:33 AM
maerhart updated this revision to Diff 549989.Aug 14 2023, 9:24 AM
maerhart marked 5 inline comments as done.

Address comments.