The following if program with multiple return operations cannot be directly supported by MLIR. scf.yield should be the final operation of the if scope, while std.return should be the last operation of the function, which causes contradiction and cannot pass verification. The root cause of this is the structured control flow in MLIR does not support immediate exit from all of the ancestor scope operations, so break/continue are also the cases (See discussion thread).
def foo(x):
with hcl.if_(x > 5):
hcl.return_(-1)
hcl.return_(x)
To mitigate the problem, one can translate the following program into a program with else branch. First yield the results as the output of scf.if operation, and return the result of scf.if, but this requires careful transformation to make it correct.
The following
if
program with multiple return operations cannot be directly supported by MLIR.scf.yield
should be the final operation of theif
scope, whilestd.return
should be the last operation of the function, which causes contradiction and cannot pass verification. The root cause of this is the structured control flow in MLIR does not support immediate exit from all of the ancestor scope operations, sobreak/continue
are also the cases (See discussion thread).(Direct translation is not valid)
To mitigate the problem, one can translate the following program into a program with
else
branch. First yield the results as the output ofscf.if
operation, and return the result ofscf.if
, but this requires careful transformation to make it correct.