This is an archive of the discontinued LLVM Phabricator instance.

[mlir] GreedyPatternRewriter: fix counting of iterations
ClosedPublic

Authored by springerm on Jan 10 2023, 2:52 AM.

Details

Summary

The GreedyPatternRewriteDriver did previously not count the first iterations. I.e., when setting config.maxIterations = 1, two iterations were performed. In pratice, this number is not really important; we usually just 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).

Diff Detail

Event Timeline

springerm created this revision.Jan 10 2023, 2:52 AM
springerm requested review of this revision.Jan 10 2023, 2:52 AM
mehdi_amini accepted this revision.Jan 10 2023, 2:59 AM

LG, but I wonder if it wasn't intentional: that is it controlled how much the driver would "loop around" in a do {} while() fashion. The idea being that passing 0 wouldn't make sense otherwise.

This revision is now accepted and ready to land.Jan 10 2023, 2:59 AM
This revision was landed with ongoing or failed builds.Jan 10 2023, 3:25 AM
This revision was automatically updated to reflect the committed changes.

LG, but I wonder if it wasn't intentional: that is it controlled how much the driver would "loop around" in a do {} while() fashion. The idea being that passing 0 wouldn't make sense otherwise.

0 would make it a "no-op" indeed.