This is an archive of the discontinued LLVM Phabricator instance.

Fix CombineContractBroadcast folding reduction iterators.
ClosedPublic

Authored by Benoit on Jun 28 2022, 9:54 AM.

Details

Summary

This enables me to drop a custom vectorization pattern that we had in IREE and just use upstream linalg vectorization instead:
https://github.com/iree-org/iree/pull/9647

Diff Detail

Event Timeline

Benoit created this revision.Jun 28 2022, 9:54 AM
Herald added a project: Restricted Project. · View Herald Transcript
Benoit requested review of this revision.Jun 28 2022, 9:54 AM
Benoit edited the summary of this revision. (Show Details)Jun 28 2022, 10:03 AM
mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
1136

seems this also works for parallel dims ?

1162

Please use bool isFunctionOfDim(unsigned position) const to make close to a 1-liner

1170

What corner case does this condition capture?

If a dim is truly unused then we cannot give it an extent anyway and the op seems like it would be invalid?

ThomasRaoux added inline comments.Jun 28 2022, 2:31 PM
mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
1135

you can replace this by broadcast.getVectorType() to avoid the cast

ThomasRaoux added inline comments.Jun 29 2022, 7:50 AM
mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
1141
1167

nit: remove single line {:

1170

The corner case is because vector.contract needs to have at least one reduction dim:
https://github.com/llvm/llvm-project/blob/2124b2f0e6083470cf27448e4217706ee646ab03/mlir/lib/Dialect/Vector/IR/VectorOps.cpp#L767
So even if the dim size is 1 we still want to keep one reduction (unless we want to relax the op but I think the semantic of it would not be ideal)

1183

nit: remove single line {:

Benoit updated this revision to Diff 441027.Jun 29 2022, 8:31 AM

addressed review comments

Benoit marked 8 inline comments as done.Jun 29 2022, 8:34 AM
Benoit added inline comments.
mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
1136

Yes, that's the point! Parallel dims are fine here, so we ignore them in this code which is checking for a potential bad case with reduction dims.

1170

Thanks for the explanation Thomas, I added your testcase and added a rationale comment on the testcases.

Benoit marked 2 inline comments as done.Jun 29 2022, 8:35 AM

Addressed review comments.

ThomasRaoux added inline comments.Jun 29 2022, 8:39 AM
mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
1136

You are missing on level of indirection here, the iterator type associated to the dimension is based on the affine map. is should be contractOp.getIteratorTypes().getValue()[map.getDimPosition(i)).
Maybe add or modifying the test to have a permutation in the affine map would help catching that kind of problem.

1170

nit: Might be worth a comment?

Benoit updated this revision to Diff 441057.Jun 29 2022, 9:48 AM

more review comments

Benoit marked 2 inline comments as done.Jun 29 2022, 9:48 AM
ThomasRaoux accepted this revision.Jun 29 2022, 10:50 AM
This revision is now accepted and ready to land.Jun 29 2022, 10:50 AM
This revision was landed with ongoing or failed builds.Jun 29 2022, 11:06 AM
This revision was automatically updated to reflect the committed changes.