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

Diego Caballero llvmlistbot at llvm.org
Wed Apr 15 10:03:09 PDT 2026


dcaballe wrote:

> ```
> // %src : f32
> vector.insert %src, %vec [0] : f32 into vector<32x1xf32>
> ```
> 
> where the %src operand would be implicitly broadcasted to be `<1xf32>`.

This is also my understanding.

> > 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 disabled the pattern on the PR and it was not turned into vector.shape_cast by the other canonicalization patterns. It is transformed into a vector.shape_cast but only after this pattern is applied first.

Yes, that was my point. If we generate a `vector.broadcast` that is then folded again into a `vector.shape_cast`, let's generate a `vector.shape_cast` directly.

For the scalar case, we could generate:

```
%init = ub.poison : vector<1xf32>
%insert = vector.insert %s, %init[0] : vector<1xf32>
```

but that will be folded into a `vector.from_elements`, so let's generate a `vector.from_elements` directly.

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


More information about the Mlir-commits mailing list