[Mlir-commits] [mlir] [mlir][vector] Fold vector extract from insert when trailing unit dims (PR #192109)

Kunwar Grover llvmlistbot at llvm.org
Wed Apr 15 10:13:12 PDT 2026


Groverkss wrote:

> > > The folding makes sense to me but I think we should generate a `vector.from_elements ... : vector<1xf32>`. We've been using that and insert/extract to cross the scalar/vector boundary and we have more folder/canonicalization patters on that front that could simplify the code further.
> > 
> > 
> > Not sure if that works for:
> > ```
> > %vec1 = vector.insert %src into %vec[0, 0] : vector<1xf32> into vector<16x1x1xf32>
> > %vec2 = vector.extract %vec1[0] : vector<1x1xf32> from vector<16x1x1xf32>
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > This can be written as:
> > ```
> > %vec2 = vector.broadcast %src : vector<1xf32> to vector<1x1xf32>
> > ```
> 
> This is a different case that is not crossing the scalar/vector boundary and would be turned into a `vector.shape_cast` by other folders/canonicalization patterns, IIRC.

I just wanted to point out that there are no other folders that would convert this into a shape_cast. As long as we handle the case it's okay, I don't mind what op we emit here, in the end it will end up in the canonical op that you mention.

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


More information about the Mlir-commits mailing list