This is an archive of the discontinued LLVM Phabricator instance.

[mlir][spirv] Support size-1 vector.insert during conversion
ClosedPublic

Authored by antiagainst on Dec 10 2021, 6:37 AM.

Details

Summary

Size-1 vectors are converted into scalars in SPIR-V so these ops
go away entirely.

Along the way, update the pass to perform partial conversion
so that we can have more focused tests.

Diff Detail

Event Timeline

antiagainst created this revision.Dec 10 2021, 6:37 AM
antiagainst requested review of this revision.Dec 10 2021, 6:37 AM
mravishankar requested changes to this revision.Dec 10 2021, 10:03 AM
mravishankar added inline comments.
mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
161

This looks like a canonicalization at vector dialect then a something to do in SPIR-V. Or do the normal thing in SPIR-V and canonicalize in SPIR-V dialect. Seems off to do this during conversion.

mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp
41 ↗(On Diff #393467)

Is this change related somehow. I dont see the correlation

This revision now requires changes to proceed.Dec 10 2021, 10:03 AM
antiagainst edited the summary of this revision. (Show Details)Dec 14 2021, 12:46 PM
antiagainst added inline comments.
mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
161

Crossing the vector-scalar boundary doesn't seem like a generic transformation to me that we'd want to put in vector dialect as a canonicalization pattern. Vector dialect should be working on vectors, even they are of size one. Going to scalar is not always wanted at that level, given that they won't work anymore with other vector-level ops.

I consider going to scalars as lowering so it makes sense to happen during vector to SPIR-V conversion time to me. (Note that size-1 vector is valid vector and valid input to SPIR-V conversion; the fact that we are lowering them to scalars is SPIR-V's particular requirements.)

mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp
41 ↗(On Diff #393467)

This is needed for cleaning up the tests. I updated the patch comment to be clear. :)

Move pass and test change to its own patch: https://reviews.llvm.org/D115756

antiagainst marked 2 inline comments as done.Dec 14 2021, 1:13 PM
antiagainst added inline comments.
mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRVPass.cpp
41 ↗(On Diff #393467)

Actually, I split this out as its own patch: https://reviews.llvm.org/D115756.

mravishankar accepted this revision.Jan 20 2022, 9:11 AM
mravishankar added inline comments.
mlir/lib/Conversion/VectorToSPIRV/VectorToSPIRV.cpp
160

Nit: type s/Speical/Special

This revision is now accepted and ready to land.Jan 20 2022, 9:11 AM

I wonder if this will lead to unrealized conversion casts not being able to be eliminated since the uses might actually need a vector.

antiagainst marked an inline comment as done.Jan 21 2022, 10:37 AM

I wonder if this will lead to unrealized conversion casts not being able to be eliminated since the uses might actually need a vector.

Size-1 vector are converted to scalars by the SPIR-V type converter globally. So shouldn't be a big problem. If it happens, it's an indication a missing op conversion.

This revision was landed with ongoing or failed builds.Jan 21 2022, 10:57 AM
This revision was automatically updated to reflect the committed changes.