[Mlir-commits] [mlir] [mlir][vector] Disallow vector broadcast along scalable dim (PR #212197)

llvmlistbot at llvm.org llvmlistbot at llvm.org
Tue Aug 4 08:17:50 PDT 2026


=?utf-8?q?Mattéo?= Rizza Murgier,=?utf-8?q?Mattéo?= Rizza Murgier,
=?utf-8?q?Mattéo?= Rizza Murgier
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/212197 at github.com>


https://github.com/Brythzz updated https://github.com/llvm/llvm-project/pull/212197

>From 4bb1542ea0ba6302cbdadb526c9993deeab6f2ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matt=C3=A9o=20Rizza=20Murgier?=
 <matteo.rizza-murgier at sipearl.com>
Date: Wed, 22 Jul 2026 11:50:58 +0200
Subject: [PATCH 1/4] [mlir][vector] Disallow vector broadcast along scalable
 dim

---
 .../Vector/Transforms/LowerVectorBroadcast.cpp       |  2 ++
 .../test/Conversion/VectorToLLVM/vector-to-llvm.mlir | 12 ++++++++++++
 2 files changed, 14 insertions(+)

diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp
index a78c31367ee28..0e31b6934e239 100644
--- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp
@@ -73,6 +73,8 @@ class BroadcastOpLowering : public OpRewritePattern<vector::BroadcastOp> {
     //   %x = [%b,%b,%b,%b] : n-D
     if (srcRank < dstRank) {
       // Duplication.
+      if (dstType.getScalableDims()[0])
+        return failure();
       VectorType resType = VectorType::Builder(dstType).dropDim(0);
       Value bcst =
           vector::BroadcastOp::create(rewriter, loc, resType, op.getSource());
diff --git a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
index 094353119e493..3da33dad91efc 100644
--- a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
+++ b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
@@ -242,6 +242,18 @@ func.func @broadcast_vec2d_from_vec1d_scalable(%arg0: vector<[2]xf32>) -> vector
 
 // -----
 
+// TODO: Add support for scalable vectors
+
+func.func @broadcast_vec2d_from_vec1d_scalable_leading(%arg0: vector<2xf32>) -> vector<[4]x2xf32> {
+  %0 = vector.broadcast %arg0 : vector<2xf32> to vector<[4]x2xf32>
+  return %0 : vector<[4]x2xf32>
+}
+// CHECK-LABEL: @broadcast_vec2d_from_vec1d_scalable_leading
+// CHECK-SAME:  %[[A:.*]]: vector<2xf32>)
+// CHECK: vector.broadcast %[[A]] : vector<2xf32> to vector<[4]x2xf32>
+
+// -----
+
 func.func @broadcast_vec2d_from_index_vec1d(%arg0: vector<2xindex>) -> vector<3x2xindex> {
   %0 = vector.broadcast %arg0 : vector<2xindex> to vector<3x2xindex>
   return %0 : vector<3x2xindex>

>From e7a34c2575a640a62f19ac5397798988ba60d436 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matt=C3=A9o=20Rizza=20Murgier?=
 <matteo.rizza-murgier at sipearl.com>
Date: Mon, 3 Aug 2026 16:28:29 +0200
Subject: [PATCH 2/4] Add match failure message

---
 mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp b/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp
index 0e31b6934e239..ceeb258805c6a 100644
--- a/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp
+++ b/mlir/lib/Dialect/Vector/Transforms/LowerVectorBroadcast.cpp
@@ -74,7 +74,9 @@ class BroadcastOpLowering : public OpRewritePattern<vector::BroadcastOp> {
     if (srcRank < dstRank) {
       // Duplication.
       if (dstType.getScalableDims()[0])
-        return failure();
+        return rewriter.notifyMatchFailure(
+            op, "Vector broadcasting over a scalable dimension is not "
+                "currently supported");
       VectorType resType = VectorType::Builder(dstType).dropDim(0);
       Value bcst =
           vector::BroadcastOp::create(rewriter, loc, resType, op.getSource());

>From 466bd68572bafbd26db4afd2d6c0a82e30e5474b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matt=C3=A9o=20Rizza=20Murgier?=
 <matteo.rizza-murgier at sipearl.com>
Date: Tue, 4 Aug 2026 11:23:07 +0200
Subject: [PATCH 3/4] Add nested dims example

---
 .../Conversion/VectorToLLVM/vector-to-llvm.mlir | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
index 3da33dad91efc..6cbf9830098fb 100644
--- a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
+++ b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
@@ -254,6 +254,23 @@ func.func @broadcast_vec2d_from_vec1d_scalable_leading(%arg0: vector<2xf32>) ->
 
 // -----
 
+// TODO: Add support for scalable vectors
+
+func.func @broadcast_vec2d_from_vec1d_scalable_inner(%arg0: vector<2xf32>) -> vector<3x[4]x2xf32> {
+  %0 = vector.broadcast %arg0 : vector<2xf32> to vector<3x[4]x2xf32>
+  return %0 : vector<3x[4]x2xf32>
+}
+// CHECK-LABEL: @broadcast_vec2d_from_vec1d_scalable_inner
+// CHECK-SAME:  %[[A:.*]]: vector<2xf32>)
+// CHECK:       %[[T0:.*]] = ub.poison : vector<3x[4]x2xf32>
+// CHECK:       %[[T1:.*]] = vector.broadcast %[[A]] : vector<2xf32> to vector<[4]x2xf32>
+// CHECK:       %[[T2:.*]] = vector.insert %[[T1]], %[[T0]] [0] : vector<[4]x2xf32> into vector<3x[4]x2xf32>
+// CHECK:       %[[T3:.*]] = vector.insert %[[T1]], %[[T2]] [1] : vector<[4]x2xf32> into vector<3x[4]x2xf32>
+// CHECK:       %[[T4:.*]] = vector.insert %[[T1]], %[[T3]] [2] : vector<[4]x2xf32> into vector<3x[4]x2xf32>
+// CHECK:       return %[[T4]] : vector<3x[4]x2xf32>
+
+// -----
+
 func.func @broadcast_vec2d_from_index_vec1d(%arg0: vector<2xindex>) -> vector<3x2xindex> {
   %0 = vector.broadcast %arg0 : vector<2xindex> to vector<3x2xindex>
   return %0 : vector<3x2xindex>

>From 5330a3df38bd4e53ad22f1aa4aa15fe83a700cc1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Matt=C3=A9o=20Rizza=20Murgier?=
 <matteo.rizza-murgier at sipearl.com>
Date: Tue, 4 Aug 2026 17:17:28 +0200
Subject: [PATCH 4/4] Move tests to appropriate file

---
 .../VectorToLLVM/vector-to-llvm.mlir          | 29 -------------------
 .../vector-broadcast-lowering-transforms.mlir | 27 +++++++++++++++++
 2 files changed, 27 insertions(+), 29 deletions(-)

diff --git a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
index 6cbf9830098fb..094353119e493 100644
--- a/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
+++ b/mlir/test/Conversion/VectorToLLVM/vector-to-llvm.mlir
@@ -242,35 +242,6 @@ func.func @broadcast_vec2d_from_vec1d_scalable(%arg0: vector<[2]xf32>) -> vector
 
 // -----
 
-// TODO: Add support for scalable vectors
-
-func.func @broadcast_vec2d_from_vec1d_scalable_leading(%arg0: vector<2xf32>) -> vector<[4]x2xf32> {
-  %0 = vector.broadcast %arg0 : vector<2xf32> to vector<[4]x2xf32>
-  return %0 : vector<[4]x2xf32>
-}
-// CHECK-LABEL: @broadcast_vec2d_from_vec1d_scalable_leading
-// CHECK-SAME:  %[[A:.*]]: vector<2xf32>)
-// CHECK: vector.broadcast %[[A]] : vector<2xf32> to vector<[4]x2xf32>
-
-// -----
-
-// TODO: Add support for scalable vectors
-
-func.func @broadcast_vec2d_from_vec1d_scalable_inner(%arg0: vector<2xf32>) -> vector<3x[4]x2xf32> {
-  %0 = vector.broadcast %arg0 : vector<2xf32> to vector<3x[4]x2xf32>
-  return %0 : vector<3x[4]x2xf32>
-}
-// CHECK-LABEL: @broadcast_vec2d_from_vec1d_scalable_inner
-// CHECK-SAME:  %[[A:.*]]: vector<2xf32>)
-// CHECK:       %[[T0:.*]] = ub.poison : vector<3x[4]x2xf32>
-// CHECK:       %[[T1:.*]] = vector.broadcast %[[A]] : vector<2xf32> to vector<[4]x2xf32>
-// CHECK:       %[[T2:.*]] = vector.insert %[[T1]], %[[T0]] [0] : vector<[4]x2xf32> into vector<3x[4]x2xf32>
-// CHECK:       %[[T3:.*]] = vector.insert %[[T1]], %[[T2]] [1] : vector<[4]x2xf32> into vector<3x[4]x2xf32>
-// CHECK:       %[[T4:.*]] = vector.insert %[[T1]], %[[T3]] [2] : vector<[4]x2xf32> into vector<3x[4]x2xf32>
-// CHECK:       return %[[T4]] : vector<3x[4]x2xf32>
-
-// -----
-
 func.func @broadcast_vec2d_from_index_vec1d(%arg0: vector<2xindex>) -> vector<3x2xindex> {
   %0 = vector.broadcast %arg0 : vector<2xindex> to vector<3x2xindex>
   return %0 : vector<3x2xindex>
diff --git a/mlir/test/Dialect/Vector/vector-broadcast-lowering-transforms.mlir b/mlir/test/Dialect/Vector/vector-broadcast-lowering-transforms.mlir
index 5b193c5e25ca0..c2922cdbe55aa 100644
--- a/mlir/test/Dialect/Vector/vector-broadcast-lowering-transforms.mlir
+++ b/mlir/test/Dialect/Vector/vector-broadcast-lowering-transforms.mlir
@@ -209,6 +209,33 @@ func.func @broadcast_scalable_duplication(%arg0: vector<[32]xf32>) -> vector<1x[
   return %res : vector<1x[32]xf32>
 }
 
+// TODO: Add support for scalable vectors
+
+// CHECK-LABEL: @broadcast_vec2d_from_vec1d_scalable_leading
+// CHECK-SAME:  %[[A:.*]]: vector<2xf32>)
+// CHECK: vector.broadcast %[[A]] : vector<2xf32> to vector<[4]x2xf32>
+
+func.func @broadcast_vec2d_from_vec1d_scalable_leading(%arg0: vector<2xf32>) -> vector<[4]x2xf32> {
+  %0 = vector.broadcast %arg0 : vector<2xf32> to vector<[4]x2xf32>
+  return %0 : vector<[4]x2xf32>
+}
+
+// TODO: Add support for scalable vectors
+
+// CHECK-LABEL: @broadcast_vec2d_from_vec1d_scalable_inner
+// CHECK-SAME:  %[[A:.*]]: vector<2xf32>)
+// CHECK:       %[[T0:.*]] = ub.poison : vector<3x[4]x2xf32>
+// CHECK:       %[[T1:.*]] = vector.broadcast %[[A]] : vector<2xf32> to vector<[4]x2xf32>
+// CHECK:       %[[T2:.*]] = vector.insert %[[T1]], %[[T0]] [0] : vector<[4]x2xf32> into vector<3x[4]x2xf32>
+// CHECK:       %[[T3:.*]] = vector.insert %[[T1]], %[[T2]] [1] : vector<[4]x2xf32> into vector<3x[4]x2xf32>
+// CHECK:       %[[T4:.*]] = vector.insert %[[T1]], %[[T3]] [2] : vector<[4]x2xf32> into vector<3x[4]x2xf32>
+// CHECK:       return %[[T4]] : vector<3x[4]x2xf32>
+
+func.func @broadcast_vec2d_from_vec1d_scalable_inner(%arg0: vector<2xf32>) -> vector<3x[4]x2xf32> {
+  %0 = vector.broadcast %arg0 : vector<2xf32> to vector<3x[4]x2xf32>
+  return %0 : vector<3x[4]x2xf32>
+}
+
 module attributes {transform.with_named_sequence} {
   transform.named_sequence @__transform_main(%module_op: !transform.any_op {transform.readonly}) {
     %f = transform.structured.match ops{["func.func"]} in %module_op



More information about the Mlir-commits mailing list