This is an archive of the discontinued LLVM Phabricator instance.

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

Authored by maerhart on Aug 22 2023, 8:13 AM.

Details

Summary

This new pattern allows us to simplify the dealloc result value (by replacing
it with a constant 'true') and to trim the 'memref' operand list when we know
that all retained memrefs alias with one in the 'memref' list that has a
constant 'true' condition. Because the conditions of aliasing memrefs are
combined by disjunction, we know that once a single constant 'true' value is in
the disjunction the remaining elements don't matter anymore. This complements
the RemoveDeallocMemrefsContainedInRetained pattern which removes values from
the 'memref' list when static information is available for all retained values
by also allowing to remove values in the presence of may-aliases, but under
above mentioned condition instead.
The BufferDeallocation pass often adds dealloc operations where the memref and
retain lists are the same and all conditions are 'true'. If the operands are
all function arguments, for example, they are always determined to may-alias
which renders the other patterns invalid, but the op could still be trivially
optimized away. It would even be enough to directly compare the two operand
lists and check the conditions are all constant 'true' (plus checking for the
extract_strided_metadata operation), but this pattern is a bit more general and
still works when there are additional memrefs in the 'memref' list that actually
have to be deallocated (e.g., see regression test).

Diff Detail

Event Timeline

maerhart created this revision.Aug 22 2023, 8:13 AM
Herald added a project: Restricted Project. · View Herald Transcript
maerhart requested review of this revision.Aug 22 2023, 8:13 AM
springerm accepted this revision.Aug 23 2023, 2:53 AM
springerm added inline comments.
mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocationSimplification.cpp
334

duplicate

This revision is now accepted and ready to land.Aug 23 2023, 2:53 AM