[Mlir-commits] [mlir] [MLIR][Vector]Add constraints to vector.shape_cast(constant) -> constant (PR #147691)

James Newling llvmlistbot at llvm.org
Tue Jul 22 11:02:53 PDT 2025


newling wrote:

> > The original solution in #147691 actually does a good job -- it uses the element type of the original attribute instead of the result.
> 
> My main concern about that fix is that the code is specialized to enable the folder on `llvm.mlir.constant` ops by specializing the implementation to the specific type semantics/constraints of `llvm.mlir.constant`. However, any op implementing the `ConstantOpLikeInterface` would hit that code, right?
> 
> ```
>   %0 = my_dialect.constant ...
>   %1 = vector.shape_cast %0 : vector<12xi128> to vector<1x12xi128>
> ```
> 
> I think the fix should go in the direction of making the folder robust enough to handle any `ConstantOpLikeInterface`, even if that means bailing out in some cases, such as the `llvm.mlir.constant`. Perhaps we can just check that the attribute and return type match and bail out otherwise?

My concern with this PR is a bit different, I think. It is that the logic isn't specific to shape_cast -- all vector dialect folders will need to be updated with this careful logic. That is why I would like to either 

1) make llvm.constant have a stricter verifier (fp8 attribute with i8 type disallowed) or 
2) make the reshape method on attributes _just_ change the shape not the type, as done in https://github.com/llvm/llvm-project/pull/149947/files


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


More information about the Mlir-commits mailing list