[Mlir-commits] [mlir] [mlir] Fix non-termination when a block becomes unreachable during rewriting (PR #221152)
Mehdi Amini
llvmlistbot at llvm.org
Fri Sep 4 09:05:00 PDT 2026
================
@@ -482,6 +482,15 @@ bool GreedyPatternRewriteDriver::processWorklist() {
}
});
+ // Folding an operation that uses its own result can loop forever, so
+ // skip it. Such operations are legal in unreachable code.
+ if (llvm::any_of(op->getOperands(), [op](Value operand) {
+ return operand.getDefiningOp() == op;
+ })) {
+ LLVM_DEBUG(logResultWithLine("failure", "operation uses its own result"));
+ continue;
+ }
----------------
joker-eph wrote:
The cost `O(wordlist-size x operands)`` I believe, what's concerning to me is that this is an edge case but we'd pay the price all the time.
Hopefully a listener should be able to detect changes in the control-flow?
https://github.com/llvm/llvm-project/pull/221152
More information about the Mlir-commits
mailing list