This is an archive of the discontinued LLVM Phabricator instance.

[MLIR][Linalg] Change insertion point for `bubbleUpPackOpThroughElemGenericOp`
ClosedPublic

Authored by chelini on Feb 17 2023, 2:07 AM.

Details

Summary

Currently, the insertion point for bubbleUpPackOpThroughElemGenericOp
is after the tensor.pack this means that the new generic will be created
right after the tensor.pack. This is inconvenient because we are moving
the position of the generic; the idea is to move pack/unpack around, not
linalg.generics. This PR changes the insertion point to preserve the
position of the generic.

Additionally, it restricts the pattern to fire if the generic has a
single user (tensor.pack) to avoid introducing recomputation.

Diff Detail

Event Timeline

chelini created this revision.Feb 17 2023, 2:07 AM
chelini requested review of this revision.Feb 17 2023, 2:07 AM
chelini added a reviewer: rengolin.
hanchung added inline comments.Feb 17 2023, 2:11 PM
mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp
328–336

style nit: we need braces if {} is used in else branch.

333–335

[optional] Is it a heavy check? If so, maybe we should have simpler check and bail-out. We can maybe introduce an aggressive mode of this is needed.

chelini marked an inline comment as done.Feb 20 2023, 8:29 AM
chelini added inline comments.Feb 20 2023, 8:43 AM
mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp
333–335

Difficult to say; it depends on the situation. I never hit this branch in my codebase as the destination of a tensor.pack (by construction) is always a tensor.empty. I added this branch to preserve the tests we already had, where the destination is a function argument. For this specific case, dominance is just a pointer comparison.

rengolin added inline comments.Feb 20 2023, 8:51 AM
mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp
333–335

If you don't exercise this code then perhaps you should craft a test showing it is valid, or emit an assert on !emptyOp.

chelini added inline comments.Feb 20 2023, 9:02 AM
mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp
333–335

Are you referring to the "else" branch? All the code is exercised, and most of the tests (but not all) we have in data-layout-propagtion.mlir takes the "else" branch. I also added another test, would_break_dominance, where the destination is not a function argument, so we should be covered.

rengolin added inline comments.Feb 20 2023, 9:23 AM
mlir/lib/Dialect/Linalg/Transforms/DataLayoutPropagation.cpp
333–335

Perfect, thanks!

hanchung accepted this revision.Feb 21 2023, 1:07 PM
This revision is now accepted and ready to land.Feb 21 2023, 1:07 PM
This revision was landed with ongoing or failed builds.Feb 23 2023, 12:25 AM
This revision was automatically updated to reflect the committed changes.