This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Vector] Fold selects of single-element i1 vectors
ClosedPublic

Authored by dcaballe on Jul 6 2023, 10:43 PM.

Details

Summary

This patch adds a folding to select operation between an all-true and all-false vector.
For now, only single element vectors (i.e., vector<1xi1>) are supported. Multi-element
cases are caught by InstCombine.

Diff Detail

Event Timeline

dcaballe created this revision.Jul 6 2023, 10:43 PM
Herald added a project: Restricted Project. · View Herald Transcript
dcaballe requested review of this revision.Jul 6 2023, 10:43 PM
ThomasRaoux added inline comments.Jul 7 2023, 12:03 AM
mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
1079–1082

it is probably better to do:

return denseAttr.isSplat() && denseAttr.getSplatValue<bool>() == value;

looping through all the elements can be expensive for large shapes.

1135

should this be a vector.broadcast? That would generalize to any vector size?

awarzynski added inline comments.Jul 7 2023, 8:11 AM
mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
1107

There's not sign extension taking place here, is there?

dcaballe updated this revision to Diff 548067.Aug 7 2023, 11:06 PM
dcaballe marked 2 inline comments as done.

Addressed feedback

Sorry for the long delay. I just forgot about this! :) I addressed all the comments.

mlir/lib/Dialect/Vector/Transforms/VectorTransforms.cpp
1107

Not for the scalar case, good catch :)

1135

Good point!

dcaballe updated this revision to Diff 548069.Aug 7 2023, 11:10 PM

Fix naming in test

awarzynski accepted this revision.Aug 9 2023, 8:27 AM

LGTM, thanks!

I see that you have also addressed comments from Thomas, so IMHO it's OK to land this without waiting for further feedback.

This revision is now accepted and ready to land.Aug 9 2023, 8:27 AM
This revision was automatically updated to reflect the committed changes.