[Mlir-commits] [mlir] [mlir][vector] Disallow vector broadcast along scalable dim (PR #212197)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Tue Aug 4 02:23:30 PDT 2026
=?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/3] [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/3] 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/3] 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>
More information about the Mlir-commits
mailing list