[Mlir-commits] [mlir] [mlir][vector] Add special lowering for 2D transpose on 1D broadcast (PR #150562)

Min-Yih Hsu llvmlistbot at llvm.org
Wed Aug 6 11:02:53 PDT 2025


================
@@ -423,6 +423,75 @@ class Transpose2DWithUnitDimToShapeCast
   }
 };
 
+// Given this snippet
+// ```
+//  %b = broadcast %arg0 : vector<2xf32> to vector<32x2xf32>
+//  %t = transpose %b, [1, 0] : vector<32x2xf32> to vector<2x32xf32>
+// ```
+// while we can't directly broadcast from vector<2xf32> to vector<2x32xf32>,
+// we can do something like this:
+// ```
+//  %cst = arith.constant dense<0.000000e+00> : vector<2x32xf32>
+//  %0 = vector.shuffle %arg0, %arg0 [0,0,...,0] : vector<2xf32>, vector<2xf32>
+//  %1 = vector.insert %0, %cst [0] : vector<32xf32> into vector<2x32xf32>
+//  %2 = vector.shuffle %arg0, %arg0 [1,1,...,1] : vector<2xf32>, vector<2xf32>
+//  %t = vector.insert %2, %1 [1] : vector<32xf32> into vector<2x32xf32>
+// ```
+// Where the shuffles are effectively 1-D broadcasts (splats), which are more
----------------
mshockwave wrote:

`vector<2xf32>` is not directly broadcastable to `vector<2x32xf32>`, and at that time I didn't think of shape_cast that is also pointed out by @newling in another comment.

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


More information about the Mlir-commits mailing list