[Mlir-commits] [mlir] [mlir][linalg] Add splat broadcast canonicalization pattern (PR #195980)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Mon May 11 21:57:34 PDT 2026


MaheshRavishankar wrote:

> > Here too, the fill seems superfluous.
> 
> Hi, for this one, if we change it to splat, it cannot handle dynamic cases. Should we bail-out in this case? wdyt?
> 
> ```mlir
> module {
>   func.func @broadcast_splat_constant_dynamic_shape(%arg0: tensor<?x3xf32>) -> tensor<?x3xf32> {
>     %cst = arith.constant dense<1.000000e+00> : tensor<3xf32>
>     %broadcasted = linalg.broadcast ins(%cst : tensor<3xf32>) outs(%arg0 : tensor<?x3xf32>) dimensions = [0] 
>     return %broadcasted : tensor<?x3xf32>
>   }
> }
> 
> hocky at hocky:~/llvm/llvm-project/build_clion$ mlir-opt why.mlir  --canonicalize
> module {
>   func.func @broadcast_splat_constant_dynamic_shape(%arg0: tensor<?x3xf32>) -> tensor<?x3xf32> {
>     %cst = arith.constant 1.000000e+00 : f32
>     %0 = linalg.fill ins(%cst : f32) outs(%arg0 : tensor<?x3xf32>) -> tensor<?x3xf32>
>     return %0 : tensor<?x3xf32>
>   }
> }
> ```

I think so yes. This goes to the same point I made either on this PR or another PR. This will force the broadcast to fuse with the fill while in some cases you might want to fuse with the consumer to not materialize the broadcasted buffer.

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


More information about the Mlir-commits mailing list