This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferization] Support multiple leaves in EmptyTensorElimination
ClosedPublic

Authored by springerm on Jan 19 2023, 8:39 AM.

Details

Summary

Support cases where a source tensor can be traced back to multiple possible tensor.empty ops.

Example:

%0 = scf.if ... {
  %1 = tensor.empty()
  %2 = "some_op"(%1)
  scf.yield %2
} else {
  ...
}
%3 = tensor.insert_slice %0 into %t

The tensor.empty inside the scf.if can now be rewritten to a tensor.extract_slice, allowing it to bufferize without an allocation.

Depends On: D142129

Diff Detail

Event Timeline

springerm created this revision.Jan 19 2023, 8:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 8:39 AM
springerm requested review of this revision.Jan 19 2023, 8:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2023, 8:39 AM
springerm updated this revision to Diff 496157.Feb 9 2023, 9:22 AM

simplify impl

mravishankar accepted this revision.Feb 9 2023, 10:03 AM

Have one comment here, more for my understanding of the nuances. Change itself looks good!

mlir/lib/Dialect/Bufferization/Transforms/EmptyTensorElimination.cpp
116

Comment needs to be updated? Now it seems like you can return multiple tensor.empty... I dont know when that happens though

This revision is now accepted and ready to land.Feb 9 2023, 10:03 AM
springerm marked an inline comment as done.Feb 10 2023, 12:40 AM