This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferization] Add pattern to BufferDeallocationSimplification pass that removes unnecessary retain values
ClosedPublic

Authored by maerhart on Aug 8 2023, 9:05 AM.

Details

Summary

Adds a pattern that removes memrefs from the retained list which are
guaranteed to not alias any memref in the memrefs list. The corresponding
result value can be replaced with false in that case according to the
operation description.

When applied after BufferDeallocation, this can considerably reduce the
overhead that needs to be added during the lowering of the dealloc operation to
check for aliasing (especially when there is only one element in the memref
list and all retained values can be removed).

Depends on D157398

Diff Detail

Event Timeline

maerhart created this revision.Aug 8 2023, 9:05 AM
Herald added a project: Restricted Project. · View Herald Transcript
maerhart requested review of this revision.Aug 8 2023, 9:05 AM
springerm accepted this revision.Aug 9 2023, 6:31 AM
springerm added inline comments.
mlir/lib/Dialect/Bufferization/Transforms/BufferDeallocationSimplification.cpp
199–201

Nit: I would put a lambda just after falseValue:

auto getOrCreateFalse = [&]() { if ... rewriter.create<artith::ConstantOp>(...) ...};
mlir/test/Dialect/Bufferization/Transforms/buffer-deallocation-simplification.mlir
12

will this fold away with -canonicalize?

This revision is now accepted and ready to land.Aug 9 2023, 6:31 AM
maerhart added inline comments.Aug 9 2023, 7:06 AM
mlir/test/Dialect/Bufferization/Transforms/buffer-deallocation-simplification.mlir
12

Yes exactly, the canonicalizer removes such dealloc operations.

maerhart updated this revision to Diff 548898.Aug 10 2023, 12:39 AM
maerhart marked 2 inline comments as done.

Add lambda.