This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Linalg] Add canonicalization to remove no-op linalg operations.
ClosedPublic

Authored by mravishankar on Jan 12 2021, 9:38 PM.

Details

Summary

linalg.generic/indexed_generic operations on tensors whose body is
just yielding the (non-induction variable) arguments of the operation
can be canonicalized by replacing uses of the result with the
corresponding arguments.

Diff Detail

Event Timeline

mravishankar created this revision.Jan 12 2021, 9:38 PM
mravishankar requested review of this revision.Jan 12 2021, 9:38 PM
hanchung accepted this revision.Jan 12 2021, 11:08 PM
hanchung added inline comments.
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
2148

auto

2148

I think we can use body.getTerminator() here. It will return an Operation *, and it's clearer to me.

2157

auto

This revision is now accepted and ready to land.Jan 12 2021, 11:08 PM
silvas accepted this revision.Jan 13 2021, 5:23 PM
silvas added inline comments.
mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
2127

nit: would call this RemoveIdentityLinalgOps.

2133

Why restrict to only GenericOp/IndexedGenericOp? The justification in DeduplicateInputs::matchAndRewrite doesn't seem to apply.

2163

should this more properly be genericOp->getInput(argumentNumber - numIndexArgs)?

mravishankar marked 4 inline comments as done.

Address comments

mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
2133

If a named op is a no-op, then we shouldnt be defining such named ops to begin with right? The Generic/IndexedGeneric ops are free form and after fusion, canonicalization, etc can become a no-op....

2163

There is an interesting corner case where you are returning one of the outs operands without any modification. That is still valid to do I think. So just using operand covers both these cases.