This is an archive of the discontinued LLVM Phabricator instance.

[mlir][linalg] Fold duplicate and unused inputs in linalg.generic
Needs RevisionPublic

Authored by springerm on Dec 9 2022, 5:45 AM.

Details

Summary

If an input bbArg is not used, its corresponding input operand is removed. If there are duplicate input operands or input operands that are also used as output operands, the duplicate input operands are removed. Output operands are never modified.

Diff Detail

Event Timeline

springerm created this revision.Dec 9 2022, 5:45 AM
Herald added a project: Restricted Project. · View Herald Transcript
springerm requested review of this revision.Dec 9 2022, 5:45 AM
Herald added a project: Restricted Project. · View Herald TranscriptDec 9 2022, 5:45 AM
This revision is now accepted and ready to land.Dec 9 2022, 6:11 AM
mlir/lib/Dialect/Linalg/Transforms/EraseUnusedOperandsAndResults.cpp
401

for (auto [x, y] : replacements) ?

springerm updated this revision to Diff 481620.Dec 9 2022, 6:17 AM
springerm marked an inline comment as done.

address comments

This revision was landed with ongoing or failed builds.Dec 9 2022, 6:22 AM
This revision was automatically updated to reflect the committed changes.
mravishankar reopened this revision.Dec 9 2022, 1:52 PM
mravishankar added inline comments.
mlir/lib/Dialect/Linalg/Transforms/EraseUnusedOperandsAndResults.cpp
373

This seems to be a duplicate of what the deduplicate operands does. I am not sure why it is done separately and not added to the existing patterns. Unless I am missing something could we revert this patch (or do a follow up fix) and see why the existing patterns doesn't cover this case. It should.

This revision is now accepted and ready to land.Dec 9 2022, 1:52 PM
mravishankar requested changes to this revision.Dec 9 2022, 1:53 PM

Want some clarification on went this is done as a separate pattern

This revision now requires changes to proceed.Dec 9 2022, 1:53 PM
springerm marked an inline comment as done.Dec 10 2022, 12:54 AM
springerm added inline comments.
mlir/lib/Dialect/Linalg/Transforms/EraseUnusedOperandsAndResults.cpp
373

DeduplicateAndRemoveDeadOperandsAndResults removes duplicate inputs and duplicate outputs separately. A value that is both an input and an output is not considered a duplicate by this pattern. The way the pattern is written it seems difficult to support this.

We needed a specific way of de-duplicating operands: Outputs should not be modified (because they are bufferization DPS destinations), but inputs that are also outputs can be removed. (Removing the outputs instead would not be desirable.)