This is an archive of the discontinued LLVM Phabricator instance.

[mlir][bufferize] Eliminate tensor.empty ops instead of bufferization.alloc_tensor ops
ClosedPublic

Authored by springerm on Nov 1 2022, 6:48 AM.

Details

Summary

tensor.empty op elimination is an optimization that brings IR in a more bufferization-friendly form. E.g.:

%0 = tensor.empty()
%1 = linalg.fill(%cst, %0) {inplace = [true]}
%2 = tensor.insert_slice %1 into %t[10][20][1]

Is rewritten to:

%0 = tensor.extract_slice %t[10][20][1]
%1 = linalg.fill(%cst, %0) {inplace = [true]}
%2 = tensor.insert_slice %1 into %t[10][20][1]

This optimization used to operate on bufferization.alloc_tensor ops. This is not correct because the documentation of bufferization.alloc_tensor says that it always bufferizes to an allocation. Instead, this optimization should operate on tensor.empty ops, which can then be lowered to bufferization.alloc_tensor ops (if they don't get eliminated).

Diff Detail

Event Timeline

springerm created this revision.Nov 1 2022, 6:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2022, 6:48 AM
springerm requested review of this revision.Nov 1 2022, 6:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 1 2022, 6:48 AM
nicolasvasilache accepted this revision.Nov 9 2022, 3:50 AM
This revision is now accepted and ready to land.Nov 9 2022, 3:50 AM
This revision was landed with ongoing or failed builds.Nov 11 2022, 2:43 AM
This revision was automatically updated to reflect the committed changes.