[mlir][Linalg] Add a hoistRedundantVectorTransfers helper function
authorNicolas Vasilache <ntv@google.com>
Fri, 5 Jun 2020 10:35:46 +0000 (06:35 -0400)
committerNicolas Vasilache <ntv@google.com>
Fri, 5 Jun 2020 10:50:24 +0000 (06:50 -0400)
commit6953cf65024395508c464dc78c90b158b3241a3a
tree6c6a9aefb9c1e5f48ec73653a243d9ec846fab11
parent9bfdf1180744f3fe8fe716fa77eacec1c56f0755
[mlir][Linalg] Add a hoistRedundantVectorTransfers helper function

This revision adds a helper function to hoist vector.transfer_read /
vector.transfer_write pairs out of immediately enclosing scf::ForOp
iteratively, if the following conditions are true:
   1. The 2 ops access the same memref with the same indices.
   2. All operands are invariant under the enclosing scf::ForOp.
   3. No uses of the memref either dominate the transfer_read or are
   dominated by the transfer_write (i.e. no aliasing between the write and
   the read across the loop)

To improve hoisting opportunities, call the `moveLoopInvariantCode` helper
function on the candidate loop above which to hoist. Hoisting the transfers
results in scf::ForOp yielding the value that originally transited through
memory.

This revision additionally exposes `moveLoopInvariantCode` as a helper in
LoopUtils.h and updates SliceAnalysis to support return scf::For values and
allow hoisting across multiple scf::ForOps.

Differential Revision: https://reviews.llvm.org/D81199
mlir/include/mlir/Dialect/Linalg/Transforms/Hoisting.h
mlir/include/mlir/Transforms/LoopUtils.h
mlir/lib/Analysis/SliceAnalysis.cpp
mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
mlir/lib/Transforms/LoopInvariantCodeMotion.cpp
mlir/test/Dialect/Linalg/hoisting.mlir
mlir/test/lib/Transforms/TestLinalgHoisting.cpp