This is an archive of the discontinued LLVM Phabricator instance.

[mlir][Vector] Disable 'vector.extract' folding for unsupported 0-D vectors
ClosedPublic

Authored by dcaballe on May 31 2023, 3:40 PM.

Details

Summary

The vector.extract folding patterns do not support 0-D vectors
(actually, 0-D vector support couldn't even be implemented as a folding
pattern as it would require replacing vector.extract with a
vector.extractelement op). This patch is bailing out folding when 0-D
vectors are found.

Diff Detail

Event Timeline

dcaballe created this revision.May 31 2023, 3:40 PM
Herald added a project: Restricted Project. · View Herald Transcript
dcaballe requested review of this revision.May 31 2023, 3:40 PM
dcaballe retitled this revision from [Vector] Disable 'vector.extract' folding for unsupported 0-D vectors to [mlir][Vector] Disable 'vector.extract' folding for unsupported 0-D vectors.

Note that ExtractOp does not support 0-D vectors at this time.
It seems to me that all these checks could be defensive asserts.

Separately, we may consider extending ExtractOp to support 0-D vectors, which would make sense given that ExtractElement returns elemental types, but we'll also need tests.

Good point! I can turn the check on ExtractOp into an assert. The key check, though, is the one on the defining op. That one may have 0-D vectors and we may end up creating a 0-D ExtracOp as a result of the folding. That's what the patch is aim to prevent.

hanchung accepted this revision.Jun 1 2023, 8:45 AM
hanchung added inline comments.
mlir/lib/Dialect/Vector/IR/VectorOps.cpp
1628–1631

Can we move it after 0-D vectors check, then we are sure that the dest type is VectorType? We can still use cast and the cast has assertion semantics -- which is good to me.

In the context, the dest type must be a vector type because input operand type is not a 0-D vector.

This revision is now accepted and ready to land.Jun 1 2023, 8:45 AM
dcaballe updated this revision to Diff 527469.Jun 1 2023, 9:47 AM

Introduce asserts for ExtractOp

ok, makes sense, can we have some tests here ?

dcaballe updated this revision to Diff 527566.Jun 1 2023, 12:39 PM

Adding test. Some case can't be tested because other canonicalization patterns get in the way.