The patch extends the loop dialect lowering to support loop.if operations that yield one or more results. In particular, the patch ensures the results yielded by the then and else blocks are forwarded to the continuation block.
Details
Diff Detail
Event Timeline
Unfortunately, this is harder than it looks. We need to make sure all IR changes in the pattern go through rewriter and we currently don't have a way of adding new block arguments there. If you are blocked by this, feel free to temporarily loop.if lowering from the pattern rewriter infra and run it as a plain IR-mutating pass.
mlir/lib/Conversion/LoopToStandard/ConvertLoopToStandard.cpp | ||
---|---|---|
243 | We should not be calling replaceAllUsesWith inside matchAndRewrite, it messes up with the pattern rewriter (it tracks all transformations and may roll some changes back, going outside the rewrite makes changes untrackable and ultimately leads to tricky crashes). |
Thanks for that hint!
I guess I have multiple patterns where I use replaceAllUsesWith(). Can a rollback happen even if there is no code path that later on returns failure()? I ask since my stuff seems to work so far.
Let's postpone the patch then!
The only case where it is actually necessary is replacing block arguments. Otherwise, you can do rewriter.replaceOp(op-that-defines-the-value, new-values).
Currently, we don't rollback if patterns don't fail. However, you don't necessarily have a guarantee that your patterns won't be combined with other patterns that may fail...
We should not be calling replaceAllUsesWith inside matchAndRewrite, it messes up with the pattern rewriter (it tracks all transformations and may roll some changes back, going outside the rewrite makes changes untrackable and ultimately leads to tricky crashes).