This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Add a hoistRedundantVectorTransfers helper function
ClosedPublic

Authored by nicolasvasilache on Jun 4 2020, 3:37 PM.

Details

Summary

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.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptJun 4 2020, 3:37 PM
aartbik added inline comments.Jun 4 2020, 4:42 PM
mlir/include/mlir/Dialect/Linalg/Transforms/Hoisting.h
24

very minor nit: no spaces around / as you did at L17 (or spaces there)

26

nit: spell out 2 as two to avoid confusing it with numbering

mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
112

you scan reverse, and keep going (no break) to find the first; this reads a bit non-intuitive, can you elaborate?

ftynse accepted this revision.Jun 5 2020, 1:35 AM

There probably exists some clever way of doing this from the innermost loop out, but okay for now.

mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
90

Nit: in the other function in this class, the check is for immediate parent, here it is for any loop parent (getParentOfType should really be called getAncestorOfType). Is this intentional? If so, please document the difference somewhere to avoid surprises.

138

properlyDominates? tranferRead and transferWrite are different operations anyway.

also, do you need the explcit .getOperation() ?

154

Nit: it's not "mark the old for erasure", the code actually erases it

This revision is now accepted and ready to land.Jun 5 2020, 1:35 AM
nicolasvasilache marked 9 inline comments as done.Jun 5 2020, 3:32 AM
nicolasvasilache added inline comments.
mlir/lib/Dialect/Linalg/Transforms/Hoisting.cpp
90

thanks for catching, should be the immediate parent indeed.

112

The comment should say "look for the last", not first.
Updated.

138

Done.

Re. .getOperation() without getOperations the compiler complains about ambiguous conversion to either Operation* or Value for single result ops.

nicolasvasilache marked 3 inline comments as done.

Address review.

This revision was automatically updated to reflect the committed changes.