-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[mlir][vector] Fold broadcast(poison) -> poison #135677
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: James Newling <[email protected]>
@llvm/pr-subscribers-mlir-vector Author: James Newling (newling) ChangesIn addition to the new folder, I've also a test for broadcast(splat) -> splat which I think was missing Full diff: https://github.com/llvm/llvm-project/pull/135677.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index bee5c1fd6ed58..4b7ff757c150a 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -2590,6 +2590,8 @@ OpFoldResult BroadcastOp::fold(FoldAdaptor adaptor) {
}
if (auto attr = llvm::dyn_cast<SplatElementsAttr>(adaptor.getSource()))
return DenseElementsAttr::get(vectorType, attr.getSplatValue<Attribute>());
+ if (llvm::dyn_cast<ub::PoisonAttr>(adaptor.getSource()))
+ return ub::PoisonAttr::get(getContext());
return {};
}
diff --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir
index 78b0ea78849e8..420244c5e734a 100644
--- a/mlir/test/Dialect/Vector/canonicalize.mlir
+++ b/mlir/test/Dialect/Vector/canonicalize.mlir
@@ -1151,6 +1151,28 @@ func.func @bitcast_i8_to_i32() -> (vector<4xi32>, vector<4xi32>) {
// -----
+// CHECK-LABEL: broadcast_poison
+// CHECK: %[[POISON:.*]] = ub.poison : vector<4x6xi8>
+// CHECK: return %[[POISON]] : vector<4x6xi8>
+func.func @broadcast_poison() -> vector<4x6xi8> {
+ %poison = ub.poison : vector<6xi8>
+ %broadcast = vector.broadcast %poison : vector<6xi8> to vector<4x6xi8>
+ return %broadcast : vector<4x6xi8>
+}
+
+// -----
+
+// CHECK-LABEL: broadcast_splat_constant
+// CHECK: %[[CONST:.*]] = arith.constant dense<1> : vector<4x6xi8>
+// CHECK: return %[[CONST]] : vector<4x6xi8>
+func.func @broadcast_splat_constant() -> vector<4x6xi8> {
+ %cst = arith.constant dense<1> : vector<6xi8>
+ %broadcast = vector.broadcast %cst : vector<6xi8> to vector<4x6xi8>
+ return %broadcast : vector<4x6xi8>
+}
+
+// -----
+
// CHECK-LABEL: broadcast_folding1
// CHECK: %[[CST:.*]] = arith.constant dense<42> : vector<4xi32>
// CHECK-NOT: vector.broadcast
|
@llvm/pr-subscribers-mlir Author: James Newling (newling) ChangesIn addition to the new folder, I've also a test for broadcast(splat) -> splat which I think was missing Full diff: https://github.com/llvm/llvm-project/pull/135677.diff 2 Files Affected:
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index bee5c1fd6ed58..4b7ff757c150a 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -2590,6 +2590,8 @@ OpFoldResult BroadcastOp::fold(FoldAdaptor adaptor) {
}
if (auto attr = llvm::dyn_cast<SplatElementsAttr>(adaptor.getSource()))
return DenseElementsAttr::get(vectorType, attr.getSplatValue<Attribute>());
+ if (llvm::dyn_cast<ub::PoisonAttr>(adaptor.getSource()))
+ return ub::PoisonAttr::get(getContext());
return {};
}
diff --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir
index 78b0ea78849e8..420244c5e734a 100644
--- a/mlir/test/Dialect/Vector/canonicalize.mlir
+++ b/mlir/test/Dialect/Vector/canonicalize.mlir
@@ -1151,6 +1151,28 @@ func.func @bitcast_i8_to_i32() -> (vector<4xi32>, vector<4xi32>) {
// -----
+// CHECK-LABEL: broadcast_poison
+// CHECK: %[[POISON:.*]] = ub.poison : vector<4x6xi8>
+// CHECK: return %[[POISON]] : vector<4x6xi8>
+func.func @broadcast_poison() -> vector<4x6xi8> {
+ %poison = ub.poison : vector<6xi8>
+ %broadcast = vector.broadcast %poison : vector<6xi8> to vector<4x6xi8>
+ return %broadcast : vector<4x6xi8>
+}
+
+// -----
+
+// CHECK-LABEL: broadcast_splat_constant
+// CHECK: %[[CONST:.*]] = arith.constant dense<1> : vector<4x6xi8>
+// CHECK: return %[[CONST]] : vector<4x6xi8>
+func.func @broadcast_splat_constant() -> vector<4x6xi8> {
+ %cst = arith.constant dense<1> : vector<6xi8>
+ %broadcast = vector.broadcast %cst : vector<6xi8> to vector<4x6xi8>
+ return %broadcast : vector<4x6xi8>
+}
+
+// -----
+
// CHECK-LABEL: broadcast_folding1
// CHECK: %[[CST:.*]] = arith.constant dense<42> : vector<4xi32>
// CHECK-NOT: vector.broadcast
|
In addition to the new folder, I've also a test for broadcast(splat) -> splat which I think was missing Signed-off-by: James Newling <[email protected]>
In addition to the new folder, I've also a test for broadcast(splat) -> splat which I think was missing