This is an archive of the discontinued LLVM Phabricator instance.

[mlir] lower loop.if operations that yield a result
AbandonedPublic

Authored by gysit on Mar 18 2020, 3:27 AM.

Details

Reviewers
ftynse
Summary

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.

Diff Detail

Event Timeline

gysit created this revision.Mar 18 2020, 3:27 AM
ftynse requested changes to this revision.Mar 18 2020, 6:11 AM

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).

This revision now requires changes to proceed.Mar 18 2020, 6:11 AM
gysit added a comment.Mar 18 2020, 7:00 AM

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.

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!

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.

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...

ftynse resigned from this revision.Apr 16 2020, 1:19 AM
gysit abandoned this revision.Apr 16 2020, 2:00 AM