This is an archive of the discontinued LLVM Phabricator instance.

[mlir][vector] Swap ExtractSliceOp(TransferWriteOp).
ClosedPublic

Authored by gysit on Apr 6 2022, 12:54 AM.

Details

Summary

Rewrite tensor::ExtractSliceOp(vector::TransferWriteOp) to vector::TransferWriteOp(tensor::ExtractSliceOp) if the full slice is overwritten and inserted into another tensor. After this rewrite, the operations bufferize in-place since all of them work on the same %iter_arg slice.

For example:

mlir
  %0 = vector.transfer_write %vec, %init_tensor[%c0, %c0]
       : vector<8x16xf32>, tensor<8x16xf32>
  %1 = tensor.extract_slice %0[0, 0] [%sz0, %sz1] [1, 1]
       : tensor<8x16xf32> to tensor<?x?xf32>
  %r = tensor.insert_slice %1 into %iter_arg[%iv0, %iv1] [%sz0, %sz1] [1, 1]
       : tensor<?x?xf32> into tensor<27x37xf32>

folds to

mlir
  %0 = tensor.extract_slice %iter_arg[%iv0, %iv1] [%sz0, %sz1] [1, 1]
       : tensor<27x37xf32> to tensor<?x?xf32>
  %1 = vector.transfer_write %vec, %0[%c0, %c0]
       : vector<8x16xf32>, tensor<?x?xf32>
  %r = tensor.insert_slice %1 into %iter_arg[%iv0, %iv1] [%sz0, %sz1] [1, 1]
       : tensor<?x?xf32> into tensor<27x37xf32>

Diff Detail

Event Timeline

gysit created this revision.Apr 6 2022, 12:54 AM
Herald added a project: Restricted Project. · View Herald Transcript
gysit requested review of this revision.Apr 6 2022, 12:54 AM
hanchung accepted this revision.Apr 8 2022, 11:58 AM
This revision is now accepted and ready to land.Apr 8 2022, 11:58 AM
nicolasvasilache accepted this revision.Apr 11 2022, 2:17 AM

Looks good, if it ever becomes too intrusive we may want to make it opt in only, but for now I am not concerned given the heavy filtering.

gysit updated this revision to Diff 421862.Apr 11 2022, 3:16 AM

Rebase.

This revision was landed with ongoing or failed builds.Apr 11 2022, 3:29 AM
This revision was automatically updated to reflect the committed changes.