[mlir] GreedyPatternRewriter: fix counting of iterations
authorMatthias Springer <springerm@google.com>
Tue, 10 Jan 2023 11:02:33 +0000 (12:02 +0100)
committerMatthias Springer <springerm@google.com>
Tue, 10 Jan 2023 11:21:08 +0000 (12:21 +0100)
commit0ff3cf0c0cda58b139ddbf6954befeebdda7ed52
tree72b5c683740c09b3bff18237aa35f2f9f98679c0
parent094ccee2c89e9fa12a3439f5561f9472f98654e5
[mlir] GreedyPatternRewriter: fix counting of iterations

The GreedyPatternRewriteDriver did previously not count the first iteration. I.e., when setting `config.maxIterations = 1`, two iterations were performed. In pratice, this number is not really important; we usually just need a limit in some reasonable order of magnitude. However, this fix allows us to write better convergence/worklist tests with carefully crafted test patterns to purposely trigger edge cases in the driver.

Similarly, the first rewrite was previously not counted towards `config.maxNumRewrites`.

For consistency, `OpPatternRewriteDriver` now uses `config.maxNumRewrites` instead of `config.maxIterations`; this driver does not have "iterations", it consists of a single loop (corresponding to the inner loop in the GreedyPatternRewriteDriver).

Differential Revision: https://reviews.llvm.org/D141365
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp