[mlir] Fix worklist bug in MultiOpPatternRewriteDriver
authorMatthias Springer <springerm@google.com>
Tue, 10 Jan 2023 14:30:49 +0000 (15:30 +0100)
committerMatthias Springer <springerm@google.com>
Tue, 10 Jan 2023 14:33:22 +0000 (15:33 +0100)
commit0e4735546e6bbcfd5d11d0a6b8b68cb9ccad9b41
treec580c40a250805811716c943768e766a8f66c62b
parent089a54469f63c2f3c4b9d79fb9694f21bef0d071
[mlir] Fix worklist bug in MultiOpPatternRewriteDriver

When `strict = true`, only pre-existing and newly-created ops are rewritten and/or folded. Such ops are stored in `strictModeFilteredOps`.

Newly-created ops were previously added to `strictModeFilteredOps` after calling `addToWorklist` (via `GreedyPatternRewriteDriver::notifyOperationInserted`). Therefore, newly-created ops were never added to the worklist.

Also fix a test case that should have gone into an infinite loop (`test.replace_with_new_op` was replaced with itself, which should have caused the op to be rewritten over and over), but did not due to this bug.

Differential Revision: https://reviews.llvm.org/D141141
mlir/lib/Transforms/Utils/GreedyPatternRewriteDriver.cpp
mlir/test/Transforms/test-strict-pattern-driver.mlir
mlir/test/lib/Dialect/Test/TestPatterns.cpp