[Mlir-commits] [mlir] [mlir][vector] shape_cast(broadcast) -> broadcast canonicalization (PR #134939)

Diego Caballero llvmlistbot at llvm.org
Wed Apr 9 03:45:34 PDT 2025


================
@@ -5778,8 +5778,7 @@ class ShapeCastCreateMaskFolderTrailingOneDim final
 
 /// Pattern to rewrite a ShapeCast(Broadcast) -> Broadcast.
 /// This only applies when the shape of the broadcast source
-/// 1. is a suffix of the shape of the result (i.e. when broadcast without
-///    reshape is expressive enough to capture the result in a single op), or
+/// 1. can be broadcast directly to the final shape, or
----------------
dcaballe wrote:

I think the documentation might be outdated. The code at the end seems to implement a `ShapeCast(Broadcast) -> ShapeCast` case. We should fix it.

In terms of canonicalization, I think the general rule would be to use shape cast when there is no actual data movement/copy (this includes trivial unit dimension expansion) and broadcast when there is data copy.

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


More information about the Mlir-commits mailing list