[Mlir-commits] [mlir] 73b8750 - [mlir][vector] fold transpose(poison) -> poison (#135675)
llvmlistbot at llvm.org
llvmlistbot at llvm.org
Wed Apr 16 10:10:26 PDT 2025
Author: James Newling
Date: 2025-04-16T13:10:23-04:00
New Revision: 73b8750a970ddaec5da1540c100561bd5104bca6
URL: https://github.com/llvm/llvm-project/commit/73b8750a970ddaec5da1540c100561bd5104bca6
DIFF: https://github.com/llvm/llvm-project/commit/73b8750a970ddaec5da1540c100561bd5104bca6.diff
LOG: [mlir][vector] fold transpose(poison) -> poison (#135675)
Following on from https://github.com/llvm/llvm-project/pull/133988
---------
Signed-off-by: James Newling <james.newling at gmail.com>
Added:
Modified:
mlir/lib/Dialect/Vector/IR/VectorOps.cpp
mlir/test/Dialect/Vector/canonicalize.mlir
Removed:
################################################################################
diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
index 504032a398fbe..3ef947c7b14a4 100644
--- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
+++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp
@@ -6009,6 +6009,10 @@ OpFoldResult vector::TransposeOp::fold(FoldAdaptor adaptor) {
if (attr.isSplat())
return attr.reshape(getResultVectorType());
+ // Eliminate poison transpose ops.
+ if (llvm::dyn_cast_if_present<ub::PoisonAttr>(adaptor.getVector()))
+ return ub::PoisonAttr::get(getContext());
+
// Eliminate identity transpose ops. This happens when the dimensions of the
// input vector remain in their original order after the transpose operation.
ArrayRef<int64_t> perm = getPermutation();
diff --git a/mlir/test/Dialect/Vector/canonicalize.mlir b/mlir/test/Dialect/Vector/canonicalize.mlir
index 733a2c67d2c0c..c28afd0dee97e 100644
--- a/mlir/test/Dialect/Vector/canonicalize.mlir
+++ b/mlir/test/Dialect/Vector/canonicalize.mlir
@@ -2240,6 +2240,17 @@ func.func @transpose_splat2(%arg : f32) -> vector<3x4xf32> {
// -----
+// CHECK-LABEL: transpose_poison
+// CHECK: %[[POISON:.*]] = ub.poison : vector<4x6xi8>
+// CHECK: return %[[POISON]] : vector<4x6xi8>
+func.func @transpose_poison() -> vector<4x6xi8> {
+ %poison = ub.poison : vector<6x4xi8>
+ %transpose = vector.transpose %poison, [1, 0] : vector<6x4xi8> to vector<4x6xi8>
+ return %transpose : vector<4x6xi8>
+}
+
+// -----
+
// CHECK-LABEL: func.func @insert_1d_constant
// CHECK-DAG: %[[ACST:.*]] = arith.constant dense<[9, 1, 2]> : vector<3xi32>
// CHECK-DAG: %[[BCST:.*]] = arith.constant dense<[0, 9, 2]> : vector<3xi32>
More information about the Mlir-commits
mailing list