[mlir][Transform] Fix transform.sequence crash in the presence of propagated silenceable errors and yield operations

Differential Revision: https://reviews.llvm.org/D137708
This commit is contained in:
Nicolas Vasilache
2022-11-09 05:09:39 -08:00
parent 0f4f246783
commit aa6a6c56d8
2 changed files with 27 additions and 1 deletions

View File

@@ -155,6 +155,12 @@ void transform::AlternativesOp::getRegionInvocationBounds(
bounds.resize(getNumRegions(), InvocationBounds(0, 1));
}
static void forwardEmptyOperands(Block *block, transform::TransformState &state,
transform::TransformResults &results) {
for (const auto &res : block->getParentOp()->getOpResults())
results.set(res, {});
}
static void forwardTerminatorOperands(Block *block,
transform::TransformState &state,
transform::TransformResults &results) {
@@ -594,8 +600,11 @@ transform::SequenceOp::apply(transform::TransformResults &results,
return result;
if (result.isSilenceableFailure()) {
if (getFailurePropagationMode() == FailurePropagationMode::Propagate)
if (getFailurePropagationMode() == FailurePropagationMode::Propagate) {
// Propagate empty results in case of early exit.
forwardEmptyOperands(getBodyBlock(), state, results);
return result;
}
(void)result.silence();
}
}

View File

@@ -920,3 +920,20 @@ transform.with_pdl_patterns {
}
"test.some_op"() : () -> ()
// -----
func.func @split_handles(%a: index, %b: index, %c: index) {
%0 = arith.muli %a, %b : index
%1 = arith.muli %a, %c : index
return
}
transform.sequence -> !pdl.operation failures(propagate) {
^bb1(%fun: !pdl.operation):
%muli = transform.structured.match ops{["arith.muli"]} in %fun
// expected-error @below {{expected to contain 3 operation handles but it only contains 2 handles}}
%h_2:3 = split_handles %muli in [3] : (!pdl.operation) -> (!pdl.operation, !pdl.operation, !pdl.operation)
/// Test that yield does not crash in the presence of silenceable error in
/// propagate mode.
yield %fun : !pdl.operation
}