Skip to content

Commit 30ce0c9

Browse files
committed
[mlir] properly handle an edge case in transform.split_handles
The `transform.split_handles` transform op has an edge case that is supposed to propagate empty handle state to all resulting handles regardless of their number. Actually set empty payload for them instead of leaving them unset. Reviewed By: springerm Differential Revision: https://reviews.llvm.org/D149652
1 parent d906426 commit 30ce0c9

File tree

2 files changed

+19
-4
lines changed

2 files changed

+19
-4
lines changed

mlir/lib/Dialect/Transform/IR/TransformOps.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,13 +1510,17 @@ transform::SplitHandlesOp::apply(transform::TransformResults &results,
15101510
if (numResultHandles != expectedNumResultHandles) {
15111511
// Empty input handle corner case: always propagates empty handles in both
15121512
// suppress and propagate modes.
1513-
if (numResultHandles == 0)
1513+
if (numResultHandles == 0) {
1514+
for (OpResult result : getResults())
1515+
results.set(result, {});
15141516
return DiagnosedSilenceableFailure::success();
1517+
}
1518+
15151519
// If the input handle was not empty and the number of result handles does
15161520
// not match, this is a legit silenceable error.
15171521
return emitSilenceableError()
15181522
<< getHandle() << " expected to contain " << expectedNumResultHandles
1519-
<< " operation handles but it only contains " << numResultHandles
1523+
<< " operation handles but it contains " << numResultHandles
15201524
<< " handles";
15211525
}
15221526
// Normal successful case.

mlir/test/Dialect/Transform/test-interpreter.mlir

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ transform.sequence failures(propagate) {
831831
// expected-remark @below {{1}}
832832
transform.test_print_number_of_associated_payload_ir_ops %h#0
833833
%muli_2 = transform.structured.match ops{["arith.muli"]} in %fun : (!pdl.operation) -> !pdl.operation
834-
// expected-error @below {{expected to contain 3 operation handles but it only contains 2 handles}}
834+
// expected-error @below {{expected to contain 3 operation handles but it contains 2 handles}}
835835
%h_2:3 = split_handles %muli_2 in [3] : (!pdl.operation) -> (!pdl.operation, !pdl.operation, !pdl.operation)
836836
}
837837

@@ -975,7 +975,7 @@ func.func @split_handles(%a: index, %b: index, %c: index) {
975975
transform.sequence -> !pdl.operation failures(propagate) {
976976
^bb1(%fun: !pdl.operation):
977977
%muli = transform.structured.match ops{["arith.muli"]} in %fun : (!pdl.operation) -> !pdl.operation
978-
// expected-error @below {{expected to contain 3 operation handles but it only contains 2 handles}}
978+
// expected-error @below {{expected to contain 3 operation handles but it contains 2 handles}}
979979
%h_2:3 = split_handles %muli in [3] : (!pdl.operation) -> (!pdl.operation, !pdl.operation, !pdl.operation)
980980
/// Test that yield does not crash in the presence of silenceable error in
981981
/// propagate mode.
@@ -984,6 +984,17 @@ transform.sequence -> !pdl.operation failures(propagate) {
984984

985985
// -----
986986

987+
transform.sequence -> !transform.any_op failures(suppress) {
988+
^bb0(%arg0: !transform.any_op):
989+
%muli = transform.structured.match ops{["arith.muli"]} in %arg0 : (!transform.any_op) -> !transform.any_op
990+
// Edge case propagating empty handles in splitting.
991+
%0:3 = split_handles %muli in [3] : (!transform.any_op) -> (!transform.any_op, !transform.any_op, !transform.any_op)
992+
// Test does not crash when accessing the empty handle.
993+
yield %0#0 : !transform.any_op
994+
}
995+
996+
// -----
997+
987998
transform.sequence failures(propagate) {
988999
^bb0(%arg0: !transform.any_op):
9891000
%0 = transform.test_produce_integer_param_with_type i32 : !transform.test_dialect_param

0 commit comments

Comments
 (0)