[Mlir-commits] [mlir] [mlir][vector] Support multi-dimensional vectors in VectorFromElementsLowering (PR #151175)

James Newling llvmlistbot at llvm.org
Fri Aug 8 07:13:27 PDT 2025


newling wrote:

> IIUC, we now have two ways to convert vector to LLVM:
> 
> 1. convert-vector-to-llvm pass. It includes two stages: a transformation stage that "lowers vector ops to other vector ops", and a conversion that "lowers vector ops to LLVM ops".
> 2. convert-to-llvm: only includes the latter conversion stage.
> 
> We only need to support lowering multi-dim from_elements ops in convert-vector-to-llvm. Please correct me if I'm wrong.
> 
> > Expanding populateVectorShapeCastLoweringPatterns (or creating patterns that inject vector.shape_cast and then leveraging populateVectorShapeCastLoweringPatterns) less so - wouldn't we be simply shifting the complexity within vector-to-llvm (as opposed to making it simpler)?
> 
> Our goal is keeping the conversion stage simple, right? So it is ok to shift the complexity to `populateVectorShapeCastLoweringPatterns` or `populateVectorFromElementsOpLoweringPatterns`, which both belong to the transformation stage.
> 
> > Or my suggestion was to add a pattern there to split a rank-D from_elements op into a rank-1 from_elements op preceded by a shape_cast, and then populateVectorShapeCastLoweringPatterns will kick in and generate the inserts/extracts.
> 
> Using shapecast or iteratively unrolling N-D vectors are both ok for me. I'd like to do some experiments to study which method can generate more efficient operations.

I don't think `populateVectorShapeCastLoweringPatterns` will need changing. The only difference in my mind between the 2 approaches is the pattern that goes inside `populateVectorFromElementsOpLoweringPatterns`. Option 'direct' will have a pattern which goes to inserts/extracts, basically the same logic as in this PR currently. Option 'shape_cast' will have a pattern which goes to shape_cast. Then `populateVectorShapeCastLoweringPatterns` already has the logic to lower from shape_cast to inserts/extracts IIRC. 

I can see pros/cons with both approach. One pro with a pattern to go to shape_cast is slightly less new code (although it's probably only slightly less, as this PR in it's current state isn't large). One con is that the lowering path is longer / less intuitive. At this point I have no strong preference, and think exploring both is a good idea -- thank you!

https://github.com/llvm/llvm-project/pull/151175


More information about the Mlir-commits mailing list