[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 06:57:48 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:

I'm concerned about the cost here. Can we instead detect when the control flow changes and a block becomes unreachable and prune it somehow?

https://github.com/llvm/llvm-project/pull/221152


More information about the Mlir-commits mailing list