Skip to content

Commit 73b8750

Browse files
authored
[mlir][vector] fold transpose(poison) -> poison (#135675)
Following on from #133988 --------- Signed-off-by: James Newling <[email protected]>
1 parent facc57f commit 73b8750

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

mlir/lib/Dialect/Vector/IR/VectorOps.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6009,6 +6009,10 @@ OpFoldResult vector::TransposeOp::fold(FoldAdaptor adaptor) {
60096009
if (attr.isSplat())
60106010
return attr.reshape(getResultVectorType());
60116011

6012+
// Eliminate poison transpose ops.
6013+
if (llvm::dyn_cast_if_present<ub::PoisonAttr>(adaptor.getVector()))
6014+
return ub::PoisonAttr::get(getContext());
6015+
60126016
// Eliminate identity transpose ops. This happens when the dimensions of the
60136017
// input vector remain in their original order after the transpose operation.
60146018
ArrayRef<int64_t> perm = getPermutation();

mlir/test/Dialect/Vector/canonicalize.mlir

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,17 @@ func.func @transpose_splat2(%arg : f32) -> vector<3x4xf32> {
22402240

22412241
// -----
22422242

2243+
// CHECK-LABEL: transpose_poison
2244+
// CHECK: %[[POISON:.*]] = ub.poison : vector<4x6xi8>
2245+
// CHECK: return %[[POISON]] : vector<4x6xi8>
2246+
func.func @transpose_poison() -> vector<4x6xi8> {
2247+
%poison = ub.poison : vector<6x4xi8>
2248+
%transpose = vector.transpose %poison, [1, 0] : vector<6x4xi8> to vector<4x6xi8>
2249+
return %transpose : vector<4x6xi8>
2250+
}
2251+
2252+
// -----
2253+
22432254
// CHECK-LABEL: func.func @insert_1d_constant
22442255
// CHECK-DAG: %[[ACST:.*]] = arith.constant dense<[9, 1, 2]> : vector<3xi32>
22452256
// CHECK-DAG: %[[BCST:.*]] = arith.constant dense<[0, 9, 2]> : vector<3xi32>

0 commit comments

Comments
 (0)