Increase scanning iterations for applyPatternsAndFoldGreedily

Hi,

I have a pattern that needs to be applied several times for the rewrite to converge.
I am using applyPatternsAndFoldGreedily.
After scanning 10 times the matchAndRewrite stops with the following message:

The pattern rewrite doesn't converge after scanning 10 times

Is there a way to increase the amount to, let’s say, 25 scanning iterations?
I happen to know it will converge at that point, as I need 24 rewrites.

Thanks in advance!

I don’t think there is a command-line option for this at the moment; it’s controlled by maxPatternMatchIterations. So you might want to increase the number there to try. But it makes sense to me to turn it into a command-line option.

Modifying and rebuilding LLVM works but ideally I don’t use a custom version of LLVM for my project.
It would indeed be nice to have a command-line option: I’ll see if I can submit an issue for it

It would be interesting to know the sequence that resulted in this too. Are these OSS?

Hi,

not sure I understand your question, but basically the situation is as follows.

struct MyPattern: public RewritePattern {

  MyPattern(MLIRContext *context)
    : RewritePattern("func", 1, context)
  {}

  LogicalResult matchAndRewrite(Operation *op, PatternRewriter &rewriter) const override {

    // Either apply a rewrite or not

    if(applied_rewrite) {
      return success();
    }
    return failure();
  } // matchAndRewrite

void MyPass::runOnFunction() {
  auto &context = getContext();
  OwningRewritePatternList patterns;
  patterns.insert<MyPattern>(&context);

  if (failed(applyPatternsAndFoldGreedily(getFunction().getParentOp(), patterns))) {
    signalPassFailure();
  }
}

Here is the link a the issue I filed: