This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Introduce canonicalization to remove dead LinalgOps
ClosedPublic

Authored by nicolasvasilache on Aug 6 2020, 2:14 AM.

Details

Summary

When any of the memrefs in a structured linalg op has a zero dimension, it becomes dead.
This is consistent with the fact that linalg ops deduce their loop bounds from their operands.

Note however that this is not the case for the tensor<0xelt_type> which is a special convention
that must be lowered away into either memref<elt_type> or just elt_type before this
canonicalization can kick in.

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald Transcript
nicolasvasilache requested review of this revision.Aug 6 2020, 2:14 AM
bkramer accepted this revision.Aug 6 2020, 2:25 AM

lg, some nits inline.

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
1280
1281–1286
This revision is now accepted and ready to land.Aug 6 2020, 2:25 AM
rriddle added inline comments.Aug 6 2020, 2:27 AM
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
1276

I wonder if it would be useful to define an InterfaceRewritePattern, similarly to OpRewritePattern. (I would still enforce that the user provide MatchAnyOpTypeTag)

1280

You aren't checking the result of this dyn_cast.

1281

Can you also use is_contained here?

mlir/lib/IR/StandardTypes.cpp
736

llvm::is_contained?

nicolasvasilache marked 2 inline comments as done.Aug 6 2020, 2:43 AM
nicolasvasilache added inline comments.
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
1280

Added some comments to explain why dyn_cast.

nicolasvasilache marked 5 inline comments as done.Aug 6 2020, 3:07 AM
nicolasvasilache added inline comments.
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
1276

Definitely, I have more and more uses for this.

1280

thanks for catching!
Also added a test for the tensor case.

nicolasvasilache marked 2 inline comments as done.

Address review.

This revision was landed with ongoing or failed builds.Aug 6 2020, 3:14 AM
This revision was automatically updated to reflect the committed changes.