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

Andrzej Warzyński llvmlistbot at llvm.org
Thu Apr 10 01:17:43 PDT 2025


================
@@ -1017,6 +1039,18 @@ func.func @canonicalize_broadcast_shapecast_to_shapecast(%arg0: vector<3x4xf32>)
 
 // -----
 
+// In this test, it could be folded to broadcast or shape_cast, shape_cast is chosen.
+// CHECK-LABEL: func @canonicalize_broadcast_shapecast_to_shapcast_priority
+//   CHECK-NOT:   vector.broadcast
+//       CHECK:   vector.shape_cast {{.+}} : vector<1xf32> to vector<1x1xf32>
+func.func @canonicalize_broadcast_shapecast_to_shapcast_priority(%arg0 : vector<1xf32>) -> vector<1x1xf32> {
----------------
banach-space wrote:

[nit] Just thinking of my future self: Does `priority` here mean the pattern favors `shape_cast` over `broadcast`? That’s not super clear to me right now, and it might be even less so later on. I’d suggest dropping the word - your comment is already helpful without it.

Related note: How is this test different from `canonicalize_broadcast_shapecast_to_shapecast`? In both, the element count stays the same, so `shape_cast` is preferred. Do we really need both tests?

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


More information about the Mlir-commits mailing list